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 4 of 4

Thread: I need helping figuirding out why this program will not work. Due Tonight (11/08/13)

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

    Default I need helping figuirding out why this program will not work. Due Tonight (11/08/13)

    QUESTION:

    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
    (Note: user input is in red color)

    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
    Account 3 has balance 500.00
    *********************************
    6
    Account 1 gets interest 0.03
    Account 2 gets interest 0.06
    Account 3 gets interest 0.04
    5
    *********************************
    Account 1 has balance 1050.03
    Account 2 has balance 720.06
    Account 3 has balance 500.04
    *********************************
    7
    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.




    Currently What I have:

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


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    571
    My Mood
    Sleepy
    Thanks
    9
    Thanked 84 Times in 78 Posts

    Default Re: I need helping figuirding out why this program will not work. Due Tonight (11/08/13)

    Please use code formatting as described in the announcements. That mess is unreadable. And don't forget to ask a question.

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    161
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: I need helping figuirding out why this program will not work. Due Tonight (11/08/13)

    It would help greatly if you mentioned what exactly you're having issues with. This only shows us what you have, which is half of the solution, but you don't mention exactly what's wrong with it.

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

    Default Re: I need helping figuirding out why this program will not work. Due Tonight (11/08/13)

    I don't like doing work for other people so at this point i am just going to point out a few problems. if you still need help i will do my best

    well first i've got to say next time use code formatting. i'm assuming the reason it's not indented is because of that aswell but if not please start to indent... it's so hard to read without it.

    Now first thing you don't seem to be importing scanner in your demo class, so i've had to do that to make it compile obviously.

    now onto problems. first thing theres a typo on "Enter a new Account number" but that's not important.
    next your menu system doesn't correlate to what you have in your code. on the menu it says
    1. Create a new current account
    2. Create a new Savings account

    however on your switch statement in the code this is reveresed. this would make the calculations appear wrong.
    next the way you create the accounts at the moment you could only create one account of each type. judging by the testing at the top of your post you want to be able to make multiple accounts.

    when depositing you don't ask which account to deposit into. you just straight off deposit into both accounts, shouldn't be too hard to fix that one. (same goes for withdrawing money).

    and you havn't added the interest at all... seriously prime example of why you don't leave things till last minute :/

Similar Threads

  1. Project Nursing Home Due Tonight Help
    By morrism35 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: October 16th, 2013, 07:17 PM
  2. Using FOR and WHILE loops to find average (DUE TONIGHT)
    By cbh793 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 1st, 2013, 07:56 PM
  3. Replies: 1
    Last Post: December 5th, 2012, 09:58 PM
  4. Working on a Car Rental Program and need to finish by Tonight!!
    By alexsport93 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 13th, 2012, 10:08 PM
  5. Help On Java Homework (DUE TONIGHT!!!)
    By agmolina90 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 14th, 2011, 08:28 AM