# NEED HELP ALL the way with this..

• November 7th, 2013, 02:44 PM
NEED HELP ALL the way with this..
Problem Description

Write a program to process bank accounts. Create a super class named Account and two subclasses named Savings and Checking. In the superclass, use an int AccountNum and a double balance for data members. Also, create two methods to do deposit and to do withdraw. Create one abstract method calculateDailyInterest that calculates and returns the daily interest. The method also adds the daily interest to the balance. The savings account is getting 3% annual interest rate. The checking account is getting 2% annual interest rate for amount that over \$500.

Sample Run:

Enter one of the following
1) Create a new Checking Account
2) Create a new Savings Account
3) Make a Deposit
4) Make a Withdraw
5) Display all accounts
6) Calculate Daily interest
7) Exit

1
A new Checking account with account number: 1
Enter the initial balance 1000
2
A new Savings account with account number: 2
Enter the initial balance 800
2
A new Savings account with account number: 3
Enter the initial balance 500
5
*********************************
Account 1 has balance 1000.00
Account 2 has balance 800.00
Account 3 has balance 500.00
*********************************
3
Which account to deposit? 1
Enter the amount of deposit: 50
5
*********************************
Account 1 has balance 1050.00
Account 2 has balance 800.00
Account 3 has balance 500.00
*********************************
4
Which account to withdraw? 2
Enter the amount of withdraw: 80
5
*********************************
Account 1 has balance 1050.00
Account 2 has balance 720.00

Problem Requirement
a) You must use a separate file for each class.
b) You must use a separate file for the Testing program.
c) Your program must produce the prompt and the output the same as given.
d) Your program should run correctly with the same inputs and outputs as given in the sample run.
e) The balances should be displayed with 2 decimal places.
• November 7th, 2013, 02:51 PM
copeg
Re: NEED HELP ALL the way with this..
• November 7th, 2013, 02:56 PM
Re: NEED HELP ALL the way with this..
I haven't tried anything...
• November 7th, 2013, 02:59 PM
Norm
Re: NEED HELP ALL the way with this..
When you do and have some specific questions about the project, post them and any code you are having problems with.
• November 7th, 2013, 05:31 PM
Junky
Re: NEED HELP ALL the way with this..
Quote:

I haven't tried anything...

No problems. Sit back and relax. I'll code it up for you, when is it due?
• November 7th, 2013, 09:33 PM
Re: NEED HELP ALL the way with this..
thanks!! tomorrow afternoon
• November 7th, 2013, 09:44 PM
Kewish
Re: NEED HELP ALL the way with this..
That might be a bit tight. Didn't you say it might take 2 days Junky ;)
• November 7th, 2013, 09:56 PM
Re: NEED HELP ALL the way with this..
nah...don't say that...lol
• November 8th, 2013, 02:29 AM
GregBrannon
Re: NEED HELP ALL the way with this..
No one is coding anything for you. Get to work. Come back when you have code and need help.
• November 8th, 2013, 12:47 PM
Re: NEED HELP ALL the way with this..
this is what I have so far...I just wrote the best I could...I get an error on my laptop and I haven't been able to view any files that I have done this semester..Im going to login and tell you what error I am getting

Code java:

```  //Account class   public abstract class Account   {   //data members   int accountnumber;   double accountbalance;   //constructor   public Account(int accn,double balance)   {   accountnumber = accn;   accountbalance = balance;   }   //deposit method   public void deposit(double amount)   {   accountbalance +=amount;   System.out.println("\$"+amount +" deposited into your account");   System.out.println("Your account balance is \$"+accountbalance);   }   //withdraw method   public void withdraw(double amount)   {   if(amount<accountbalance)   {   accountbalance -=amount;   System.out.println("You have drawn an amount of \$"+amount);   System.out.println("Your account balance is \$"+accountbalance);   }   else   {   System.out.println("Your account doesn't have sufficient balance");   }   }   //show method   public void show()   {   System.out.println("Account Details");   System.out.println("---------------");   System.out.println("Account Number :"+accountnumber);   System.out.println("Account Balance :"+accountbalance);   System.out.println("---------------");   }   //abstract method to calculate interest   abstract void calculateDailyInterest();   }   /File Name : Checking.java   //child class Checking   public class Checking extends Account   {   public Checking(int ano,double balance)   {   //calling base class constructor   super(ano,balance);   }   //calculating daily interest   void calculateDailyInterest()   {   accountbalance +=accountbalance+(accountbalance-500)*0.02;   }   }   //File Name : Savings.java   //child class Savings   public class Savings extends Account   {   public Savings(int ano, double balance)   {   //calling base class constructor   super(ano,balance);   }   //calculating daily interest   void calculateDailyInterest()   {   accountbalance +=accountbalance+accountbalance*0.05;   }   }   //File Name : AccountDemo.java   public class AccountDemo   {   public static void main(String args[])throws Exception   {   //declaring variables   Savings sAcc=new Savings(0,0.0);   Checking cAcc=new Checking(0,0.0);   int choice;   int ano;   double balance;   Scanner scan=new Scanner(System.in);   //do loop   do   {   System.out.println("1. create new checking account");   System.out.println("2. create new savings");   System.out.println("3. make deposit");   System.out.println("4. make withdraw");   System.out.println("5. display all accounts");   System.out.println("6. calculate daily interest");   System.out.println("7 exit");   choice=scan.nextInt();   switch(choice)   {   case 1:System.out.print("Enter Accoutn Number:");   ano=scan.nextInt();   System.out.print("Enter Accoutn Balance:");   balance=scan.nextDouble();   sAcc=new Savings(ano,balance);   break;   case 2:System.out.print("Enter Accoutn Number:");   ano=scan.nextInt();   System.out.print("Enter Accoutn Balance:");   balance=scan.nextDouble();   cAcc=new Checking(ano,balance);   break;   case 3:System.out.print("Enter Amount to deposit:");   balance=scan.nextDouble();   sAcc.deposit(balance);   cAcc.deposit(balance);   break;   case 4:System.out.print("Enter Amount to withdraw:");   balance=scan.nextDouble();   sAcc.withdraw(balance);   cAcc.withdraw(balance);   break;   case 5: sAcc.show();   cAcc.show();   break;   case 6: sAcc.calculateDailyInterest();   cAcc.calculateDailyInterest();   break;   case 7:System.exit(0);   }//end of switch   }while(true);//end of do-while   }//end of main   }//end of class```
• November 8th, 2013, 01:05 PM
Norm
Re: NEED HELP ALL the way with this..
[code=java]
[/code]
to get highlighting and preserve formatting.
• November 8th, 2013, 01:11 PM
Re: NEED HELP ALL the way with this..
did that work?
• November 8th, 2013, 01:27 PM
Norm
Re: NEED HELP ALL the way with this..
Partly. The code has lost all its formatting. Nested statements should be indented. All the statements in the code start in the first column instead of being indented to show logic nesting. That makes the code hard to read.
• November 8th, 2013, 04:21 PM
Re: NEED HELP ALL the way with this..
I don't have java on this pc.. I have to get help to download it and instructions on how to view it. But is this better now...?

Code java:

```  //File Name :Account.java   //Account class   public abstract class Account   {   //data members   int accountnumber; double accountbalance;   //constructor   public Account(int accn,double balance)   {   accountnumber = accn; accountbalance = balance;   }   //deposit method   public void deposit(double amount)   {   accountbalance +=amount;   System.out.println("\$"+amount +" deposited into your account");   System.out.println("Your account balance is \$"+accountbalance);   }   //withdraw method   public void withdraw(double amount)   {   if(amount<accountbalance)   {   accountbalance -=amount;   System.out.println("You have drawn an amount of \$"+amount);   System.out.println("Your account balance is \$"+accountbalance);   }   else   {   System.out.println("Your account doesn't have sufficient balance");   }   }   //show method   public void show()   {   System.out.println("Account Details");   System.out.println("---------------");   System.out.println("Account Number :"+accountnumber);   System.out.println("Account Balance :"+accountbalance);   System.out.println("---------------");   }   //abstract method to calculate interest   abstract void calculateDailyInterest();   }       //File Name : Checking.java   //child class Checking   public class Checking extends Account   {   public Checking(int ano,double balance)   {   //calling base class constructor   super(ano,balance);   }   //calculating daily interest   void calculateDailyInterest()   {   accountbalance +=accountbalance+(accountbalance-500)*0.02;   }   }     //File Name : Savings.java   //child class Savings   public class Savings extends Account   {   public Savings(int ano, double balance)   {   //calling base class constructor   super(ano,balance);   }   //calculating daily interest   void calculateDailyInterest()   {   accountbalance +=accountbalance+accountbalance*0.05;   }   }     //File Name : AccountDemo.java   public class AccountDemo   {   public static void main(String args[])throws Exception   {   //declaring variables   Savings sAcc=new Savings(0,0.0);   Checking cAcc=new Checking(0,0.0);   int choice;   int ano;   double balance;   Scanner scan=new Scanner(System.in);   //do loop   do   {   System.out.println("1. create new checking account");   System.out.println("2. create new savings");   System.out.println("3. make deposit");   System.out.println("4. make withdraw");   System.out.println("5. display all accounts");   System.out.println("6. calculate daily interest");   System.out.println("7 exit");   choice=scan.nextInt();   switch(choice)   {   case 1:System.out.print("Enter Account Number:");   ano=scan.nextInt();   System.out.print("Enter Account Balance:");   balance=scan.nextDouble();   sAcc=new Savings(ano,balance);   break;   case 2:System.out.print("Enter Account Number:");   ano=scan.nextInt();   System.out.print("Enter Account Balance:");   balance=scan.nextDouble();   cAcc=new Checking(ano,balance);   break;   case 3:System.out.print("Enter Amount to deposit:");   balance=scan.nextDouble();   sAcc.deposit(balance);   cAcc.deposit(balance);   break;   case 4:System.out.print("Enter Amount to withdraw:");   balance=scan.nextDouble();   sAcc.withdraw(balance);   cAcc.withdraw(balance);   break;   case 5: sAcc.show();   cAcc.show();   break;   case 6: sAcc.calculateDailyInterest();   cAcc.calculateDailyInterest();   break;   case 7:System.exit(0);   }//end of switch   }while(true);//end of do-while   }//end of main   }//end of class```
• November 8th, 2013, 04:34 PM
Norm
Re: NEED HELP ALL the way with this..
some better. Some of the { and } need to be indented also. There should never be one } directly beneath another }
The case should be indented and the statements in the case indented further.
Code :

``` switch(choice) {   case 1: System.out.print("Enter Account Number:"); ano=scan.nextInt(); break;   case 2: System.out.print("Enter Account Number:");```

There are too empty lines that spread the code out too much.
• November 8th, 2013, 05:05 PM
Re: NEED HELP ALL the way with this..
NOW?

Code java

//File Name :Account.java

//Account class

public abstract class Account

{

//data members

int accountnumber;
double accountbalance;

//constructor

public Account(int accn,double balance)

{

accountnumber = accn;
accountbalance = balance;

}

//deposit method

public void deposit(double amount)

{

accountbalance +=amount;

System.out.println("\$"+amount +" deposited into your account");

}

//withdraw method

public void withdraw(double amount)

{

if(amount<accountbalance)

{

accountbalance -=amount;

System.out.println("You have drawn an amount of \$"+amount);

}

else

{

System.out.println("Your account doesn't have sufficient balance");

}

}

//show method

public void show()

{

System.out.println("Account Details");

System.out.println("---------------");

System.out.println("Account Number :"+accountnumber);

System.out.println("Account Balance :"+accountbalance);

System.out.println("---------------");

}

//abstract method to calculate interest

abstract void calculateDailyInterest();

}

//File Name : Checking.java

//child class Checking

public class Checking extends Account

{

public Checking(int ano,double balance)

{

//calling base class constructor

super(ano,balance);

}

//calculating daily interest

void calculateDailyInterest()

{

accountbalance +=accountbalance+(accountbalance-500)*0.02;

}

}

//File Name : Savings.java

//child class Savings

public class Savings extends Account

{

public Savings(int ano, double balance)

{

//calling base class constructor

super(ano,balance);

}

//calculating daily interest

void calculateDailyInterest()

{

accountbalance +=accountbalance+accountbalance*0.05;

}

}

//File Name : AccountDemo.java

public class AccountDemo

{

public static void main(String args[:

```)throws Exception   {   //declaring variables   Savings sAcc=new Savings(0,0.0);   Checking cAcc=new Checking(0,0.0);   int choice;   int ano;   double balance;   Scanner scan=new Scanner(System.in);   //do loop   do   {   System.out.println("1. create new checking account");   System.out.println("2. create new savings");   System.out.println("3. make deposit");   System.out.println("4. make withdraw");   System.out.println("5. display all accounts");   System.out.println("6. calculate daily interest");   System.out.println("7 exit");   choice=scan.nextInt();   switch(choice)   {   case 1:System.out.print("Enter Account Number:");   ano=scan.nextInt();   System.out.print("Enter Account Balance:");   balance=scan.nextDouble();   sAcc=new Savings(ano,balance);   break;   case 2:System.out.print("Enter Account Number:");   ano=scan.nextInt();   System.out.print("Enter Account Balance:");   balance=scan.nextDouble();   cAcc=new Checking(ano,balance);   break;   case 3:System.out.print("Enter Amount to deposit:");   balance=scan.nextDouble();   sAcc.deposit(balance);   cAcc.deposit(balance);   break;   case 4:System.out.print("Enter Amount to withdraw:");   balance=scan.nextDouble();   sAcc.withdraw(balance);   cAcc.withdraw(balance);   break;   case 5: sAcc.show();   cAcc.show();   break;   case 6: sAcc.calculateDailyInterest();   cAcc.calculateDailyInterest();   break;   case 7:System.exit(0);   }//end of switch   }while(true);//end of do-while   }//end of main   }//end of class```
• November 8th, 2013, 06:01 PM
Norm
Re: NEED HELP ALL the way with this..
That looks worse. Too many blank lines. The code and the }s don't make sense.
Too many statements start in the same column when the nested statements should be indented.