Menu

[Solved]Bankaccount Class Simulates Bank Account Public Class Bankaccount Private Double Balance A Q37140863

/ 令 This progan denons tr ates the Sankaccount class. prtvate double balances ccouTE baTance his constructor sets, the starti

a bank account ublic class Bankaccount nport java. text. Decima1Format; / For the DecimalFormat clas private double balance:

/**
The BankAccount class simulates a bank account.
*/

public class BankAccount
{
private double balance; // Account balance

/**
This constructor sets the starting balance
at 0.0.
*/

public BankAccount()
{
balance = 0.0;
}

/**
This constructor sets the starting balance
to the value passed as an argument.
@param startBalance The starting balance.
*/

public BankAccount(double startBalance)
{
balance = startBalance;
}

/**
This constructor sets the starting balance
to the value in the String argument.
@param str The starting balance, as a String.
*/

public BankAccount(String str)
{
balance = Double.parseDouble(str);
}

/**
The deposit method makes a deposit into
the account.
@param amount The amount to add to the
balance field.
*/

public void deposit(double amount)
{
balance += amount;
}

/**
The deposit method makes a deposit into
the account.
@param str The amount to add to the
balance field, as a String.
*/

public void deposit(String str)
{
balance += Double.parseDouble(str);
}

/**
The withdraw method withdraws an amount
from the account.
@param amount The amount to subtract from
the balance field.
*/

public void withdraw(double amount)
{
balance -= amount;
}

/**
The withdraw method withdraws an amount
from the account.
@param str The amount to subtract from
the balance field, as a String.
*/

public void withdraw(String str)
{
balance -= Double.parseDouble(str);
}

/**
The setBalance method sets the account balance.
@param b The value to store in the balance field.
*/

public void setBalance(double b)
{
balance = b;
}

/**
The setBalance method sets the account balance.
@param str The value, as a String, to store in
the balance field.
*/

public void setBalance(String str)
{
balance = Double.parseDouble(str);
}

/**
The getBalance method returns the
account balance.
@return The value in the balance field.
*/

public double getBalance()
{
return balance;
}
}

import javax.swing.JOptionPane; // For the JOptionPane class
import java.text.DecimalFormat; // For the DecimalFormat class

/**
This program demonstrates the BankAccount class.
*/

