java - Where do I input values? -


java gurus,

working on class assignment , given set of 2 programs. 1 calls on calculate interest rate, balances, etc bank account. having problems with, figuring out supposed input variables given successful compile our program. below 2 java files given. made adjustments correct purposeful errors in code compiles nicely far.

public class bankaccount {     private double balance; // account balance     private double interestrate; // interest rate     private double interest; // interest earned      /**      * constructor initializes balance      * , interestrate fields values      * passed startbalance , intrate.      * interest field assigned 0.0.      */     public bankaccount(double startbalance, double intrate) {         balance = startbalance;         interestrate = intrate;         interest = 0.0;     }      /**      * deposit method adds parameter      * amount balance field.      */     public void deposit(double amount) {         balance += amount;     }      /**      * withdraw method subtracts      * parameter amount balance      * field.      */     public void withdraw(double amount) {         balance -= amount;     }      /**      * addinterest method adds interest      * month balance field.      */     public void addinterest() {         interest = balance * interestrate;         balance += interest;     }      /**      * getbalance method returns      * value in balance field.      */     public double getbalance() {         return balance;     }      /**      * getinterest method returns      * value in interest field.      */     public double getinterest() {         return interest;     } } 

here program2.java need compile:

import java.text.decimalformat; // needed 2 decimal place amounts import java.util.scanner; // needed scanner class  public class program2 {     public static void main(string[] args) {         bankaccount account; // reference bankaccount object         double balance, // account's starting balance             interestrate, // annual interest rate             pay, // user's pay             cashneeded; // amount of cash withdraw          // create scanner object keyboard input.         scanner keyboard = new scanner(system.in);          // create object dollars , cents         decimalformat formatter = new decimalformat("#0.00");          // starting balance.         system.out.print("what account's " + "starting balance? ");         balance = keyboard.nextdouble();          // monthly interest rate.         system.out.print("what monthly interest rate? ");         interestrate = keyboard.nextdouble();          // create bankaccount object.         account = new bankaccount(balance, interestrate);          // amount of pay month.         system.out.print("how paid month? ");         pay = keyboard.nextdouble();          // deposit user's pay account.         system.out.println("we deposit pay " + "into account.");         account.deposit(pay);         system.out.println("your current balance %bodyquot; + formatter.format( account.getbalance()  )");          // withdraw cash account.         system.out.print("how " + "to withdraw? ");         cashneeded = keyboard.nextdouble();         account.withdraw(cashneeded);          // add monthly interest account.         account.addinterest();          // display interest earned , balance.         system.out.println("this month have earned %bodyquot; + formatter.format( account.getinterest() )" +             " in interest.");         system.out.println("now balance %bodyquot; + formatter.format( account.getbalance() ) )");     } } 

what required enter 500 starting balance, 0.00125 monthly interest rate (interest compounded monthly in code , pretty sure know put variable), 1000 monthly pay , 900 withdrawl amount. end result should $600.75.

is of code there or need declare value of variables starting balance, interest rate, monthly pay , withdrawl amount?

please let me know if doing wrong, or if answer smack in front of face , blind today.

its copy paste issue in code.

change from:

system.out.println("your current balance %bodyquot; + formatter.format( account.getbalance()  )"); 

to:

 system.out.println("your current balance " + formatter.format( account.getbalance()  )); 

use below mentioned updated code.

import java.text.decimalformat; // needed 2 decimal place amounts import java.util.scanner; // needed scanner class  public class program2 {     public static void main(string[] args) {         bankaccount account; // reference bankaccount object         double balance, // account's starting balance             interestrate, // annual interest rate             pay, // user's pay             cashneeded; // amount of cash withdraw          // create scanner object keyboard input.         scanner keyboard = new scanner(system.in);          // create object dollars , cents         decimalformat formatter = new decimalformat("#0.00");          // starting balance.         system.out.print("what account's " + "starting balance? ");         balance = keyboard.nextdouble();          // monthly interest rate.         system.out.print("what monthly interest rate? ");         interestrate = keyboard.nextdouble();          // create bankaccount object.         account = new bankaccount(balance, interestrate);          // amount of pay month.         system.out.print("how paid month? ");         pay = keyboard.nextdouble();          // deposit user's pay account.         system.out.println("we deposit pay account.");         account.deposit(pay);         system.out.println("your current balance " + formatter.format( account.getbalance()  ));          // withdraw cash account.         system.out.print("how withdraw? ");         cashneeded = keyboard.nextdouble();         account.withdraw(cashneeded);          // add monthly interest account.         account.addinterest();          // display interest earned , balance.         system.out.println("this month have earned " + formatter.format( account.getinterest() ) +             " in interest.");         system.out.println("now balance " + formatter.format( account.getbalance() ) );     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -