Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
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 (8th 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 - Prob. 36STQCh. 9.4 - Prob. 37STQCh. 9.4 - Prob. 38STQCh. 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 - 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
In Exercises 1 through 52, determine the output produced by the lines of code. DimintRate,doublingTimeAsDecimal...
Introduction To Programming Using Visual Basic (11th Edition)
Write a function called showReading. It should accept a Reading structure variable (see Problem 21) as its argu...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Summarize the distinction between batch processing and interactive processing.
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
A ______ structure can execute a set of statements only under certain circumstances. a. sequence b. circumstant...
Starting Out with Python (4th Edition)
Answer question 3.33, but do not consider any pet having the breed of Unknown.
Database Concepts (8th Edition)
The current source in the circuit shown generates the current pulse
Find (a) v (0); (b) the instant of time gr...
Electric Circuits. (11th Edition)
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
- Design 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_forwardDefine 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_forward
- Code 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_forwardc# programMake a class called Employees, with attributes Name, Gender, Experience, Salary and ID.Make a delegate called EligiblePromo. This delegate takes an employees object as a parameter and returns a boolean value indication whether or not the employee should be promoted.Make a PromoteEmployee() method that takes an arraylist of Employees and delegate of type EligiblePromo as parametersNB: PromoteEmployee() methos loops through each Employees object and passes it to the delegate(25)arrow_forward
- Object 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_forwardFibonacci A fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers. For example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on… For this, you will implement a class that takes a positive integer (n) and returns the number in the nth position in the sequence. Examples When n is 1, the returned value will be 0. When n is 4, the returned value will be 2. When n is 9, the returned value will be 21. come up with the formula and base cases Implementation Create a class Fibonacci with a public static method getValue. Create a Main class to test and run your Fibonacci class.arrow_forwardRainfall 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_forward
- JAVA 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_forwardJava Programming Class Car Attributes (all private): vin: String (5 digits) make: String model: String year: int price: double Methods: Parameterized constructor for initializing a new Car instance Getters for all attributes toString method to display a Car's attributes Executable Class Create an array of at least ten Car objects. Be sure to use many with identical last years and different prices. Create an ArrayList from the array. Shuffle the ArrayList. Sort the ArrayList first by year and then by price. See page 790-791. Using the forEach method and a lambda expression, print all cars sorted as above. Create a LinkedList from the ArrayList. Create an iterator capable of cycling both forward and backward through the LinkedList. Iterate forward through the entire LinkedList but without generating any output. Then iterate backwards through the LinkedList to print the cars data.arrow_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