SlideShare a Scribd company logo
1 of 7
Download to read offline
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

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

Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfMAYANKBANSAL1981
 
The java program that simulates ATM operations. The prog.pdf
  The java program that simulates ATM operations.  The prog.pdf  The java program that simulates ATM operations.  The prog.pdf
The java program that simulates ATM operations. The prog.pdfpoddaranand1
 
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docxCSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx
CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docxruthannemcmullen
 
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...sriram sarwan
 
The java Payroll that prompts user to enter hourly rate .pdf
  The java Payroll that prompts user to enter  hourly rate .pdf  The java Payroll that prompts user to enter  hourly rate .pdf
The java Payroll that prompts user to enter hourly rate .pdfangelfashions02
 
Banks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdfBanks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdfrajeshjain2109
 
Create a new Java project and add the Account class into the source co.pdf
Create a new Java project and add the Account class into the source co.pdfCreate a new Java project and add the Account class into the source co.pdf
Create a new Java project and add the Account class into the source co.pdfadmin618513
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language鍾誠 陳鍾誠
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfneerajsachdeva33
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application javagthe
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment systempranoy_seenu
 
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdfAccount.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdfanujmkt
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design ExamplesTareq Hasan
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsEvangelia Mitsopoulou
 
The java class Account that simultes the Account class.pdf
   The java class Account that simultes  the Account class.pdf   The java class Account that simultes  the Account class.pdf
The java class Account that simultes the Account class.pdfakshay1213
 

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

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

More from annaindustries

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

More from annaindustries (20)

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

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

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