I recently submitted an assignment to my instructor, and i got a less than desirable grade and the jist of the marks were that iw as using hard coded variables so can someone explain to me how to use the getter method a little better? (i assume thats what i have to use to get the user information)
public class BankAccount {
private String name = "JohnDoe";
private int nextAccountNumber = 123456;
private double balance = 5000;
private String typeofaccount = "checking";
public void setname(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setBalance(double balance2){
this.balance = balance2;
}
public double getBalance(){
return this.balance;
}
public void setAccountNumber(int AccountNumber){
this.nextAccountNumber = nextAccountNumber;
}
public int getAccountNumber(){
return this.nextAccountNumber;
}
public void settypeofaccount(String typeofaccount){
this.typeofaccount = typeofaccount;
}
public String getTypeOfAccount(){
return this.typeofaccount;
}
public void displayAccountInfo(){
System.out.println("Account Type: " + this.typeofaccount);
System.out.println("Name: " + this.name);
System.out.println("Account Number: " + this.nextAccountNumber);
System.out.println("Balance: $" + this.balance);
}
public void displayInfo() {
// TODO Auto-generated method stub
}
}
import java.util.Scanner;
public class BankAccountDriver{
private static String JohnDoe = null;
private static final String CheckingAccount = null;
private static String name = JohnDoe;
public static void main (String[] args){
// create instance of Bankaccount
BankAccount account = new BankAccount();
String name = askName();
account.setname(name);
String type = askType();
account.settypeofaccount(type);
String accnum = askName();
account.displayAccountInfo();
double balance = askBalance();
account.setBalance(balance);
account.displayInfo();
}
private static double askBalance() {
// TODO Auto-generated method stub
return 0;
}
private static String askType() {
// TODO Auto-generated method stub
return CheckingAccount;
}
private static String askName() {
// TODO Auto-generated method stub
return JohnDoe;
}
}