subject

Modify the TimeSpan class from Chapter 8 to include a compareTo method that compares time spans by their length. A time span that represents a shorter amount of time is considered to be "less than" one that represents a longer amount of time. For example, a span of 3 hours and 15 minutes is greater than a span of 1 hour and 40 minutes. GIVEN TIMESPAN FILE/** Adapted for CS211 from Building Java Programs, 4th Edition,* by Stuart Reges and Marty Stepp* adapted by James Livingston, Bellevue College Adjunct Instructor*/// Represents a time span of elapsed hours and minutes.// Simple implementation using only total minutes as state. public class TimeSpan {private int totalMinutes;// Constructs a time span with the given interval.// pre: hours >= 0 && minutes >= 0public TimeSpan(int hours, int minutes) {totalMinutes = 0;add(hours, minutes);}// Adds the given interval to this time span.// pre: hours >= 0 && minutes >= 0public void add(int hours, int minutes) {totalMinutes += 60 * hours + minutes;}// Returns a String for this time span such as "6h15m".public String toString() {return (totalMinutes / 60) + "h"+ (totalMinutes % 60) + "m";}}GIVEN TIMESPANMAIN FILE/** TimeSpanClient: a simple test client for the TimeSpan class* Shows creation of an instance object, displaying that object,* adding hours and minutes to that object, and showing the result.*/public class TimeSpanClient {public static void main(String[] args) {int h1 = 13, m1 = 30;TimeSpan t1 = new TimeSpan(h1, m1);System. out. println("New object t1: " + t1); h1 = 3; m1 = 40;System. out. println("Adding " + h1 + " hours, " + m1 + " minutes to t1");t1.add(h1, m1);System. out. println("New t1 state: " + t1);}}

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 17:00, xo216aaliyah216xo
How can data be added to a new table in data base
Answers: 1
image
Computers and Technology, 22.06.2019 00:30, Angellbatton6763
At an open or uncontrolled intersection, yield if a. your road is paved and the crossroad is not b. the cross road is paved and yours is not c. you have two or more passengers in your vehicle d. you did not yield in the last intersection
Answers: 1
image
Computers and Technology, 23.06.2019 00:40, QueenKy6050
Consider the following statements: struct nametype{string first; string last; }; struct coursetype{string name; int callnum; int credits; char grade; }; struct studenttype{nametype name; double gpa; coursetype course; }; studenttype student; studenttype classlist[100]; coursetype course; nametype name; mark the following statements as valid or invalid. if a statement is invalid, explain why. a.) student. course. callnum = "csc230"; b.) cin > > student. name; c.) classlist[0] = name; d.) classlist[1].gpa = 3.45; e.) name = classlist[15].name; f.) student. name = name; g.) cout < < classlist[10] < < endl; h.) for (int j = 0; j < 100; j++)classlist[j].name = name; i.) classlist. course. credits = 3; j.) course = studenttype. course;
Answers: 1
image
Computers and Technology, 23.06.2019 12:00, kp2078
What type of slide show is a dynamic and eye-catching way to familiarize potential customers with what your company has to offer? a. ole b. photo album c. brochure d. office clipboard
Answers: 2
You know the right answer?
Modify the TimeSpan class from Chapter 8 to include a compareTo method that compares time spans by t...

Questions in other subjects:

Konu
Mathematics, 15.12.2020 15:20