China MOOC_ object-oriented Programming--java language _ 2nd Week object Interaction _1 digital clock with seconds

Source: Internet
Author: User

2nd Week Programming Questions

View Help

return

2nd week programming, modified on the basis of the clock program given by the course

In accordance with the terms of academic integrity, I guarantee that this work is done independently.

Warm tips:

1. This assignment belongs to the online Judge topic and is enigmatic grading by the system immediately after submission.

2. Students can submit an unlimited number of answers before the deadline , and the system will take the highest score as the final result.

1 Digital clock with seconds (10 minutes)

Topic content:

This week's programming question requires that you modify the clock program given by the course. But we do not give you the code of the clock program directly, according to the video input the clock program's display, and clock Class code, and then to do this topic.

We need to add a display to the clock program that represents seconds, and then add the following public member functions for clock:

Public Clock (int hour, int minute, int second);

Initializes the time with hour, minute, and second.

public void tick ();

"Tick" a bit, time to walk 1 seconds.

Public String toString ();

Returns a String value that represents the current time as "Hh:mm:ss". Each of these values occupies two bits, which is less than two 0. such as "00:01:22". Note that the colon is in Latin, not Chinese.

Tip: String.Format () can format a string in the same way as printf.

Also write a main class, its main function for the following look, note, must be intact as main's main function:

public static void Main (string[] args) {

Java.util.Scanner in = new Java.util.Scanner (system.in);

Clock clock = new Clock (in.nextint (), In.nextint (), In.nextint ());

Clock.tick ();

SYSTEM.OUT.PRINTLN (clock);

In.close ();

}

Attention! At the time of submission, the code for Main, clock, and display three classes is merged together, where the main class is public and the clock and display classes have no modifiers. Also, be careful that the first line cannot have a package statement.

Input format:

The given main function takes no account of the input output.

Output format:

The given main function takes no account of the input output.

Input Sample:

The given main function takes no account of the input output.

Sample output:

The given main function takes no account of the input output.

time limit: 500ms memory limit: 32000kb

public class Main {public static void main (string[] args) {Java.util.Scanner in = new Java.util.Scanner (system.in); Clock clock = new Clock (in.nextint (), In.nextint (), In.nextint ()); Clock.tick (); SYSTEM.OUT.PRINTLN (clock); In.close ();}} class Display {private int value = 0;private int limit = 0;public Display (int limit) {this.limit = limit;} public void Increase () {value++;if (value = = limit) {value = 0;}} public int GetValue () {return value;} public void SetValue (int value) {this.value = value;}} Class Clock {private Display hour = new display;p rivate display minute = new display;p rivate display second = new Display (ublic);p clock (int hour, int minute, int second) {//with hour, minute, and second initialization time. This.hour.setValue (hour); This.minute.setValue (minute); This.second.setValue (second);} public void tick () {//"tick" a bit, time to go 1 seconds. This.second.increase (); if (this.second.getValue () = = 0) {this.minute.increase (); if (this.minute.getValue () = = 0) { This.hour.increase ();}}} Public String toString () {//returns a strThe value of ING, in the form of "Hh:mm:ss", representing the current time. Each of these values occupies two bits, which is less than two 0. such as "00:01:22". Note that the colon is in Latin, not Chinese. Return String.Format ("%02d:%02d:%02d", This.hour.getValue (), This.minute.getValue (), This.second.getValue ());// Tip: String.Format () can format a string in the same way as printf. }}

China MOOC_ object-oriented Programming--java language _ 2nd Week object Interaction _1 digital clock with seconds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.