I am trying to add the values from the account method but I don’t know how to call it or how write the first line.
I am trying to test the account number and if it is a certain one add a value to balance.
the rest of the code is same as previous post
account1.java
acccount.java
thx for your help
Code:
creditAccounts()
{
if theAccountNumber == 1001{
theBalance += 1000;
}
if theAccountNumber == 1002{
theBalance += 500;
}
return theBalance;
}
the rest of the code is same as previous post
account1.java
Code:
public class Account1
{
private int theAccountNumber;
private int theBalance;
private String theHolder;
public Account1(int accN, int initBal, String name)//constructor method
{
this.setAccountNumber(accN);
this.setBalance(initBal);
this.setHolder(name);
}
public void setAccountNumber(int aNumber)//modifier method
{
theAccountNumber=aNumber;
}
public void setBalance(int anAmount)
{
theBalance=anAmount;
}
public void setHolder(String aName)
{
theHolder=aName;
}
public int getAccountNumber()
{
return theAccountNumber;
}
public int getBalance()
{
creditAccounts()
return theBalance;
}
public String getHolder()
{
return theHolder;
}
creditAccounts()
{
if theAccountNumber == 1001{
theBalance += 1000;
}
if theAccountNumber == 1002{
theBalance += 500;
}
return theBalance;
}
}
acccount.java
Code:
public class Account
{
public static void main(String[]args)
{
//cereate new account
Account1 myAccount=new Account1(1000, 2000, "Tony");
//list the excisting accounts
int accountNumber=myAccount.getAccountNumber();
int accountBalance=myAccount.getBalance();
String accountHolder = myAccount.getHolder();
System.out.println("Account Number " +accountNumber);
System.out.println("Account Balance "+accountBalance);
System.out.println("Account Holder " +accountHolder);
System.out.println();
Account1 hisAccount=new Account1(1001, 2000, "Mark");
accountNumber=hisAccount.getAccountNumber();
accountBalance=hisAccount.getBalance();
accountHolder = hisAccount.getHolder();
System.out.println("Account Number1 " +accountNumber);
System.out.println("Account Balance1 "+accountBalance);
System.out.println("Account Holder1 " +accountHolder);
System.out.println();
Account1 herAccount=new Account1(1002, 500, "Sarah");
accountNumber=herAccount.getAccountNumber();
accountBalance=herAccount.getBalance();
accountHolder = herAccount.getHolder();
System.out.println("Account Number1 " +accountNumber);
System.out.println("Account Balance1 "+accountBalance);
System.out.println("Account Holder1 " +accountHolder);
}
}
thx for your help