public class AccountTest
{
public static void main(String[] args)
{
String input; // To hold user input

// Create a DecimalFormat object for displaying dollars.
DecimalFormat dollar = new DecimalFormat(“#,###.00”);

// Get the starting balance.
input = JOptionPane.showInputDialog(“What is your ” +
“account’s starting balance?”);

// Create a BankAccount object.
BankAccount account = new BankAccount(input);

// Get the amount of pay.
input = JOptionPane.showInputDialog(“How much were ” +
“you paid this month? “);

// Deposit the user’s pay into the account.
account.deposit(input);

// Display the new balance.
JOptionPane.showMessageDialog(null,
“Your pay has been deposited.n” +
“Your current balance is $ ” +
dollar.format(account.getBalance()));

// Withdraw some cash from the account.
input = JOptionPane.showInputDialog(“How much would ” +
“you like to withdraw? “);
account.withdraw(input);

// Display the new balance
JOptionPane.showMessageDialog(null,
“Now your balance is $” +
dollar.format(account.getBalance()));

System.exit(0);
}
}

He doesn’t say anything other than practice and Try compiling itkept giving error messages. what am i missing. Thank you for yourtime.

/ 令 This progan denons tr ates the Sankaccount class. prtvate double balances ccouTE baTance his constructor sets, the starting balance at 0.0 To hald se ingut balance 0,0; String inp cparan anount The Create ecinaFarmat object for diselaying dollars This constructor sets the starting batane lpar an starrealance blic void withdrawdouble anoumt) Get the starting balance The starting balance ccount’s starting bslance?”) blic sankaAccounk (double startealance) balance startealance the withdr an method wi thdr aws an anourt epar an str The anount to ssbtract from lic void withda(string str) balance . Double.parseoouble(str he sersalance nethod sets the account the balance leld, as a string this comtructor sets the startio you onid this month? “It sccount. deponitCinjut) eparanstr The starting balance, a Oisplay the ne balance. – van. Teiaalue to stre in the cur pay bee deposited do11ar. format (occount.getilace blic void secealance(double b) blic sankaccount (string str) balance-b balance Couble.parsepouble(str)i the depeu ts rethos nskes a deposit iml ite s blie vaid deposst(double anount) setealance sethod sets the xcount epar an str The vale, asa sering, blic vold setsalance(String str) balance Double, parsecouble(str): dollar.tot(count.get Ealanc): System.esitCO deposit mecthod makes deposit into1 The anste anount to add to thet alnnceeho r Add lass AccountTest second Gparan str The anount to idd to the blic void deposit (string str batance -Cocble. parsauble(strH ble in the balance field valve in the balance field The balance fleld. as a string ereturn ubTic double getaalance important: The class BankAccount java & AccountTest End of programn method] MUST be on same folder ! bankAccount return bal ance; tinue on part 2/2 Create the class BankAccount First a bank account ublic class Bankaccount nport java. text. Decima1Format; / For the DecimalFormat clas private double balance: / account balance This constructor sets the an demonstrates the BankAccount class. / starting balance at 0.0 bl1c BankAccount) lic class Accountrest 0 publ The withdr aw nethod withdr aws an anount balance -0.o public static void main(String] args) Gpar am anount The anount to subtract String inputst// To hold user input from the balance field This constructor sets the starting balanc teue passed as an ar gument.public void withdr aw double amount / tparhe stirtealance the stareing ba lancepublic void withdr aw(double anount) 1ic void withdraw(double amount) balanceamount // Get the starting balance. blic Bankaccount (double startBalance) The withdr aw method withdraws an anount account’s starting balance?) balance startsalance; from the account eparan str The amount to subtract from Sankaccount account nex Bankaccount (input); the balance field, as a String. This constructor sets the startina / blic void withdr an(String str) balance Double. parseDouble(str): to the value in the string argument. @paran str The starting balance, as a string. accoumt. deposit(sngue pay iate the account the set Balance net hod sets the account // Sparan b The value to store in the /Display the nex balance 0ptionPane. shosMess dollar.:Tormat(account. getbalanceO)) public void setealance(double b) public Bankaccount (string str) balance b balance Double. parseDouble(str); yThe deposit method makes a deposit intd // The setealance method sets the account account. wi thdraw input); the account.j Spar am str The value, as a string // to store in the balance field. Display the new balance blic void deposit (double amount) dollar. fornat (account.getSalanceO) ublic void setBalance(String str) balance + amount; The deposit method makes a deposit into par am str the anount to add to the ublic void deposit(string str) balance + Double. parseDouble(str); balance Double. parseDouble(str); Add class AccountTest second aihe amouns to add to thethe getsalance method returns the account balance balance field. as a string.recurn the value in the balance field. 11c double getsalance return balance; End of program (main method) MUST be on same folder l Continue on part 272 Show transcribed image text / 令 This progan denons tr ates the Sankaccount class. prtvate double balances ccouTE baTance his constructor sets, the starting balance at 0.0 To hald se ingut balance 0,0; String inp cparan anount The Create ecinaFarmat object for diselaying dollars This constructor sets the starting batane lpar an starrealance blic void withdrawdouble anoumt) Get the starting balance The starting balance ccount’s starting bslance?”) blic sankaAccounk (double startealance) balance startealance the withdr an method wi thdr aws an anourt epar an str The anount to ssbtract from lic void withda(string str) balance . Double.parseoouble(str he sersalance nethod sets the account the balance leld, as a string this comtructor sets the startio you onid this month? “It sccount. deponitCinjut) eparanstr The starting balance, a Oisplay the ne balance. – van. Teiaalue to stre in the cur pay bee deposited do11ar. format (occount.getilace blic void secealance(double b) blic sankaccount (string str) balance-b balance Couble.parsepouble(str)i the depeu ts rethos nskes a deposit iml ite s blie vaid deposst(double anount) setealance sethod sets the xcount epar an str The vale, asa sering, blic vold setsalance(String str) balance Double, parsecouble(str): dollar.tot(count.get Ealanc): System.esitCO deposit mecthod makes deposit into1 The anste anount to add to thet alnnceeho r Add lass AccountTest second Gparan str The anount to idd to the blic void deposit (string str batance -Cocble. parsauble(strH ble in the balance field valve in the balance field The balance fleld. as a string ereturn ubTic double getaalance important: The class BankAccount java & AccountTest End of programn method] MUST be on same folder ! bankAccount return bal ance; tinue on part 2/2 Create the class BankAccount First
a bank account ublic class Bankaccount nport java. text. Decima1Format; / For the DecimalFormat clas private double balance: / account balance This constructor sets the an demonstrates the BankAccount class. / starting balance at 0.0 bl1c BankAccount) lic class Accountrest 0 publ The withdr aw nethod withdr aws an anount balance -0.o public static void main(String] args) Gpar am anount The anount to subtract String inputst// To hold user input from the balance field This constructor sets the starting balanc teue passed as an ar gument.public void withdr aw double amount / tparhe stirtealance the stareing ba lancepublic void withdr aw(double anount) 1ic void withdraw(double amount) balanceamount // Get the starting balance. blic Bankaccount (double startBalance) The withdr aw method withdraws an anount account’s starting balance?) balance startsalance; from the account eparan str The amount to subtract from Sankaccount account nex Bankaccount (input); the balance field, as a String. This constructor sets the startina / blic void withdr an(String str) balance Double. parseDouble(str): to the value in the string argument. @paran str The starting balance, as a string. accoumt. deposit(sngue pay iate the account the set Balance net hod sets the account // Sparan b The value to store in the /Display the nex balance 0ptionPane. shosMess dollar.:Tormat(account. getbalanceO)) public void setealance(double b) public Bankaccount (string str) balance b balance Double. parseDouble(str); yThe deposit method makes a deposit intd // The setealance method sets the account account. wi thdraw input); the account.j Spar am str The value, as a string // to store in the balance field. Display the new balance blic void deposit (double amount) dollar. fornat (account.getSalanceO) ublic void setBalance(String str) balance + amount; The deposit method makes a deposit into par am str the anount to add to the ublic void deposit(string str) balance + Double. parseDouble(str); balance Double. parseDouble(str); Add class AccountTest second aihe amouns to add to thethe getsalance method returns the account balance balance field. as a string.recurn the value in the balance field. 11c double getsalance return balance; End of program (main method) MUST be on same folder l Continue on part 272

Expert Answer


Answer to /** The BankAccount class simulates a bank account. */ public class BankAccount { private double balance; // Account ba… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *