SlideShare a Scribd company logo
Hi,
I have updated the code as per your requirement. Highlighted the code changes below.
Program2.java
import java.util.Scanner; // Needed for the Scanner class
import java.text.DecimalFormat; // Needed for 2 decimal place amounts
public class Program2
{
public static void main(String[] args)
{
BankAccount account; // To reference a BankAccount object
double balance, // The account's starting balance
interestRate, // The annual interest rate
pay, // The user's pay
cashNeeded; // The amount of cash to withdraw
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Create an object for dollars and cents
DecimalFormat formatter = new DecimalFormat ("#0.00");
// Get the starting balance.
System.out.print("What is your account's " + "starting balance? ");
balance = keyboard.nextDouble();
// Get the monthly interest rate.
System.out.print("What is your an annual interest rate? ");
interestRate = keyboard.nextDouble();
// Create a BankAccount object.
account = new BankAccount(balance, interestRate);
// Get the amount of pay for the month.
System.out.print("How much were you paid this month? ");
pay = keyboard.nextDouble();
// Deposit the user's pay into the account.
System.out.println("We will deposit your pay " + "into your account.");
account.deposit(pay);
System.out.println("Your current balance is " + formatter.format( account.getBalance() ));
// Withdraw some cash from the account.
System.out.print("How much would you like " + "to withdraw? ");
cashNeeded = keyboard.nextDouble();
account.withdraw(cashNeeded);
// Add the monthly interest to the account.
account.addInterest();
// Display the interest earned and the balance.
System.out.println("This month you have earned " + formatter.format( account.getInterest() ) +
" in interest.");
System.out.println("Now your balance is "+ formatter.format( account.getBalance() ) );
}
}
BankAccount.java
public class BankAccount
{
private double balance; // Account balance
private double interestRate; // Interest rate
private double interest; // Interest earned
/**
* The constructor initializes the balance
* and interestRate fields with the values
* passed to startBalance and intRate. The
* interest field is assigned to 0.0.
*/
public BankAccount(double startBalance, double intRate)
{
balance = startBalance;
interestRate = intRate / (12 * 100);
interest = 0.0;
}
/**
* The deposit method adds the parameter
* amount to the balance field.
*/
public void deposit(double amount)
{
balance += amount;
}
/**
* The withdraw method subtracts the
* parameter amount from the balance
* field.
*/
public void withdraw(double amount)
{
balance -= amount;
}
/**
* The addInterest method adds the interest
* for the month to the balance field.
*/
public void addInterest()
{
interest = balance * interestRate;
balance += interest;
}
/**
* The getBalance method returns the
* value in the balance field.
*/
public double getBalance()
{
return balance;
}
/**
* The getInterest method returns the
* value in the interest field.
*/
public double getInterest()
{
return interest;
}
}
Output:
What is your account's starting balance? 500
What is your an annual interest rate?
1.5
How much were you paid this month? 1000
We will deposit your pay into your account.
Your current balance is 1500.00
How much would you like to withdraw? 900
This month you have earned 0.75 in interest.
Now your balance is 600.75
Solution
Hi,
I have updated the code as per your requirement. Highlighted the code changes below.
Program2.java
import java.util.Scanner; // Needed for the Scanner class
import java.text.DecimalFormat; // Needed for 2 decimal place amounts
public class Program2
{
public static void main(String[] args)
{
BankAccount account; // To reference a BankAccount object
double balance, // The account's starting balance
interestRate, // The annual interest rate
pay, // The user's pay
cashNeeded; // The amount of cash to withdraw
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Create an object for dollars and cents
DecimalFormat formatter = new DecimalFormat ("#0.00");
// Get the starting balance.
System.out.print("What is your account's " + "starting balance? ");
balance = keyboard.nextDouble();
// Get the monthly interest rate.
System.out.print("What is your an annual interest rate? ");
interestRate = keyboard.nextDouble();
// Create a BankAccount object.
account = new BankAccount(balance, interestRate);
// Get the amount of pay for the month.
System.out.print("How much were you paid this month? ");
pay = keyboard.nextDouble();
// Deposit the user's pay into the account.
System.out.println("We will deposit your pay " + "into your account.");
account.deposit(pay);
System.out.println("Your current balance is " + formatter.format( account.getBalance() ));
// Withdraw some cash from the account.
System.out.print("How much would you like " + "to withdraw? ");
cashNeeded = keyboard.nextDouble();
account.withdraw(cashNeeded);
// Add the monthly interest to the account.
account.addInterest();
// Display the interest earned and the balance.
System.out.println("This month you have earned " + formatter.format( account.getInterest() ) +
" in interest.");
System.out.println("Now your balance is "+ formatter.format( account.getBalance() ) );
}
}
BankAccount.java
public class BankAccount
{
private double balance; // Account balance
private double interestRate; // Interest rate
private double interest; // Interest earned
/**
* The constructor initializes the balance
* and interestRate fields with the values
* passed to startBalance and intRate. The
* interest field is assigned to 0.0.
*/
public BankAccount(double startBalance, double intRate)
{
balance = startBalance;
interestRate = intRate / (12 * 100);
interest = 0.0;
}
/**
* The deposit method adds the parameter
* amount to the balance field.
*/
public void deposit(double amount)
{
balance += amount;
}
/**
* The withdraw method subtracts the
* parameter amount from the balance
* field.
*/
public void withdraw(double amount)
{
balance -= amount;
}
/**
* The addInterest method adds the interest
* for the month to the balance field.
*/
public void addInterest()
{
interest = balance * interestRate;
balance += interest;
}
/**
* The getBalance method returns the
* value in the balance field.
*/
public double getBalance()
{
return balance;
}
/**
* The getInterest method returns the
* value in the interest field.
*/
public double getInterest()
{
return interest;
}
}
Output:
What is your account's starting balance? 500
What is your an annual interest rate?
1.5
How much were you paid this month? 1000
We will deposit your pay into your account.
Your current balance is 1500.00
How much would you like to withdraw? 900
This month you have earned 0.75 in interest.
Now your balance is 600.75

More Related Content

PDF
Java programI made this Account.java below. Using the attached cod.pdf
PDF
public class NegativeAmountException extends Exception {    .pdf
PDF
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
PDF
Consider this C++ BankAccount class with the following public member.pdf
PDF
I need help creating a basic and simple Java program. Here is the ex.pdf
PDF
You are not setting any values for those variables(name, ID, interes.pdf
PDF
Interest.javaimport java.util.Scanner; public class Interest.pdf
PDF
The java program MortgagePayment that prompts user to .pdf
Java programI made this Account.java below. Using the attached cod.pdf
public class NegativeAmountException extends Exception {    .pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
Consider this C++ BankAccount class with the following public member.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
You are not setting any values for those variables(name, ID, interes.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdf
The java program MortgagePayment that prompts user to .pdf

Similar to Hi,I have updated the code as per your requirement. Highlighted th.pdf (15)

PDF
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
PDF
The java program that simulates ATM operations. The prog.pdf
DOCX
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
DOCX
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
PDF
The java Payroll that prompts user to enter hourly rate .pdf
PDF
Banks offer various types of accounts, such as savings, checking, cer.pdf
PDF
Create a new Java project and add the Account class into the source co.pdf
PDF
Lecture 09 high level language
PDF
Please distinguish between the .h and .cpp file, create a fully work.pdf
DOC
Procedure to create_the_calculator_application java
PDF
Cbse computer science (c++) class 12 board project bank managment system
PDF
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
PPT
Java: Class Design Examples
PPTX
Battle of React State Managers in frontend applications
PDF
The java class Account that simultes the Account class.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
The java program that simulates ATM operations. The prog.pdf
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
The java Payroll that prompts user to enter hourly rate .pdf
Banks offer various types of accounts, such as savings, checking, cer.pdf
Create a new Java project and add the Account class into the source co.pdf
Lecture 09 high level language
Please distinguish between the .h and .cpp file, create a fully work.pdf
Procedure to create_the_calculator_application java
Cbse computer science (c++) class 12 board project bank managment system
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Java: Class Design Examples
Battle of React State Managers in frontend applications
The java class Account that simultes the Account class.pdf
Ad

More from annaindustries (20)

PDF
This is Due to highest Cncentration of Comon Ions.pdf
PDF
There is no reaction. The nearest I can think of .pdf
PDF
The decomposition of hydrogen peroxide to gaseous.pdf
PDF
NaBr Na is metal and Br is electronegative. All.pdf
PDF
it is not hydrolyzed because of steric hindrance .pdf
PDF
Im not entirely sure what this is asking. I ass.pdf
PDF
HI = hydrogen iodide .pdf
PDF
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
PDF
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf
PDF
First remember that non polar compounds are solub.pdf
PDF
There are many types of malwares like Trojans, viruses, worms, rootk.pdf
PDF
The standard form of a complex number is a real number plusminus an.pdf
PDF
DNA and RNA .pdf
PDF
Solution-1. For this weSolutionSolution-1. For this we.pdf
PDF
Question) one or more attributes that comprise a primary key in a ro.pdf
PDF
pls provide the dataSolutionpls provide the data.pdf
PDF
Photosynthesis - is the unique process that is limited to plant king.pdf
PDF
Please follow the code and comments for description a)CODE #.pdf
PDF
Optimized Waterfall processIs a common project methodology and it.pdf
PDF
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
This is Due to highest Cncentration of Comon Ions.pdf
There is no reaction. The nearest I can think of .pdf
The decomposition of hydrogen peroxide to gaseous.pdf
NaBr Na is metal and Br is electronegative. All.pdf
it is not hydrolyzed because of steric hindrance .pdf
Im not entirely sure what this is asking. I ass.pdf
HI = hydrogen iodide .pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
Z = (x-mean)sd = (82-70)8 = 1.50SolutionZ = (x-mean)sd = (8.pdf
First remember that non polar compounds are solub.pdf
There are many types of malwares like Trojans, viruses, worms, rootk.pdf
The standard form of a complex number is a real number plusminus an.pdf
DNA and RNA .pdf
Solution-1. For this weSolutionSolution-1. For this we.pdf
Question) one or more attributes that comprise a primary key in a ro.pdf
pls provide the dataSolutionpls provide the data.pdf
Photosynthesis - is the unique process that is limited to plant king.pdf
Please follow the code and comments for description a)CODE #.pdf
Optimized Waterfall processIs a common project methodology and it.pdf
Organism Entameoeba histolyticQ AIt can be analyzed by feces te.pdf
Ad

Recently uploaded (20)

PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
advance database management system book.pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
IGGE1 Understanding the Self1234567891011
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
RMMM.pdf make it easy to upload and study
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Complications of Minimal Access Surgery at WLH
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Classroom Observation Tools for Teachers
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Weekly quiz Compilation Jan -July 25.pdf
advance database management system book.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
IGGE1 Understanding the Self1234567891011
UNIT III MENTAL HEALTH NURSING ASSESSMENT
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
Paper A Mock Exam 9_ Attempt review.pdf.
RMMM.pdf make it easy to upload and study
Final Presentation General Medicine 03-08-2024.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Complications of Minimal Access Surgery at WLH
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
What if we spent less time fighting change, and more time building what’s rig...
Classroom Observation Tools for Teachers
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
A powerpoint presentation on the Revised K-10 Science Shaping Paper

Hi,I have updated the code as per your requirement. Highlighted th.pdf

  • 1. Hi, I have updated the code as per your requirement. Highlighted the code changes below. Program2.java import java.util.Scanner; // Needed for the Scanner class import java.text.DecimalFormat; // Needed for 2 decimal place amounts public class Program2 { public static void main(String[] args) { BankAccount account; // To reference a BankAccount object double balance, // The account's starting balance interestRate, // The annual interest rate pay, // The user's pay cashNeeded; // The amount of cash to withdraw // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Create an object for dollars and cents DecimalFormat formatter = new DecimalFormat ("#0.00"); // Get the starting balance. System.out.print("What is your account's " + "starting balance? "); balance = keyboard.nextDouble(); // Get the monthly interest rate. System.out.print("What is your an annual interest rate? "); interestRate = keyboard.nextDouble(); // Create a BankAccount object. account = new BankAccount(balance, interestRate); // Get the amount of pay for the month. System.out.print("How much were you paid this month? "); pay = keyboard.nextDouble(); // Deposit the user's pay into the account. System.out.println("We will deposit your pay " + "into your account."); account.deposit(pay); System.out.println("Your current balance is " + formatter.format( account.getBalance() )); // Withdraw some cash from the account. System.out.print("How much would you like " + "to withdraw? ");
  • 2. cashNeeded = keyboard.nextDouble(); account.withdraw(cashNeeded); // Add the monthly interest to the account. account.addInterest(); // Display the interest earned and the balance. System.out.println("This month you have earned " + formatter.format( account.getInterest() ) + " in interest."); System.out.println("Now your balance is "+ formatter.format( account.getBalance() ) ); } } BankAccount.java public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields with the values * passed to startBalance and intRate. The * interest field is assigned to 0.0. */ public BankAccount(double startBalance, double intRate) { balance = startBalance; interestRate = intRate / (12 * 100); interest = 0.0; } /** * The deposit method adds the parameter * amount to the balance field. */ public void deposit(double amount) { balance += amount;
  • 3. } /** * The withdraw method subtracts the * parameter amount from the balance * field. */ public void withdraw(double amount) { balance -= amount; } /** * The addInterest method adds the interest * for the month to the balance field. */ public void addInterest() { interest = balance * interestRate; balance += interest; } /** * The getBalance method returns the * value in the balance field. */ public double getBalance() { return balance; } /** * The getInterest method returns the * value in the interest field. */ public double getInterest() { return interest; } }
  • 4. Output: What is your account's starting balance? 500 What is your an annual interest rate? 1.5 How much were you paid this month? 1000 We will deposit your pay into your account. Your current balance is 1500.00 How much would you like to withdraw? 900 This month you have earned 0.75 in interest. Now your balance is 600.75 Solution Hi, I have updated the code as per your requirement. Highlighted the code changes below. Program2.java import java.util.Scanner; // Needed for the Scanner class import java.text.DecimalFormat; // Needed for 2 decimal place amounts public class Program2 { public static void main(String[] args) { BankAccount account; // To reference a BankAccount object double balance, // The account's starting balance interestRate, // The annual interest rate pay, // The user's pay cashNeeded; // The amount of cash to withdraw // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Create an object for dollars and cents DecimalFormat formatter = new DecimalFormat ("#0.00"); // Get the starting balance. System.out.print("What is your account's " + "starting balance? "); balance = keyboard.nextDouble(); // Get the monthly interest rate. System.out.print("What is your an annual interest rate? ");
  • 5. interestRate = keyboard.nextDouble(); // Create a BankAccount object. account = new BankAccount(balance, interestRate); // Get the amount of pay for the month. System.out.print("How much were you paid this month? "); pay = keyboard.nextDouble(); // Deposit the user's pay into the account. System.out.println("We will deposit your pay " + "into your account."); account.deposit(pay); System.out.println("Your current balance is " + formatter.format( account.getBalance() )); // Withdraw some cash from the account. System.out.print("How much would you like " + "to withdraw? "); cashNeeded = keyboard.nextDouble(); account.withdraw(cashNeeded); // Add the monthly interest to the account. account.addInterest(); // Display the interest earned and the balance. System.out.println("This month you have earned " + formatter.format( account.getInterest() ) + " in interest."); System.out.println("Now your balance is "+ formatter.format( account.getBalance() ) ); } } BankAccount.java public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields with the values * passed to startBalance and intRate. The * interest field is assigned to 0.0. */ public BankAccount(double startBalance, double intRate)
  • 6. { balance = startBalance; interestRate = intRate / (12 * 100); interest = 0.0; } /** * The deposit method adds the parameter * amount to the balance field. */ public void deposit(double amount) { balance += amount; } /** * The withdraw method subtracts the * parameter amount from the balance * field. */ public void withdraw(double amount) { balance -= amount; } /** * The addInterest method adds the interest * for the month to the balance field. */ public void addInterest() { interest = balance * interestRate; balance += interest; } /** * The getBalance method returns the * value in the balance field. */ public double getBalance()
  • 7. { return balance; } /** * The getInterest method returns the * value in the interest field. */ public double getInterest() { return interest; } } Output: What is your account's starting balance? 500 What is your an annual interest rate? 1.5 How much were you paid this month? 1000 We will deposit your pay into your account. Your current balance is 1500.00 How much would you like to withdraw? 900 This month you have earned 0.75 in interest. Now your balance is 600.75