Complete the code below according to the instructions below and the example test: method withdraw throws an exception if amount is greater than balance.
Q: Write a class that prompts the user for the day’s high and low temperatures. If the high is greater…
A: Step 1:- Note:-I am writing the program in the java language Program Approach:- Import the…
Q: create a class that asks a user for 2 string inputs (USE The Java. Util. SCANNER) -compare…
A: write a Program in java on string operations given in problem statement
Q: of the following code snippet. class Test int test a, test b Test(int a, int b) test aa test b- b; )…
A: Here is the two codes First code and second code examples of inheritance.
Q: Write a method dominant that accepts three integers as parameters and returns true if any one of the…
A: We need to write dominant method that accepts three integers as parameters and returns true if any…
Q: Question: Change this code in java just with changing abstraction and exception handling…
A: Answer: I have given answer in the brief explanation.
Q: nalyze the following code:
A: Program Analysis In the main method, The integer array "x" is initialized with 6 values from 0 to 5…
Q: Write a JAVA program to define a static method checkPT() to receive 3 positive integer parameters…
A: public class InvalidPythagoreanTripletException extends Exception{ public…
Q: Define stubs for the methods called by the below main(). Each stub should print "FIXME: Finish…
A: This program print the method name and average. The name of the program is MthdStubsStatistics.…
Q: Complete the following programs to demostrate use of local variables. Will "amount" and "balance"…
A: class CheckingAct{ private String accountNo; private String name;…
Q: Create a class named Employee with a method information. Then take the input of n number of…
A: CODE FOR THE ABOVE QUESTION import java.util.Scanner; import java.io.*; import java.io.file; public…
Q: public class BackAccount { public double Balance { set; get; } public void Deposit(double amount) {…
A: //****************************************************************************** // File:…
Q: Your cousin owns an automotive maintenance shop that performs routine maintenance on cars. He has…
A: The required methods will be defined as follows: carMaintenace method: This method will take the…
Q: With throws topic, write a java method which takes 'a' as a parameter and returns it's reciprocal.…
A: With throws, write a java method which takes 'a' as a parameter and returns its reciprocal.
Q: Consider the following method header, and then write a call to this method that passes the integer…
A:
Q: Class: DoubleMethod Write a method using the header below public static double…
A: Here in this program, I have completed the method which will take a prompt as an argument and return…
Q: 1. Create a class named Contact with the following attributes : First name, Middle name, Last name,…
A: Since you have asked multiple questions in a single request, we will be answering only the first…
Q: Write the CheckingAccount class so that the following code generates the output below: class…
A: numberOfAccount is a class level variable which can be accessed by using class name and this gets…
Q: public class CallStack{ // Called by func1() void func2 (){ System.out.println("In…
A: According to the information given:- We have to examine the code and handle the exception by…
Q: Implement the design of the Account class so that the following output is produced: Driver Code…
A: class Account(): def __init__(self, name='Default Account', bal=0.0): self.name = name…
Q: Write the missing code in the below program. A calendarDemo class is created with a setTime method…
A: Program Explanation: Import the classes for formatting date and handling exceptions Define a class…
Q: Complete both Unit Tests using the given code
A: Build Output is showing error as error: performOperation(double,double,String) has private access in…
Q: What Is The Output of the value of x ?, when the value of a :count=2 class test { private: int…
A: In this question we have to execute the given C++ class program with constructor and operator method…
Q: In this task, you are asked to write a program called Swap.java, including at least 3 following…
A: As per the above descriptions : method used: methods: Swap() swapDigitPairs(int num)…
Q: Provide answer in C# public class BackAccount { public double Balance { set; get; } public void…
A: Let’s build a sample banking program to perform the common tasks like Withdraw and Deposit. Task 1:…
Q: Write the CheckingAccount class so that the following code generates the output below: class…
A: ANSWER : Here I have given a python code with the given function name, please find the code, code…
Q: CreditCardTest.java: // Student Name Today's Date public class CreditCardTest { public…
A: The given code has two files "CreditCard.java" and "CreditCardTest.java". CreditCard.java: It is…
Q: Write a method named getSumOfRange that accepts two integer parameters min and max and returns the…
A: function sumAll(arr) { var a=[]; var b; if(arr[0]<arr[1]) { b=arr[0]; for(var…
Q: Write a method called method2 that keeps asking the user for their name (Use a loop and do NOT use a…
A: Java code: import java.util.Scanner; public class Main{ public static void main(String[] args) {…
Q: JAVA Create a class named Contact with the following attributes : First name, Middle
A: NOTE Below is the answer for the given question. Hope you understand it well. If you have any…
Q: BJP4 Exercise 4.16: printPalindrome Write a method called printPalindrome that accepts a Scanner…
A: PROGRAM: //Header file import java.util.Scanner; //Defining the main() class Main {…
Q: public class BackAccount { public double Balance { set; get; } public void Deposit(double amount) {…
A: Using code snippet above complete the bank account functionality..
Q: This code will be used to answer the question at the bottom. public class AccountBalance {…
A: Code for above mentioned problem is in step 2
Q: In this task, you are asked to write a program called Swap.java, including at least 3 following…
A: SOURCE CODE import java.util.Scanner; public class Main { //method to swap a number public…
Q: Write a test program named TestAccount that performs the following: • Create an Account object with…
A: A class is a user-defined data structure that contains encapsulates the data members and member…
Q: Define a public static method called squareArea that takes one double argument called length,which…
A: Algorithm: Start Define a method squareArea() which takes side length of square as argument and…
Q: Need Q. sap in JAVA 1. Create a class named Contact with the following attributes : First name,…
A: /******************************************************************************…
Q: Write a program that uses separate class-level methods to print a table of integers and the digits…
A: The several class-level methods are that kind of methods that does not use the class object. These…
Q: IN JAVA "New Employee Gross Salary Calculator" Write a method that accepts an employee's yearly…
A: Please find the implementation of above code This code have been in java language as mentioned in…
Q: Start with the code below and complete the getInt method. The method should prompt the user to enter…
A: throw is the keyword used to explicitly throw an Exception
Q: 1. For each call of the method below, display the value that is returned public int retVal(int a,…
A: Explanation: In case of option d, if we pass x to a and y to b and if x takes 20, then y should…
Q: Consider the following code: public class Banker { private BankAccount[] accounts; public…
A: Consider the following code:public class Banker {private BankAccount[] accounts; public…
Q: 1. Write down a method that will take an integer as a parameter and will return 1 if the integer is…
A: Program description: n is the user input integer variable that is used to store the upper limit of…
Q: You need to read in and process the wind speeds in East London over the past few days. The maximum…
A: The methods including parameters are given. Minimum 4 to 8 reading are required from the user as…
Q: public static int bar (int number) { while (number > -3) { if (number > 5) { System.out.print…
A: Here in the function foo(), the value of the number is 9. Now in the function, it prints the SE115…
Q: public class Liquid { private int currentTemperature; public Liquid (int ct) { currentTemperature =…
A: Ans : The following that best explains why the getCurrentTemperature method does not work as…
Q: the code (also known as dry run). And then find the answer by executing the program. I expect not…
A: class TestApp { public static void main() { int odd=1; if(odd){…
Q: 2. TestScores Class Custom Exception Write an exception class named InvalidTestScore. Modify the…
A: Java is a programming language originally developed by James Gosling at Sun Microsystems (which is…
Q: public class A{ private int x; public A({ x=10; public void setX(int x) { this.x=x; } public int…
A: It is defined as programs can be asked from control statements, array, string, oops etc. Java basic…
Q: Write a program that estimates the cost of carpet for one or more rooms with rectangular floors.…
A: The program is written in Java. Check the program screenshot for the correct indentation. Please…
Complete the code below according to the instructions below and the example test:
method withdraw throws an exception if amount is greater than balance.
For example:
Test | Result |
---|---|
Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(5500.0); System.out.println("Balance: "+account.getBalance()); |
Insufficient: Insufficient funds. Balance: 5000.0 |
Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(500.0); System.out.println("Balance: "+account.getBalance()); |
Balance: 4500.0 |
Incomplete java code:
private String accntNumber;
private String accntName;
private double balance;
public Account(){}
public Account(String num, String name, double bal){
accntNumber = num;
accntName = name;
balance = bal;
}
public double getBalance(){ return balance;}
}
//your class here
Step by step
Solved in 2 steps
- Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each question has one correct answer. Thank you. Part 1 - Which of these keywords is used by the calling method to guard against the exception that is thrown by called method? A. tryB. throwC. throwsD. catchE. finally Part 2 - Which of the following is correct? A. All classes of Exception extend from Error.B. All classes of Error extend from Exception.C. All classes of Exception extend from Throwable.D. All classes of Throwable extend from Exception.E. All classes of Throwable extend from RuntimeException.Suppose you are asked to test the code below. The code: public String allocateRoom(int numOfEmps) throws IllegalArgumentException { if (numOfEmps == 0) throw new IllegalArgumentException(); if (numOfEmps < 5) return "Small"; if (numOfEmps < 10) return "Standard"; return "Large"; } Throws exception if there are no employees Returns small up to 5 employees Returns standard for 5 to 9 employees Returns large for 10 or more employees List the minimum amount of test inputs that achieve 100% branch coverage. You need to specify the branch(es) each input covers. List the minimum amount of test inputs that achieve 100% path coverage. You need to specify the path each input covers. Explain if executing the test suites above will reveal any defects.Write a Java program to read the mobile number of an Employee. If the mobile number does not start with 9 or doesn't contain exactly 8 digits, throw a user defined exception InvalidNumberException. If the number entered is valid, display the message “correct mobile number is entered!” otherwise display “Entered mobile number is invalid!!” [Hint: Use String.valueOf(num).length() methods to first convert the gsm number (num) to string and then find the length of the string]
- Let's revisit chapter 5 example, but this time, no method can throw any exception out of the method and if an exception was detected then you will have to throw your own custom exception to let the user know what happened. public class Chapter11Demo{ public static void main(java.lang.String[] args) {method1();}private static void method1(){ method2();}private static void method2(){ method3();}private static void method3(){ method4();}private static void method4(){ method5();}private static void method5(){ method6();}private static void method6(){ java.io.File in=new java.io.File("somefile.txt"); java.io.File out=new java.io.File("somefile2.txt"); java.util.Scanner inFile=new java.util.Scanner(in); java.io.FileWriter outFile=new java.io.FileWriter(out); }}public class BackAccount{public double Balance { set; get; }public void Deposit(double amount){Balance = Balance + amount;} }Transaction FeesTransaction TypeDeposit Withdrawal Check BalanceAmount0.25 % of the deposit amount 0.5 % of the withdrawal amount FreeQ.1.1Amount0.25 % of the deposit amount 0.5 % of the withdrawal amount FreeQ.1.1Using the code snippet above, complete the bank account functionality by adding Withdraw and CheckBalance methods. In your definition for the Withdraw method, check if the account has sufficient funds before making a withdrawal. Apply transaction fees as per the table above: Q.1.2Using the transaction fees table and code snippet above, modify the Deposit method to include transaction fee charge.Q.1.3Generate a UML class diagram for the class definition above. Complete Q.1.1 and Q.1.2 before completing this question.Q.1.4Write a Unit Test class for the class used in Question 1 above. Name the unit test class “BankAccountTests”.Create a test method name…This is the question - Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays the message Can't take square root of negative number. Code I was given - import java.util.*; public class SqrtException { public static void main(String[] args) throws ArithmeticException { // Write your code here } }
- The following code is causing an exception during the runtime. class test{ public static void main(String[] args) { Object o = "Hello"; Object s = new Random(); m(o); m(s); } public static void m(Object o) { String s = (String)o; System.out.println(s.length()); }} Exception can be prevented by adding an if statement and type casting in the method m Exception can be handled by adding try-catch in the main method answers A or B both works Non of the answersConsider the following code:public class Banker {private BankAccount[] accounts; public Banker(BankAccount[] theAccounts) {accounts = theAccounts;} public BankAccount[] updateOverDueAccounts() {try {for (BankAccount anAccount : accounts) {if (anAccount.getOverdueAmount() <= 250) {anAccount.setOverdueFlag();}}}catch (Exception ex) {System.out.println ("Exception: " + ex.getMessage());}return accounts;}}Calculate the following metrics (IMPORTANT: show how each value was calculated):a- The Cyclomatic Complexity of the Banker constructor methodb- The Cyclomatic Complexity of the updateOverDueAccounts methodc- The WMPC (Weighted-methods-per-class) of the Banker classd- The CBO (Coupling-between-objects) of the Banker class.Java : Write the code segments in main( ) and in methodA( ) for the following scenario: main( ) passes methodA an int variable called a. methodA generates an exception, but does not deal with it, if a is not between 1 and 100. Hint: main will try and catch the exception and methodA throws exception.
- Write a method that will take in a time in 24 hour format (1430) and return the time in 12 hour format (2:30pm). This method should have appropriate exception handling. If an incorrect time is sent as an argument (something out of bounds or 23(#4k in other words garbage), then your method should throw a TimeFormatException which you define. In no case should your method throw an unhandled exception! Show how to test the method to be sure.Complete the following program that reads a file (where the file name is provided tothe main method as parameter) that contains the students’ information, adds 2 to thetotal marks (without updating the file), and prints student information and whether ispassed or not. public class ProcessGrades { public static void main(String[] args) throws Exception { String fileName = args[0]; Scanner s = new Scanner(Paths.get(fileName)); while(s.hasNext()) { // add you code here } }}You must pass the name of the file as option while running the file. So you can run yourprogram using a command line similar to: java ProcessGrades results.txtIt is supposed to have the following output (after running the program):100 Fahd 95.00 Passed101 Omar 52.00 Failed102 Anas 60.00 PassedA pedometer treats walking 2,000 steps as walking 1 mile. Write a stepsToMiles() method that takes the number of steps as an integer parameter and returns the miles walked as a double. The stepsToMiles() method throws an Exception object with the message "Exception: Negative step count entered." when the number of steps is negative. Complete the main() method that reads the number of steps from a user, calls the stepsToMiles() method, and outputs the returned value from the stepsToMiles() method. Use a try-catch block to catch any Exception object thrown by the stepsToMiles() method and output the exception message. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue);