ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 06 Jun 2017 My Price 9.00

Design a class named Clock

Design a class named Clock. The class contains private data fields for startTime and stopTime, a no argument constructor that initializes the startTime to the current time, a method named start() that resets the startTime to the given time, a stop() method that sets the endTime to the given time and a getElapsedTime() method that returns the elapsed time in seconds. Construct a Clock instance and return the elapsed time. Command line arguments should be used to send the start and end times. You should use the java.time classes.

Here is sample run: java TestClock 11:45:12 11:48:13 Elapsed time in seconds is: 181

My professor looked at my following code and said : ask the user to press a key that will place the computer time into the start variable and then ask the user to wait some time and then have him press a key and at that point the same method will get the new current time in the computer and assign it to the end variable. With the two different times of start and end, you should be able to use your getElapsedTime () method to work."

He wants some interactive code where the user is prompted as asked in his feedback.  WARNING:  my professor is picky and wants things done as asked.  I am just under a time crunch here and do not understand how to use LocalTime.now(); through prompting the user to do what he is asking.  I could figure it out if I had hours but I don't.

The code so far:

import java.time.LocalTime;// Makes the LocalTime class visible
import java.time.Duration;// Makes the Duration class visible


/**
*
* @author
*/
public class Homework4 {//program name
  
public class Clock {
private LocalTime startTime;//start time
private LocalTime stopTime;//stop time
  
public Clock() {
// gets the current time from the system clock in the default time-zone
startTime = LocalTime.now();

}//end Clock

public void start(String start) {//sets start time
String[] time = start.split(":");// split Hours, minutes, seconds
startTime = LocalTime.of(Integer.parseInt(time[0]),Integer.parseInt(time[1]) ,Integer.parseInt(time[2]));//set the start time
}//end start method
  
public void stop(String stop) {//sets stop time
String[] time = stop.split(":");// split Hours, minutes, seconds
stopTime = LocalTime.of(Integer.parseInt(time[0]),Integer.parseInt(time[1]) ,Integer.parseInt(time[2]));//set the stop time
}//end stop method

public long getElapsedTime() {//getElapsedTime method
long expired = Duration.between(startTime,stopTime).getSeconds();//find the duration between the given two times
System.out.println( startTime + " " + stopTime);//print start and stop times
return expired;//returns expired time
}//end getElapsedTime

}//end class Clock

/**
* @param args the command line arguments
*/
public static void main(String[] args) {//begin main program
String startTime = "11:45:12";//start time
String endTime = "11:48:13";//stop time
  
Clock clock = new Clock();// create Clock instance

clock.start(startTime);//call start method
clock.stop(endTime);//call end method
long elapseTime = clock.getElapsedTime();
System.out.println("Elapsed time in seconds is " + elapseTime);//print elapsed time


}//end main
  
}//end Homework4 class

Answers

(11)
Status NEW Posted 06 Jun 2017 02:06 AM My Price 9.00

-----------

Attachments

file 1496717533-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)
Relevent Questions