Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 17 of 17

Thread: NEED HELP ALL the way with this..

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: NEED HELP ALL the way with this..


  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP ALL the way with this..

    I haven't tried anything...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: NEED HELP ALL the way with this..

    Quote Originally Posted by HelpMePlease View Post
    I haven't tried anything...
    No problems. Sit back and relax. I'll code it up for you, when is it due?
    Improving the world one idiot at a time!

  6. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP ALL the way with this..

    thanks!! tomorrow afternoon

  7. #7
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: NEED HELP ALL the way with this..

    That might be a bit tight. Didn't you say it might take 2 days Junky

  8. #8
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP ALL the way with this..

    nah...don't say that...lol

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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.

  10. #10
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


     
    //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

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: NEED HELP ALL the way with this..

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP ALL the way with this..

    did that work?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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...?


     
    //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

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
         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.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP ALL the way with this..

    NOW?


    )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

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.