Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 9.2, Problem 16STQ
Program Plan Intro
- • Create a class named “MessageTooLongException” that extends “Exception”.
- ○ Define a default constructor that calls the parent class’s method using “super ()” by passing a message.
- ○ Define a parameterized constructor that calls the parent class’s method using “super ()” by passing a message that is given as the argument.
- • Create a class named “Main”.
- ○ Define the “main ()” method.
- ■ Create an object “e” for the class. Here the exception is thrown using default constructor.
- ■ Get and print the message using the method “e.getMessage()”.
- ○ Define the “main ()” method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
please solve this important, thanks.
public class Test {
public static void main (String [] args) {
Object circlel = new Circle ();
Object circle2 = new Circle ();
System.out.println(circlel.equals (circle2));
class Circle {
double radius;
class Circle {
double radius;
public boolean equals (Circle circle) {
public boolean equals (Object o) {
return this.radius =
( (Circle)o).radius;
return this.radius = circle.radius;
This is the question -
In Chapter 4, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game.
This is the code that I have so far but can't seem to get them to compare correctly -
public class Game {
private Team team1;
private Team team2;
private String time;
public Game(Team t1, Team t2, String time) {
// your code here
this.team1=t1;
this.team2 = t2;
if(team1 == team2)
this.time = time;
else
this.time = "Game cancelled!";
}
public Team getTeam1() {
// your code here
return team1;
}
public Team getTeam2()…
Chapter 9 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 9.1 - Prob. 1STQCh. 9.1 - What output would the code in the previous...Ch. 9.1 - Prob. 3STQCh. 9.1 - Prob. 4STQCh. 9.1 - Prob. 5STQCh. 9.1 - Prob. 6STQCh. 9.1 - Prob. 7STQCh. 9.1 - Prob. 8STQCh. 9.1 - In the code given in Self-Test Question 1,...Ch. 9.1 - In the code given in Self-Test Question 1,...
Ch. 9.1 - Prob. 11STQCh. 9.1 - Prob. 12STQCh. 9.1 - Prob. 13STQCh. 9.1 - Prob. 14STQCh. 9.2 - Prob. 15STQCh. 9.2 - Prob. 16STQCh. 9.2 - Prob. 17STQCh. 9.2 - Prob. 18STQCh. 9.2 - Prob. 19STQCh. 9.2 - Prob. 20STQCh. 9.2 - Suppose that, in Self-Test Question 19, we change...Ch. 9.2 - Prob. 22STQCh. 9.2 - Prob. 23STQCh. 9.3 - Prob. 24STQCh. 9.3 - Prob. 25STQCh. 9.3 - Prob. 26STQCh. 9.3 - Prob. 27STQCh. 9.3 - Prob. 28STQCh. 9.3 - Repeat Self-Test Question 27, but change the value...Ch. 9.3 - Prob. 30STQCh. 9.3 - Prob. 31STQCh. 9.3 - Prob. 32STQCh. 9.3 - Consider the following program: a. What output...Ch. 9.3 - Write an accessor method called getPrecision that...Ch. 9.3 - Prob. 35STQCh. 9.4 - Rewrite the class ColorDemo in Listing 9.13 so...Ch. 9.4 - Prob. 37STQCh. 9 - Write a program that allows students to schedule...Ch. 9 - Prob. 2ECh. 9 - Prob. 3ECh. 9 - Prob. 4ECh. 9 - Prob. 5ECh. 9 - Write code that reads a string from the keyboard...Ch. 9 - Create a class Rational that represents a rational...Ch. 9 - Prob. 9ECh. 9 - Suppose that you are going to create an object...Ch. 9 - Revise the class RoomCounter described in the...Ch. 9 - Prob. 12ECh. 9 - Write a class LapTimer that can be used to time...Ch. 9 - Prob. 1PCh. 9 - Prob. 2PCh. 9 - Prob. 3PCh. 9 - Write a program that uses the class calculator in...Ch. 9 - Prob. 3PPCh. 9 - Prob. 7PPCh. 9 - Prob. 9PPCh. 9 - Suppose that you are in change of customer service...Ch. 9 - Write an application that implements a trip-time...
Knowledge Booster
Similar questions
- This is the question - In Chapter 4, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game. This is the code it starts me with. I honestly have no clue where to start to change this - public class Game { private Team team1; private Team team2; private String time; public Game(Team t1, Team t2, String time) { // your code here } public Team getTeam1() { // your code here } public Team getTeam2() { // your code here } public String getTime() { // your code here } } public class Team { private String name; private String sport; private…arrow_forwardIn Java Attachedarrow_forwardThis is the question: In Chapter 4, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game. This is the code given: public class Game { private Team team1; private Team team2; private String time; public Game(Team t1, Team t2, String time) { // your code here } public Team getTeam1() { // your code here } public Team getTeam2() { // your code here } public String getTime() { // your code here } }arrow_forward
- JAVA Problem – CycleFileInput Revisit the Cycle class . Modify your application such that the properties will be read from a text file called “Cycle.txt”. Directions Examine your application for the class called Cycle. Add an appropriate throws statement in the main method. Create a reference to a File class with the appropriate name of a text file (Cycle.txt). Note: Cycle.txt was created in the previous assignment, CycleFileOutput. In your code, check that the text file does exist. Input the values from the file to memory. Close the file. public class Cycle { // Declear integer instance variable private int numberOfWheels; private int weight; // Constructer declear class public Cycle(int numberOfWheels, int weight ) { this.numberOfWheels = numberOfWheels; this.weight = weight; } // String method for output public String toString() { String wheel = String.valueOf(this.numberOfWheels); String load = String.valueOf(this.weight); return("No of wheels in cycle = " +…arrow_forwardMust be written in Python. Please include docstring and show how output should look like. Remember that all data members should be private. An object can access it's own private data members directly. It can also access the private data members of other objects of the same class directly. But when accessing a private data member of an object of another class, it needs to call the appropriate get method. If that sounds complicated, just remember this: if a method is in the same class as a private data member, then it can access that data member directly, otherwise, it needs to use a get method. Write a class named Point that has two data members, x_coord and y_coord, representing the two coordinates of the point. It should have: an init method that takes two arguments, an x-coordinate and y-coordinate (in that order), and uses them to initialize the two data members. get methods for the two data members: get_x_coord and get_y_coord. a method named distance_to that takes a Point object…arrow_forwardModify 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:arrow_forward
- https://youtu.be/4hAoK54Pfdc Here is a video regarding the kit component.arrow_forwardThis is the question - Create a UsedCarException class that extends Exception; its constructor receives a value for a vehicle identification number (VIN) that is passed to the parent constructor so it can be used in a getMessage() call. Create a UsedCar class with fields for VIN, make, year, mileage, and price. The UsedCar constructor throws a UsedCarException when the VIN is not four digits; when the make is not Ford, Honda, Toyota, Chrysler, or Other; when the year is not between 1997 and 2017 inclusive; or either the mileage or price is negative. Write an application that establishes an array of at least seven UsedCar objects and handles any Exceptions. Display a list of only the UsedCar objects that were constructed successfully. Here is the code I have - public class ThrowUsedCarException { public static void main(String[] args) { // Write your code here } } public class UsedCar { String vin; String make; int year; int mileage; int…arrow_forwardIn Java. 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. The words for output is highlighted in grey and yellow in the blue box. Class should be named Driver, as shown in blue box…arrow_forward
- Place the CashRegister calss in a file called cashregister.py and write following test code in the cell below. a Complete following test code: Import all methods of CashRegister class Write a test function to test the getTotal() and getCount() methods as it follows. add 5 items. undo the last item. add 3 more items. undo the last item after your test has done all of the above, print an statement for expected total price and total count. call the getTotal() and getCount(). (the result must be equal to the previous part) class CashRegister: def __init__(self): self._itemCount=0 self._totalPrice=0.0 self._taxPercent=13 def addItem(self,price): self._itemCount=self._itemCount+1 self._totalPrice=self._totalPrice+price def getTotal(self): return self._totalPrice def getCount(self): return self._itemCount def clear(self): self._itemCount=0 self._totalPrice=0 def updateTaxRate(self,newTaxPercent): if…arrow_forwardDescriptionIn this assignment, you are required to implement an electronic programming quiz system. User can createquestions and preview the quiz.Your TaskYou are asked to write a Java program for the programming quiz system. There are two types of questions:Multiple Choice Question and Ture/False Question. User can create questions using the system; andpreview the quiz, which display all questions in the system one by one. During the preview, the user canattempt the quiz by entering his/her answers to questions. The system will then immediately check theanswer and calculate. After attempting all questions, the total score will be displayed. A sample run of theprogram is shown as below (Green text refers to user input): Please choose (c)reate a question, (p)review or (e)xit >> cEnter the type of question (MC or TF) >> MCEnter the question text >> Each primitive type in Java has a correspondingclass contained in the java.lang package. These classes are called…arrow_forwardINSTRUCTIONS: Write a C++ script/code to do the given problem. Write a class called profileID, which has data members firstName,lastName, age, birthday and ageCompany (the age when you entered in the company). Remember to use set and get methods to access the data members this time. Also, write another class called bonusAward that has a method getBonus()with arguments yos and etype which are both integer data types. This method calculates the bonus received by an employee using this formula: yos*1000 + etype*1000. Write two derived classes, ASE and SE, using multiple inheritance usingprofileID and bonusAward as parent classes. Both classes must have amethod named getyos()that returns the yos of an employee using the formula age–ageCompany; and a method named getetype() which returns a constant based on the employee type. For ASE, the constant is 10 while for SE that constant is 20. Last, write a main program where you instantiate ASE as employee1 and SE as employee2. Get their…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,