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

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.;.pdf
MAYANKBANSAL1981
 
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
poddaranand1
 
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
ruthannemcmullen
 
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 .pdf
angelfashions02
 
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
rajeshjain2109
 
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
admin618513
 
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
neerajsachdeva33
 
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 system
pranoy_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.pdf
anujmkt
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design Examples
Tareq 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 applications
Evangelia 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.pdf
akshay1213
 

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.pdf
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
HI = hydrogen iodide .pdf
                     HI = hydrogen iodide                             .pdf                     HI = hydrogen iodide                             .pdf
HI = hydrogen iodide .pdf
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
DNA and RNA .pdf
                     DNA and RNA                                      .pdf                     DNA and RNA                                      .pdf
DNA and RNA .pdf
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 
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
annaindustries
 

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

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.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