Results 1 to 3 of 3
  1. #1
    thecodingnewb is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default I need SERIOUS help. I'm an idiot at coding.

    Assignment.

    Define a class where one object represents one savings account. Call your class "SavingsAccount". A savings account is made up of a deposit and an annual interest rate so these will be the private member (aka "instance") variables of your class SavingsAccount. After you have successfully coded and tested this class, you will have to write a more complicated main() that prints a table showing how an initial deposit grows after a number of years.

    What will be the member methods for your class? You will need methods to set the value of each of your member variables. You will also need a method that calculates and returns the future investment value for the savings plan after a certain number of years. This member method will be called futureInvestmentValue(). Because the method futureInvestmentValue() is also a member of the class SavingsAccount, this method will automatically have access to the private member variables, so you don't need to send in values for the deposit nor the annual interest rate. But the main() will need to tell the futureInvestmentValue() method how long the deposit will be in the account, so the method will have a parameter for the number of years the investment will stay in the bank.

    The following formula calculates the future investment value when an initialDeposit is left in a bank account for some years which compounds interest monthly at monthlyInterestRate:

    futureInvestmentValue = initialDeposit * (1 + monthlyInterestRate) years*12

    Here is a main() that will test whether your futureInvestmentValue() method works or not.

    /**

    * Tests class SavingsAccount by creating a

    * SavingsAccount object and printing

    * the amount that would be in it after 10 years.

    */

    class TestSavingsAccount {

    public static void main(String args[]) {

    SavingsAccount saver;

    saver = new SavingsAccount ();

    saver.setDeposit(1000);

    saver.setAnnualInterestRate(0.0325);

    System.out.println(saver.futureInvestmentValue(10) );

    // prints the amount in the account after 10 years.

    // expected output: 1383.42

    }

    }

    Hint: Even though the main() sets the annual interest rate, the futureInvestmentValue() method calculates using the corresponding monthly interest rate. This is because banks usually advertise their annual interest rate but they actually compound the interest monthly.

    Do not proceed with this assignment until the program above gives the expected output.

    Now the final part of this assignment is to modify the main() to print a table that shows how much the deposit grows each year over a period of years. In order to complete this part of the assignment, you will leave your class SavingsAccount untouched. The rest of this assignment is to be completed by modifying the class TestSavingsAccount only.

    There will be one row in the table for each year, and the table will have two columns: one for the number of the year and one for the amount in the account (including the interest) at the end of that year. Modify your main() so that it prints such a table by repeatedly calling your futureInvestmentValue() method in class SavingsAccount. Note that you earn more interest each month of each year because the interest is compounded. Under no circumstances are you to modify the class SavingsAccount for this part of the assignment.

    THIS IS WHAT I HAVE AND IT'S NOT WORKING! :( SO SAD. I MUST BE AN IDIOT. I'VE BEEN WORKING ON THIS FOR THE PAST 13 HOURS AND STARTED OVER SO MANY TIMES!!!!! HARDEST CLASS I'VE EVER TAKEN IN MY LIFE. I've taken some challenging classes ACCOUNTING 1B, BUSINESS LAW, CALCULUS, etc... Nothing has challenged me like this Java class :(


    XML Code:
    public class Investment {
        private int years;
        private double deposit;
        private double annualInterestRate;
        private double monthlyInterestRate;
        public double futureInvestmentValue;
        
            public void setDeposit  (int newDeposit) {
            deposit = newDeposit;
        }
        public void setAnnualInterestRate (double newAnnualInterestRate) {
            annualInterestRate = newAnnualInterestRate;
        }    
        
        public double getAnnualInterestRate() {
            return annualInterestRate;
        }
        public double getDeposit () {
            return deposit;
        }
        
            public Investment() {
                
                
                 years = 1;
                 deposit = 1000;
                 
                System.out.print( "First Year:  ");
                monthlyInterestRate = 0.0325 / 12;
                futureInvestmentValue = deposit * Math.pow((1 + 
                        monthlyInterestRate),(years * 12));
    
                }
    }
    The output is suppose to look like this :(

    Year Balance

    1 xxxx.xx

    2 xxxx.xx

    3 xxxx.xx
    .
    .
    .
    .
    .
    .
    .
    10 xxxx.xx

    :( so HARD!!!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: I need SERIOUS help. I'm an idiot at coding.

    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: I need SERIOUS help. I'm an idiot at coding.

    What is your output? Does it make sense after one year?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 01-16-2012, 06:23 AM
  2. (Me <= idiot)?
    By truant420 in forum AWT / Swing
    Replies: 8
    Last Post: 03-11-2011, 05:31 PM
  3. Java idiot...help!!!
    By usa100 in forum New To Java
    Replies: 2
    Last Post: 01-05-2011, 02:49 PM
  4. Replies: 4
    Last Post: 10-25-2010, 03:49 PM
  5. Am I an IDIOT ?????????????
    By Mandilon in forum New To Java
    Replies: 1
    Last Post: 02-02-2008, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •