CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2014
    Posts
    2

    Interest of deposit program help

    So i have a class project due at midnight and it's causing me a great deal of problems right now and I would appreciate any help I could get from anybody. the prompt is as follows;


    Input Specification:

    <Introductory Message Describing Program>
    Please enter the initial balance: 1000.00
    Please enter the interest rate: 6.50
    Please enter the number of years: 10

    Output Specification

    Ensure your columns are aligned for the sample input given above. Large balances may throw off your spacing. Again, that's OK.

    Year Balance Interest New Balance
    ---- ------- -------- -----------
    1 1000.00 65.00 1065.00
    2 1065.00 69.23 1134.22
    .
    .
    .
    10 ...

    Required Methods
    Implement each of these methods exactly as specified, including the parameters and return values
    // inform user what program will compute
    void printIntro ( )
    // This method is responsible for printing the headers for the table and generating the content of the table – it should call
    // printRow to print each individual row of the table
    void printTable (int numRows, double balance, double rate)
    // This method is responsible for printing a single row of the table
    void printRow (int rowNum, double balance, double interest)
    // This method calculates and returns the amount of interest
    double calcInterest (double balance, double rate)

    and as of right now this is what I have,

    see attached.
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2014
    Posts
    2

    Re: Interest of deposit program help

    didn't realize the pic would be that tiny. here it is written out;


    import java.text.DecimalFormat;
    import java.util.Scanner;
    public class Interest {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    printIntro();
    System.out.println();
    Scanner console = new Scanner(System.in);
    // get initial balance
    System.out.println("Please enter the initial balance: ");
    double balance = console.nextDouble();
    // get interest rate
    System.out.println("Please enter the interest rate: ");
    double rate = console.nextDouble();
    // get time
    System.out.println("Please enter the number of years");
    int time = console.nextInt();
    printTable(time, balance, rate);
    }
    //tells the user what this program will do
    public static void printIntro() {
    System.out.println("Given the initial balance, interest rate, and time, this program will compute the new balance of the CD.");
    }
    // prints headers for table and calculates number content within the table by calling printRow method
    public static void printTable(int time, double balance, double rate) {
    System.out.println("Year \t Balance \t Interest \t New Balance");
    System.out.println("---- \t ------- \t -------- \t -----------");
    printRow(time, balance, calcInterest(balance, rate));
    }
    // prints a single row of the table
    public static void printRow(int time, double balance, double interest) {

    double newBalance = balance + interest;

    //prints number of years entered by user onto table
    for (int i = 1; i <= time; i++){
    System.out.println(i + "\t" + balance + "\t" + interest + "\t" + newBalance);

    }
    }

    public static double calcInterest(double balance, double rate){
    double interest = balance * (rate/100);
    return interest;
    }
    }

  3. #3
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Interest of deposit program help

    What questions do you have about the rest of the problems?

    Please edit the post and wrap the code in code tags.
    Norm

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured