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
Textbook Question
Chapter 9, Problem 11PP
Write an application that implements a trip-time calculator. Define and use a class TripComputer to compute the time of a trip. TripComputer should have the private attributes
- totalTime—the total time for the trip
- restStopTaken—a boolean flag that indicates whether a rest stop has been taken at the end of the current leg
and the following methods:
- computeLegTime (distance, speed) —computes the time for a leg of the trip having a given distance in miles and speed in miles per hour. If either the distance or the speed is negative, throws an exception.
- takeRestStop (time)—takes a rest stop for the given amount of time. If the time is negative, throws an exception. Also throws an exception if the client code attempts to take two rest stops in a row.
- getTripTime—returns the current total time for the trip.
- Here is one possible configuration of the labels, buttons, and text fields required by the trip-time calculator:
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Computer Science
You are required to develop a small chatting application where two or more friends can communicate each other through messages.
Create a class Message which has Date d, and message (string). Provide getters/setters, constructors, toString.
Create a class Friend having String name, String contact, email and ArrayList of Messages provide getters/setters, constructors, toString addMessage(Message m) method which will add new message to the list.
Provide following options to the user using JFrame.
Login which will help user login to the application.
View Friends (Display List of All Friends)
View Messages ( This should display all message of a Friend)
Send message (This should ask for friend name and message match the friend name and write that message to the array list).
Shape Class JAVA
Implement the Shapehierarchy shown in figure below.
Shape
TwoDimensionalShape
ThreeDimensionalShape
Circle
Square
Sphere
Cube
Each TwoDimensionalShape should contain method getArea to
calculate thearea of the two-dimensional shape.
• Each ThreeDimensionalShape should have methods getArea and
getVolume tocalculate the surface area and volume, respectively, of the
three- dimensional shape.
Add OneDimensionalShape with sub classes , and add more shapes
to classes (TwoDimensionalShape , ThreeDimensionalShape ).
Create a program that uses an array of Shape references to objects of
each concrete class in the hierarchy. The program should print a text
description of the object to which each array element refers.
• Also, in the loop that processes all the shapes in the array, determine
OneDimensionalShape,
whether
each
shape
is
a
TwoDimensionalShape or a ThreeDimensionalShape. If it is a
TwoDimensionalShape,
it is
display
ThreeDimensionalShape, display its area and volume.
its…
Exercise 6 - Loaded Coin Simulation
Make a new class in the Lab2 project called LoadedCoinSim that simulates the toss of a
loaded coin. A coin is loaded when it is constructed such that it is more likely to land on one
value than another. Assume the probability the coin will land head is HEAD_PROB, and declare
that as a constant in your program. Initially, use a value of 0.75, which means 75% chance the
coin will show heads. Given this probability, simulate ten coin tosses and displaying the result.
At the end, display the number of times the coin showed heads.
The output should appear like this:
Toss 1: HEADS
Toss 2: HEADS
Toss 3: HEADS
Toss 4: TAILS
Toss 5: HEADS
Toss 6: HEADS
Toss 7: HEADS
Toss 8: HEADS
Toss 9: TAILS
Toss 10: HEADS
Number of heads
= 8
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Given the following variable declarations: f s l d and the seven steps outlined in this chapter for conversion ...
Programming in C
T F: Clicking on a radio button selects it and leaves any other selected radio button in the same group selecte...
Starting Out With Visual Basic (8th Edition)
Write a structure declaration for a structure named Student that holds the following data about a student: ID (...
Starting Out with C++: Early Objects
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (8th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
Suppose the memory cells at addresses 0x00 through 0x07 in the Vole contain the following bit patterns: Address...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Object Oriented Programming in JAVA language please solvearrow_forwardDesign an application that does the following: A Solid can be a FlatSurfaceSolid or a CurvedSurfaceSolid. Every solid will have a volume. The method volume will be polymorphic. A solid has faces, vertices and edges. A flat-surface solid also has a variable called side which represents the length of the side. A curved-surface solid also has a radius. A Cube is a FlatSurfaceSolid. A cube has 6 faces, 8 vertices and 12 edges. It will have a side. A Sphere is a CurvedSurfaceSolid. It has 1 face, 0 vertices and 0 edges. It will have a radius. Create an ArrayList of solids (driver file named YourLastNameCISC231Q1.java). The arraylist will have 4 elements – 2 cubes (one with side length 3 and another will side length 4) and 2 spheres (one with radius 3 and another with radius 4). Create a driver class to instantiate an array of solids and display the details of each solid along with the volume of each solid.arrow_forwardAssignment:The BankAccount class models an account of a customer. A BankAccount has the followinginstance variables: A unique account id sequentially assigned when the Bank Account is created. A balance which represents the amount of money in the account A date created which is the date on which the account is created.The following methods are defined in the BankAccount class: Withdraw – subtract money from the balance Deposit – add money to the balance Inquiry on:o Balanceo Account ido Date createdarrow_forward
- Define a Student class, with 3 data fields: ID: string Name: string FavoriteThing: string Create an application that stores and outputs a list of the students' favorite things. Suppose each student only has one favorite thing.arrow_forwardCode the StudentAccount class according to the class diagramMethods explanation:pay(double): doubleThis method is called when a student pays an amount towards outstanding fees. The balance isreduced by the amount received. The updated balance is returned by the method.addFees(double): doubleThis method is called to increase the balance by the amount received as a parameter. The updatedbalance is returned by the method.refund(): voidThis method is called when any monies owned to the student is paid out. This method can onlyrefund a student if the balance is negative. It displays the amount to be refunded and set thebalance to zero. (Use Math.abs(double) in your output message). If there is no refund, display anappropriate message.Test your StudentAccount class by creating objects and calling the methods addFees(), pay() andrefund(). Use toString() to display the object’s data after each method calledarrow_forwardIn Java Language Create a CheckingAccount class to represent a checking account This class inherits from the Account class that you've created so far and has one new attribute, the overdraft limit, specifying how much the account can be overdrawn by. For example, if you have $100 in the account and you try to withdraw $150. This would be fine, if your overdraft limit was $50, meaning you can overdraw your account by $50 without penalty. Note: All you're doing at this stage is creating the limit, don't worry about dealing with the overdraft yet. You just want a variable at this stage. Your CheckingAccount class should also have getters and setters for the overdraft attribute and a constructor, but keep in mind how constructors work with inheritance. No other methods or adjustments are to be made at this time. Write a driver (or use your existing one) to test your CheckingAccount class by creating at least 1 instance and printing out its overdraft limit by using the getter.arrow_forward
- JAVA CODE PLEASE 3. Term by CodeChum Admin Construct a class called Term. It is going to represent a term in polynomial expression. It has an integer coefficient and an exponent. In this case, there is only 1 independent variable that is 'x'. There should be two operations for the Term: public Term times(Term t) - multiplies the term with another term and returns the result public String toString() - prints the coefficient followed by "x^" and appended by the exponent. But with the following additional rules: if the coefficient is 1, then it is not printed. if the exponent is 1, then it is not printed ( the caret is not printed as well) if the exponent is 0, then only the coefficient is printed. Input The first line contains the coefficient and the exponent of the first term. The second line contains the coefficient and the exponent of the second term. 1·1 4·3 Output Display the resulting product for each of the test case. 4x^4arrow_forwardclass Point { private: int x, y ; public: : x(u), y(v) {} Point (int u, int v) int getX) { return x; } int getY () { return y; } void doubleVal() { *= 2: y *= 2; } }; int main () { const Point myPoint (5, 3) myPoint.doubleVal() ; cout << myPoint.getX() << " " return 0; << myPoint.getY() << "\n"; }arrow_forwardObject Oriented Programming: 213COMP, 214COMP (Feb-2022) Assignment- I [10 marks] Academic honesty: O Only pdf file accepted & student ID, will be your upload file. O Student who submit copied work will obtain a mark of zero. O Late work or attach file by email message not allowed. Q1: Write the signature for a method that has one parameter of type String, and does not return a value. Q2: Write the signature for a method that has two parameters, both of type Student, and returns an int value. Q3: Write the constructor's headers of the followings? new Student (202101156, “Ahmed"); new Address(51, "jazan university","CS&IT" ); new Grade(true, 505235600, 4.5); Q4: a) Write a class Student that define the following information: name, stid , age. b) Explain a mutators (setters) and accessors(getters) methods for each attributes(fields). c) Add three constructors: • with empty constructor. one parameter constructor (name of student) two parameters constructor (name and stid) d) Create two…arrow_forward
- Rainfall Type Create a RainFall class that keeps the total rainfall in an array of doubles for each of the 12 months. Methods in the programme should return the following values: • the total annual rainfall; • the average monthly rainfall • the wettest month of the year • the month with the least amount of rain Demonstrate the class in its entirety. Validation of Input: Accepting negative amounts for monthly rainfall data is not permitted.arrow_forwardJAVA PROGRAMMING Write two java files for this assignment: Circle.java, and Main.java. The Circle.java file will create an actual class. The Circle class: MEMBER VARIABLE double radius double x double y Eight methods: Six of the methods are simple: getter’s and setter’s for x, y, and radius. There should also be a getArea method that returns the area (derived from the radius) A doesOverlap method. This method should accept a Circle as an argument, and return true if this circle overlaps the circle that the method was invoked on. [Note: two circles overlap if the sum of their radius' is greater than or equal to the distance between their centers.] void setX(double value) double getX() void setY(double value) double getY() void setRadius(double value) double getRadius() double getArea() boolean doesOverlap(Circle otherCircle) second class will be the typical replit Main class, with its static main method .It should contain code that tests the Circle class. submit code that…arrow_forwardJavaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.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,
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License