1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NeTakaya
3 years ago
5

Design a class named Time. The class contains: The data fields hour, minute, and second that represent a time. A no-arg construc

tor that creates a Time object for the current time. (The values of the data fields will represent the current time.) A constructor that constructs a Time object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. (The values of the data fields will represent this time.) A constructor that constructs a Time object with the specified hour, minute, and second. Three getter methods for the data fields hour, minute, and second, respectively. A method named set Time(long elapsed Time) that sets a new time for the object using the elapsed time. For example, if the elapsed time is 555550000 milliseconds, the hour is 10, the minute is 19, and the second is 10. Write a test program that creates two Time objects (using new Time() and new Time(555550000)) and displays their hour, minute, and second in the format hour:minute:second. Hint: The first two constructors will extract the hour, minute, and second from the elapsed time. For the no-arg constructor, the current time can be obtained using System.currentTimeMillis()
Computers and Technology
1 answer:
sergejj [24]3 years ago
3 0

Answer:

import java.util.Scanner;

class Time

{

  int hour,min,sec;

 

      Time()

      {

      long millisecs=System.currentTimeMillis();

      sec=(int)millisecs%60;

      min=(int)(millisecs/60)%60;  

      hour=(int)(millisecs/(60*60))%24;

      }

 

      Time(long millisecs)

      {

      sec=(int)millisecs%60;

      min=(int)(millisecs/60)%60;  

      hour=(int)(millisecs/(60*60))%24;

      }

     

      Time(int hour,int min,int sec)

      {

          this.hour=hour;

          this.min=min;

          this.sec=sec;

      }

      void readTime()

      {

          Scanner s=new Scanner(System.in);

          System.out.println("Type Hours : ");

          hour=s.nextInt();

          System.out.println("Type mins : ");

          min=s.nextInt();

          System.out.println("Type sec : ");

          sec=s.nextInt();

      }

     

      void setTime(long ellapseTime)

      {

      sec=(int)ellapseTime%60;

      min=(int)(ellapseTime/60)%60;  

      hour=(int)(ellapseTime/(60*60))%24;

      }

     

      void showTime()

      {

          System.out.println("Time is(hh:mm:ss) - "+hour+":"+min+":"+sec);

      }

  }

  class ShowCurrentTime

  {

      public static void main(String args[])

      {  

          Time t1=new Time();

          Time t2=new Time(555550000);

          Time t3=new Time(4,46,34);

          t1.showTime();

          t2.showTime();

          t3.showTime();

      }

  }

Explanation:

  • Initialize the seconds, miliseconds, minutes and hours in the constructor of the Time class.
  • Take the hour, minute and seconds as an input from user inside the readTime method.
  • Calculate the hour, minute and seconds inside the setTime method.
  • Inside the main method, create object of the Time class and call the showTime method to display the time.
You might be interested in
What advantage does having ultraviolet vision give bees?
Art [367]
Ultraviolet helps bee's see depth and they can see 3 dimensional, they can also see long distance. Bee's have have single lenses that helps the bee maintain stability and navigate. 


5 0
3 years ago
Read 2 more answers
Many universities form tight-knit alumni networks, causing the alumni to continue to use each other as a resource for career pla
Dominik [7]

In the case above, this is an example of type of networking as alumni network.

<h3>What’s an alumni network?</h3>

An alumni network is known to be a kind of community of people that are linked as they have attended the same university and therefore, they act to support each other and stay linked to their alma mater.

Therefore, In the case above, this is an example of type of networking as alumni network.

Learn more about networking from

brainly.com/question/1027666

#SPJ1

6 0
2 years ago
Which of the following is an individual’s social equals?
ozzi
Its multiple choice what did they say
4 0
4 years ago
What does Pentium means?:/
netineya [11]
Pentium is just a brand of a CPU chips from Intel that is usually in your laptops or chromebooks. It's used for general purpose computing. Produced by Intel since 1993. 
4 0
3 years ago
Read 2 more answers
token is 64 bytes long (the 10-Mbps Ethernet minimum packet size), what is the average wait to receive the token on an idle netw
ikadub [295]

Given that,

Token is 64 bytes long

The average number of stations that the token must pass = 20

We need to calculate the transmission delay for token

Using formula of transmission delay

Transmission\ delay=\dfrac{token\ size}{minimum\ size}

Put the value into the formula

Transmission\ delay=\dfrac{64\ bytes}{10\ Mbps}

Transmission\ delay=\dfrac{64\times8}{10\times10^6}

Transmission\ delay=0.0000512\ sec

Transmission\ delay=5.12\times10^{-5}\ sec

We need to calculate the average wait to receive token on an idle network with 40 stations

Using formula of average wait

\text{average wait to receive token}=\text{average number of stations that the token must pass}\times transmission\ delay

Put the value into the formula

\text{average wait to receive token}=20\times5.12\times10^{-5}

\text{average wait to receive token}= 0.001024\ sec

\text{average wait to receive token}= 1.024\ ms

Hence, The average wait to receive token on an idle network with 40 stations is 1.024 ms.

8 0
4 years ago
Other questions:
  • You have implemented nap with dhcp enforcement, so you need to ensure you have an updated anti-virus software package, an update
    7·1 answer
  • Whoevr answers this will be marked brainliest
    12·1 answer
  • Which is the most used operating system? A. Windows B.Linux C.Leopard D. DOS
    14·2 answers
  • Examine the following declarations and definitions for the array-based implementations for the Stack and Queue ADTs. Assume that
    14·1 answer
  • When you need to move data over long distances using the internet, for instance across countries or continents to your amazon s3
    5·2 answers
  • Which information can you apply to every page of your document with the page layout options?
    9·1 answer
  • Gn guys have an Amazing day!
    12·2 answers
  • ¿Cómo afecta negativamente a las relaciones familiares el uso de la tecnología?
    7·1 answer
  • Who doesn't like reeses
    11·2 answers
  • Instruction: weird I know (~ ̄³ ̄)~
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!