The second week of MOOC zero basic Java assignment of Zhejiang University

1. Time conversion
Content:

UTC is world coordinated time, BJT is Beijing time, and UTC time is equivalent to BJT minus 8. Now, your program will read in an integer representing the hours and minutes of BJT. The bits and tens of integers represent fractions, and the hundredths and thousandths represent hours. If the hour is less than 10, then there is no kilo part; if the hour is 0, then there is no hundred part; if the score is less than 10, then the 0 on the ten bit needs to be reserved. For example, 1124 is 11:24, 905 is 9:5, 36 is 0:36, 7 is 0:7.

The valid input range is 0 to 2359, which means that your program cannot read input data beyond 0 to 2359 from the test server.

Your program should output the UTC time corresponding to this time. The output format is the same as that of the input, that is, output an integer to represent the UTC time and minute. The bits and tens of integers represent fractions, and the hundredths and thousandths represent hours. If the hour is less than 10, then there is no kilo part; if the hour is 0, then there is no hundred part; if the score is less than 10, then the 0 on the ten bit needs to be reserved.

Reminder: be careful about Cross Day conversion.

Input format:

An integer representing the hours and minutes of BJT. The bits and tens of integers represent fractions, and the hundredths and thousandths represent hours. If the hour is less than 10, there is no kilo part; if the hour is 0, there is no hundred part; if the hour is not 0 and the score is less than 10, the 0 in the tens should be retained.

Output format:

An integer representing the hour and minute of UTC. The bits and tens of integers represent fractions, and the hundredths and thousandths represent hours. If the hour is less than 10, there is no kilo part; if the hour is 0, there is no hundred part; if the hour is not 0 and the score is less than 10, the 0 in the tens should be retained.

Input example: 933

Output example: 133

Time limit: 500ms memory limit: 32000kb
Think: this assignment is similar to the first week assignment

import java.util.Scanner;
//Second week assignment of Zhejiang University (1): time conversion
public class BJTtoUTC {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int UTC;
		Scanner in = new Scanner(System.in);
		int BJT = in.nextInt();
		if(BJT >= 800 && BJT<2400)
			UTC = BJT - 800;
		else
			UTC = (BJT-800) + 2400;//When the time is less than 8 o'clock, calculate the next day
		System.out.println( UTC );
	}

}

Output results:

2. Signal report (5 points)
Content:
The RS system signal report of radio station is composed of three parts:
R(Readability) signal resolution is the definition
S(Strength) signal strength is the size
Where R is the first in the report, divided into 5 levels, expressed by 1 - 5 numbers
1—Unreadable
2—Barely readable, occasional words distinguishable
3—Readable with considerable difficulty
4—Readable with practically no difficulty
5—Perfectly readable
The second digit of the report is S, which is divided into nine levels, and is represented by one digit in 1-9
1—Faint signals, barely perceptible
2—Very weak signals
3—Weak signals
4—Fair signals
5—Fairly good signals
6—Good signals
7—Moderately strong signals
8—Strong signals
9—Extremely strong signals

Now, your program will read in a signal report number and output the corresponding meaning. If 59 is read, output:
Extremely strong signals, perfectly readable.

Input format:
An integer, signal report. The ten bit part of an integer represents the resolution, and the one bit part represents the strength. The input integer range is a valid number in [11,59], and the number outside this range cannot appear in the test data.

Output format:
In a word, the meaning of this signal report. According to the text in the title, first output the text indicating the strength, followed by commas and spaces, then the text indicating the legibility, followed by periods.
Note that the first letter of a sentence with legibility is lowercase. Note that the punctuation here is in English.

Input example: 33

Output examples: weak signals, readable with consistent efficiency
Thinking: using switch loop to output desired results, but such code repetition rate is too high, too long, which is a stupid method, not recommended. Note that comma and space are required between two characters

```java
import java.util.Scanner;
//Second week assignment of Zhejiang University (2): Information Report
public class massage {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int R;
		int S;
		int num;
		num = in.nextInt();
		if(num >= 11 && num <=59) {
			S = num % 10;
			R = num / 10;
			switch(S) {
			case 1:
				System.out.print("Faint signals, barely perceptible"+",");//. toLowerCase() is to convert English uppercase characters to lowercase characters
				break;
			case 2:
				System.out.print("Very weak signals"+",");
				break;
			case 3:
				System.out.print("Weak signals"+",");
				break;
			case 4:
				System.out.print("Fair signals"+",");
				break;
			case 5:
				System.out.print("Fairly good signals"+",");
				break;
			case 6:
				System.out.print("Good signals"+",");
				break;
			case 7:
				System.out.print("Moderately strong signals"+",");
				break;
			case 8:
				System.out.print("Strong signals"+",");
				break;
			case 9:
				System.out.print("Extremely strong signals"+",");
				break;
			default :
					System.out.print("Signal input error");
			}
			
			switch(R) {
			case 1:
				System.out.print(" Unreadable".toLowerCase() + ".");
				break;
			case 2:
				System.out.print(" Barely readable, occasional words distinguishable".toLowerCase()+".");
				break;
			case 3:
				System.out.print(" Readable with considerable difficulty".toLowerCase()+".");
				break;
			case 4:
				System.out.print(" Readable with practically no difficulty".toLowerCase()+".");
				break;
			case 5:
				System.out.print(" Perfectly readable".toLowerCase()+".");
				break;
			default :
				System.out.print("Signal input error");
			}
		}
		in.close();

	}
}

Method 2: output results by array subscript

import java.util.Scanner;
//Second week assignment of Zhejiang University (2): Information Report
public class massage {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] Ra = {"Unreadable.","Barely readable, occasional words distinguishable.",
				"Readable with considerable difficulty.","Readable with practically no difficulty.",
				"Perfectly readable."};
		
		String[] Sa = {"Faint signals, barely perceptible,","Very weak signals,","Weak signals,","Fair signals,",
				"Fairly good signals,","Good signals,","Moderately strong signals,","Strong signals,",
				"Extremely strong signals,"};
		
		Scanner in = new Scanner(System.in);
		int R;
		int S;
		int num;
		num = in.nextInt();
		if(num >= 11 && num <=59) {
			S = num % 10;
			R = num / 10;
			System.out.print(Sa[S - 1] + " " + Ra[R - 1].toLowerCase());//Ra[R - 1].toLowerCase() is to convert English uppercase characters to lowercase characters
		}
		in.close();
	}
}

Output results:

Published 3 original articles, won 0 praise and 0 visitors
Private letter follow

Keywords: less Java

Added by JimStrosky on Mon, 24 Feb 2020 12:30:12 +0200