The following class maintains an account balance and returns a special error code. public class Account { private double balance; // returns new balance or -1 if error public double deposit(double amount) { if (amount > 0) balance += amount; else return -1; // Code indicating error return balance; } } Rewrite the class so that it throws appropriate exception instead of returning -1 as an error code. Write test code that attempts to deposit
Q: c++ Declare an Animal class that has the attributes of Name, Genus, and Weight. Declare four…
A: #include <iostream> #include <sstream> using namespace std; class Animal { string…
Q: Create a class named Shape with a function that prints "This is a shape". Create another class named…
A: Inheritance refers to a class's ability to derive properties and characteristics from another class.…
Q: Write a program to create a class” Fan “to represents features of a fan as follows: “Fan “should…
A: Given: Write a program to create a class” Fan “to represents features of a fan as follows: “Fan…
Q: Create a classstudent which includes parameters roll_no, name and address and consider as super…
A: //code import java.util.Scanner; class Student3 { void Student(int roll, String name,int…
Q: Create a class MyTime which has the datamembers as follows: 1. hour: integer (1 to 12) 2. minute:…
A: #include <iostream>using namespace std; class MyTime{ private: int hour; int…
Q: Write a java program that declares two classes. The parent class is called Simple that has two data…
A: code: public class JavaExample{ int add(int num1, int num2) { return num1+num2; }…
Q: Define a public static method called bigWord that has a single String parameter called word. The…
A: The program is solved in Java and below is the code with explanation:
Q: amountofcontainers int amountofholds: int Gload (containes: int) load (type: String ) 1) Create a…
A: public class Ship { public int length; public double grosstonnage; public String flag; public…
Q: Define an iterator class named PrimeIterator foriteratingprime numbers. The constructor takes an…
A: PROGRAM: //Adding the required header file import java.util.Iterator; //Defining the class public…
Q: Doggie Day Care Given the TestDog class below, write a Dog class that will pass the tests contained…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: Define an iterator class named FibonacciIteratorfor iterating Fibonacci numbers. The constructor…
A: Program code: //import the required packages import java.util.Iterator; //Create a class…
Q: Modify the attached code: Create a new class called CalculatorWithMod. This class should be a sub…
A: Given: Modify the attached code: Create a new class called CalculatorWithMod. This class should be…
Q: 1. A constructor is a special type of method. 2. The following code will result in a compiler error:…
A: True/False for the given statements are: 1. True Explanation: In Java, a constructor is a block of…
Q: Implement the sub class FullTimeEmp This class has: • Data Fields Salary (double )should be> =260 JD…
A: super() can be used to call the constructor of parent class. It should be written in the first line…
Q: The code public class MyClass { private T myObject; public…
A: Given: The code public class MyClass<T> { private T myObject;…
Q: Given the following code segment. class Bike { private int wheels; public void setWheel(int wheel) {…
A: Q: Code the given problem in Java
Q: Write a class named StockPrices . The class constructor should accept an array of stock prices as…
A: public class StockPrices { double stockPrices[]; public StockPrices(double prices[]) {…
Q: A decimal number is composed of an integral part and a fractional part. The number appearing before…
A: SOLUTION: CODE: #ifndef ROUNDOFF_H #define ROUNDOFF_H #include<iostream>…
Q: Define a public static method called bigWord that has a single String parameter called word. The…
A: Steps TO follow -------------------------- -> Find length of word it can be done using String…
Q: plven the following code ublic class Account { private double balance; / instance variable that…
A: This is a simple Java code which makes use of Class and function to demonstrate encapsulation. In…
Q: Answer the question by looking at the following Java statement. Pick ONE that is correct. circleArea…
A: The statement: circleArea = super.calArea(); System.out.println(circleArea = super.calArea());
Q: Write a class named StockPrices . The class constructor should accept an array of stock prices as…
A: Actually, c++ is powerful general purpose language.
Q: #c++# Write a program that inputs a line of text, replaces all punctuation marks with spaces.
A: Note: - As per our guidelines we can only answer one question at a time. Please resubmit the other…
Q: Q4. Given below is the code for the controlling class with constructor overloading, analyse the code…
A: Constructor overloading a concept of having more than one constructors in class with different…
Q: Code: Create a Pizza class which stores information about a single pizza. It contains the…
A: It is defined as a general-purpose, high-level, simple but effective object-oriented programming…
Q: efine a class Human with properties "first name" and "last name". Define the class Student…
A: in this problem, we have to define different classes According to the conditions of the given…
Q: You must implement the pieces of the below classes on the following pages. You only should implement…
A: The methods that needs to be implemented are: Rectangle(const Point &ll, const Point &ur);…
Q: class A Q5: Correct the following code fragment and what will be the final results of the variable a…
A: Source Code #include <iostream> using namespace std; class A { protected: int…
Q: As part of conducting encapsulation related to a class, declare all instance variables in the class…
A: - We have to talk about the object priented ocncepts highlighted through the statements.
Q: a. Write a class named Student has the following data fields and methods: private int Id private…
A: *****NOTE: As programing language is not mentioned using c++ language to solve the above…
Q: java. write grading program for a class with the following grading policies. thers a total of 2…
A: Program1 public class gradingProgram{public static void main(String[] args){int quiz1;int quiz2;int…
Q: JAVA write grading program for a class with the following grading policies. thers a total of 2…
A: Logic: Average is calculated after giving weight-age to each marks. Function grading with attribute…
Q: A constructor: A always accepts two arguments B) has the same name as the class C) has return type…
A: A constructor is a special method of a class. The constructor will have the same name as the class…
Q: O Show Header BJP5 Self-Check 8.26: encapsulatedName Language/Type: Author: $ Java classes…
A: 8.26 Algorithm: Start Create a class Name with attributes firstName, lastName and middleInitial…
Q: Q1.) Write a Review class that has: • These private data members: • string user: ID of the user…
A:
Q: Create a class Student with following instance private variables and member functions: Variable: id…
A: Code: import java.util.Scanner; class Student { private int id; private String name, Major;…
Q: Define the class InvalidSideException, which inherits from the Exception class. Also define a Square…
A: In Java, we can create our own exceptions by extending Exception class that belongs to java.lang…
Q: Write a class named TestScores. The class constructor should accept an array of test scores as its…
A: c ++ code is an given below : #include <iostream> using namespace std; class TestScores {…
Q: Rational numbers are used to represent fractions. Arithmetic operations can also be performed on…
A: Sample Response: //java program, tested on NetBeans IDE 12.0package rational;import…
Q: JAVA PROGRAM !!! Write a program that converts a number entered in Roman numerals to decimal. Your…
A: import java.util.Scanner;class RomanToNumber{// This function returns value of a Roman symbolprivate…
Q: he Identity of the Customer it belongs to. The program should run in a loop; continuously asking the…
A: JAVA PROGRAM Write a program named AccountManager which stores customers’ details including…
Q: write a java programme: Vehicle class: First create an abstract Vehicle class that contains code…
A: To write a java program for given scenario which hold methods like class and interfaces. An…
Q: Suppose a program has the following class declaration: class CheckPoint {private: int a;protected:…
A: Given: Suppose a program has the following class declaration: class CheckPoint {private: int…
Q: Write a class named StockPrices . The class constructor should accept an array of stock prices as…
A: Program: #include <iostream> using namespace std; //class class StockPrices { public:…
Q: class A Q5: Correct the following code fragment and what will be the final results of the variable a…
A: Modified code with output provided in next step
Q: Write a derived class of the NumberGuesser class named RandomNumberGuesser. The derived class…
A: Solution is given below :
Q: rlined and followed by a "TODO: implement" comment. An example main function is provided to help you…
A: Below the program I have complete the task according to given discrimination.
Q: QUESTION 1: Implement class myTime, this class should: 1) Encapsulate information about the hours…
A: Objective: This program implements the working of a clock using a class "myTime". It includes…
Q: Language: C++ Write a Garage class that has a Car (i.e., object of a second class) that is having…
A: ANSWER:-
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
- !!!!!!!!!!Below is The following class maintains an account balance and returns aspecial error code.public class Account{private double balance;// returns new balance or -1 if errorpublic double deposit(double amount){if (amount > 0)balance += amount;elsereturn -1; // Code indicating errorreturn balance;}}Rewrite the class so that it throws appropriate exception instead ofreturning -1 as an error code. Write test code that attempts to depositinvalid amounts and catches the exceptions that are thrown/. Cosepublic abstract class Shape { public Shape() { } public abstract double area() ; public String who() { return "Shape" ; } } public class Circle extends Shape { private int radius ; public Circle( int r ) { radius = r ; } @Override public double area() { return Math.PI * radius * radius ; } } public class Square extends Shape { private int _sideLength ; public Square( int sideLength ) { /* TODO question 45 */ } @Override public double area() { return _sideLength * _sideLength ; } } Implement the Square constructor, and make sure it throws an exception when the input parameter is not a valid length. The input parameter must be positive to be considered valid.Modify the attached code: Create a new class called CalculatorWithMod. This class should be a sub class of the base class Calculator. This class should also have an additional method for calculating the modulo. The modulo method should only be seen at the sub class, and not the base class! Include exception handling for instances when dividing by 0 or calculating the modulo with 0. You would need to use throw, try, and catch. The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.Example: 20 mod 3 equals 2Because 20/3 = 6 with a remainder of 2 Refer also to the attached sample outputs:
- Write the CheckingAccount class so that the following code generates the output below: class Account: def __init__(self, balance): self._balance = balance def getBalance(self): return self._balance print('Number of Checking Accounts: ', CheckingAccount.numberOfAccount) print(CheckingAccount()) print(CheckingAccount(100.00)) print(CheckingAccount(200.00)) print('Number of Checking Accounts: ', CheckingAccount.numberOfAccount) OUTPUT: Number of Checking Accounts: 0 Account Balance: 0.0 Account Balance: 100.00 Account Balance: 200.00 Number of Checking Accounts: 3Write a class named StockPrices . The class constructor should accept an array of stock prices as its argument. The class should have a member function that returns the average of the stock prices. If any stock price in the array is negative or greater than 5000, the class should throw an exception. Demonstrate the class in a program. This is a question of c++In Java, Write a line of code that performs each of the following tasks : (a) Call superclass Employee's toString method from subclass Pieceworker's toString method. (b)Specify that class Pieceworker inherits from class Employee. (c) Call superclass Employee's constructor from subclass Pieceworker's constructor - assume that the superclass constructor receives three strings representing the first name, last name and social security number.
- The BankAccount class described below is used to represent a personal savings account with a yearly interest rate, (represented as a percentage, e.g., a 7% rate is represented by .07). The interest is applied monthly, (i.e., at the end of each month 1/12 of the interest is deposited into the account). public class BankAccount { public BankAccount(double rate) public BankAccount(double initBal, double rate) public double getBalance() public double getIntRate() public void setIntRate(double rate) public void deposit(double amount) public void withdraw(double amount) public void addMonthsInterest() private double balance; private double intRate; } Suppose a bank offers to its special customers a new type of savings account, called a “Credit Account”, that allows the customer to withdraw extra money if needed, so that the account balance is allowed to be negative at some times. These accounts award interest at the end of every month, as long as the balance is positive. If the…ANSWER IN JAVA Standard Output: Enter·side·length·of·square:Side·length·must·be·greater·than·0.↵ Define the class InvalidSideException, which inherits from the Exception class. Also define a Square class, which has one method variable -- an int describing the side length. The constructor of the Square class should take one argument, an int meant to initialize the side length; however, if the argument is not greater than 0, the constructor should throw an InvalidSideError. The Square class should also have a method getArea(), which returns the area of the square.Create a Driver class with a main method to test your classes. Your program should prompt the user to enter a value for the side length, and then create a Square object with that side length. If the side length is valid, the program should print the area of the square. Otherwise, it should catch the InvalidExceptionError, print "Side length must be greater than 0.", and terminate the program.//Todo write test cases for SimpleCalculator Class // No need to implement the actual Calculator class just write Test cases as per TDD. // you need to just write test cases no mocking // test should cover all methods from calculator and all scenarios, so a minimum of 5 test // 1 for add, 1 for subtract, 1 for multiply, 2 for divide (1 for normal division, 1 for division by 0) // make sure all these test cases fail public class CalculatorTest { //Declare variable here private Calculator calculator; //Add before each here //write test cases here }
- JAVA write grading program for a class with the following grading policies. thers a total of 2 quizzes, each graded on the basis of 10 points. theeres is 1 midterm exam and one final exam, each graded on the basis of 100 points. final exam counts for 50% of the grade, the midterm counts for 25%, and the 2 quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores.) letter grade will be given based on the following criterion: 90 – 100 A 80 – 89 B 70 – 79 C 60 – 69 D 0 – 59 E program will read student’s scores from a txf file, save them in an arrayor arrays), process the arrays), print the student’s record, which consists of the name, 2 quiz and 2 exam scores as well along with students avg numscore for the course and final letter rade. please noteAll the scores are integers and a student name consists of no more than 10 characters. justify output filein C# i need to Write the program BookExceptionDemo for the Peterman Publishing Company. Create a BookException class that is instantiated when a Book’s price exceeds 10 cents per page and whose constructor requires three arguments for title, price, and number of pages. Create an error message that is passed to the Exception class constructor for the Message property when a Book does not meet the price-to-pages ratio. For example, an error message: For Goodnight Moon, ratio is invalid. ...Price is $12.99 for 25 pages. Next, create a Book class that contains fields for title, author, price, and number of pages. Include properties for each field. Throw a BookException if a client program tries to construct a Book object for which the price is more than 10 cents per page. Finally, using the Book class, create an array of five Books. Prompt the user for values for each Book. To handle any exceptions that are thrown because of improper or invalid data entered by the user, set the Book’s…write a java programme: Vehicle class:First create an abstract Vehicle class that contains code common to all of the vehicles.1. Vehicle class has a color, IDnumber, and a model.2. Throw an exception named “InputNotCorrectException” if the IDnumber is negative.3. The accessor and mutator methods for all three data fields.4. Also include a void wheels() method which is declared abstract. Runnable interface:1.Deaclare an abstract method named HowToRun() which has a return type of void. Car class:Car class is a subclass of Vehicle which implements the Runnable interface.1. Write a class called Car which extends the Vehicle class and implements the Runnable interface.2. Override the equals method in the Object class. Two Car objects are equal if their models are thesame.3. In the Car class override the wheels() method to display “A car has four wheels”.4. A method named toString() that returns a string description for the car.5. Override the HowToRun() method to display “A car runs with…