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
If the algorithm does not have instructions for unanticipated results, the computer program will a. solve a problem b. start ove
MrMuchimi

Answer: halt, just did the question

6 0
3 years ago
Create a class named TestCircle whose main() method declares Several Circle objects. Using the setRadius() method, assign one Ci
emmainna [20.7K]

Answer:ublic class Circle {

public int radius = 1;

public double diameter;

public double area;

//Constructor for circle class

public double Circle(int First){

return radius;

}

//Start set and get for radius

private double setRadius(int r){

   return radius = 5;

}

private double getRadius(){

 return radius;

}

//Start set and get for diameter

public double setDiamter(double d){

   return diameter = 7;

}

public double getDiamter(){

 return radius * diameter;

}

5 0
3 years ago
The primary function of a __________ is to translate the URL or web address a user enters in a web browser, into the correct cor
Mnenie [13.5K]
The primary function of a " Domain name server (DNS" is to translate the URL or web address a user enters in a web browser, into the correct corresponding IP address.
8 0
3 years ago
Complete the sentence.
Advocard [28]

The Hard drive storage is not recommended for long-term archiving because the storage media can degrade over time.

<h3>What is Long-term archiving?</h3>

Long-term archiving is known to be the act of  getting data, that are long-term in terms of accessibility and intelligibility.

Therefore, The Hard drive storage is not recommended for long-term archiving because the storage media can degrade over time.

Learn more about  Storage from

brainly.com/question/24227720

#SPJ1

7 0
3 years ago
Design a system for a book store that allows the owner to keep track of the store’s inventory and members. The store sells two t
IRINA_888 [86]

Hey! How are you? My name is Maria, 19 years old. Yesterday broke up with a guy, looking for casual sex.

Write me here and I will give you my phone number - *pofsex.com*

My nickname - Lovely

7 0
3 years ago
Other questions:
  • As the network administrator for a growing company, you’re asked to solve a remote access dilemma. The 12 employees who work fro
    6·1 answer
  • All digital images are made up from varying rectangles of color, called _____________.
    6·2 answers
  • Write a zip code class that encodes and decodes 5-digit bar codes used by the U.S. Postal Service on envelopes. The class should
    11·1 answer
  • Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For
    15·1 answer
  • Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is
    5·1 answer
  • A growling noise is heard only when the driver exerts force on the clutch pedal. No noise is heard when the clutch pedal is up.
    14·1 answer
  • True or False: In Google Cloud IAM: if a policy applied at the project level gives you Owner permissions, your access to an indi
    8·1 answer
  • I have no idea what I’m doing and this is due in 45 minutes
    7·1 answer
  • Which data type does not allow duplicate values-python
    6·1 answer
  • Doctrine Creative is a video production company with its own file server within its business office. The company needs to be abl
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!