Concept explainers
Explanation of Solution
Modified code:
“Account.java”:
//Class Account
public class Account
{
//Private variable
private double balance;
//Define a constructor
public Account()
{
//Initialize the amount value
balance = 0;
}
//Parameterized constructor
public Account(double initialDeposit)
{
//Assign the value
balance = initialDeposit;
}
//Function to get balance
public double getBalance()
{
//Return the amount
return balance;
}
//Function to deposit the amount
public double deposit(double amount) throws NegativeAmountException
{
//Check if amount is greater than 0
if (amount > 0)
//Add the value to the balance
balance += amount;
//Else
Else
//return -1;
//Throw an exception
throw new NegativeAmountException();
//Return the balance
return balance;
}
//Function definition to withdraw the amount
public double withdraw(double amount) throws InsufficentBalanceException, NegativeAmountException
{
//Check if amount is greater than balance
if (amount > balance)
//throw an exception
throw new InsufficentBalanceException();
//Check if amount is less than 0
else if (amount < 0)
//Throw an exception
throw new NegativeAmountException();
//Else
else
//Calculate the balance
balance -= amount;
//Return the balance amount
return balance;
}
//Main method
public static void main(String[] args)
{
//Create an object for the class
Account a = new Account(10);
//Try block
try
{
//Deposit the value
a...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Value-returning methods must pass parameters. -True or -Falsearrow_forwardIf two methods in the same class have the same name, which is true? (choose one) They must have a different number of parameters They must have different return types They must have different parameter type lists The compiler must generate an error messagearrow_forwardtrue of false: a) The first step in any programming task is to start coding. b) The only places we would ever want to put a comment in our code are above a method and above a class.arrow_forward
- 11arrow_forwardmport java.util.Scanner; public class ParkingCharges { // function to calculate the basic charge using the asked hours static double getBasicCharge(int hours) { if (hours >= 7 && hours <= 8) return 5.50; else if (hours >= 5 && hours <= 6) return 4.50; else if (hours >= 2 && hours <= 4) return 4.00; return 3.00; } // function to return the amount to subtract based on local living and OAP static double getDiscount(String isLocal, String isOAP) { if (isOAP.equals("Yes") && isLocal.equals("Yes")) return 2.0 + 1.0; else if (isOAP.equals("Yes")) return 2.0; else if (isLocal.equals("Yes")) return 1.0; return 0; } public static void main(String[] args) { // create a new Scanner object Scanner sc = new Scanner(System.in); // prompt the user to ask if they are disabled…arrow_forwardOverloading a method and overriding a method are two separate but related concepts.arrow_forward
- Java programarrow_forwardpublic static class Lab2{public static void Main(){int idNum;double payRate, hours, grossPay;string firstName, lastName;// prompt the user to enter employee's first nameConsole.Write("Enter employee's first name => ");firstName = Console.ReadLine();// prompt the user to enter employee's last nameConsole.Write("Enter employee's last name => ");lastName = Console.ReadLine()// prompt the user to enter a six digit employee numberConsole.Write("Enter a six digit employee's ID => ");idNum = Convert.ToInt32(Console.ReadLine());// prompt the user to enter the number of hours employeeworkedConsole.Write("Enter the number of hours employee worked =>");// prompt the user to enter the employee's hourly pay rateconsole.Write("Enter employee's hourly pay rate: ");payRate = Convert.ToDouble(Console.ReadLine());// calculate gross paygrossPay = hours * payRate;// output resultsConsole.WriteLine("Employee {0} {1}, (ID: {2}) earned {3}",firstName, lastName, idNum,…arrow_forwardTrue or False A static method can reference an instance variable.arrow_forward
- Note: It`s python codingarrow_forwardprivate float c; private void method2(double y) { c = y; } in another class we created an object of the first class then within in it : tester.method2 (10.0f); are there any errors ? how many errors if there are any and with explanation please.arrow_forwardWhen a method call parameter is preceded by the word "out" in a piece of programming code, what does this imply?arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT