Assignment-2 Solution

$30.00 $24.00

A2Q1: Chinese Lunar year [25 points] Please write a program to show the Chinese Lunar year of Stems-­‐and-­‐ Branches(天干地支) according to the year number, and the animal symbol(属相) of the year which a person was born in. The Stems-­‐and-­‐Branches uses 10 Stems called:jia, yi, bing, ding, wu, ji, geng, xin, ren, and gui(甲乙丙丁戊己庚辛壬癸), and 12…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

A2Q1: Chinese Lunar year [25 points]

Please write a program to show the Chinese Lunar year of Stems-­‐and-­‐ Branches(天干地支) according to the year number, and the animal symbol(属相) of the year which a person was born in.

The Stems-­‐and-­‐Branches uses 10 Stems called:jia, yi, bing, ding, wu, ji, geng, xin, ren, and gui(甲乙丙丁戊己庚辛壬癸), and 12 Branches called zi, chou, yin, mao, chen, si, wu, wei, shen, you, xu and hai(子丑寅卯辰巳午未申酉戌亥).Combining each of the10 Stems with one of the 12 Branches in sequence creates 60 chronological symbols.For example jiazi, yichou, bingyin, etc. These 60 symbols are used in circles and thus each year has a chronological symbol. And the Branches also represents the animal symbol of Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog, Pig. For example, it is the year of JiHai(己亥年) in 2019. And it is the year of Pig.

Search on web how to calculate it

(1) Remainder=Year%10,

{(Stems:remainder) }={(jia:4)}{(yi:5)}(bing:6)(ding:7)(wu:8)(ji:9)(geng:0)(xin:1 )(ren:2)(gui:3)

(2) Remainder=Year%12

{(Branches:remainder) }={(zi:4)}{(chou:5)}{(yin:6)}{(mao:7)}{(chen:8)}{(si:9)}{ (wu:10)}{(wei:11)}{(shen:0)}{(you:1)}{(xu:2)}{(hai:3)} (3)Branches and animal pair

{(zi:Rat)}{(chou:Ox)}{(yin:Tiger)}{(mao:Rabbit)}{(chen:Dragon)}{(si:Snake)}{(w

u:Horse)}{(wei:Sheep)}{(shen:Monkey)}{(you:Rooster)}{(xu:Dog)}{(hai:Pig)}

ref: http://baijiahao.baidu.com/s?id=1543800345816500

The output has two lines for each test case, the first line is Stems-­‐Branches for current year, and the second line is the animal pair of current year. Sample output:

Sample code:

Null

A2Q2: Simple Statistic of number sequence [25 points]

Write a program to calculate the average(平均数), mode(众数) and median(中位数) of a sequence of numbers.

The average of the numbers is the sum divided by count. The mode is the number appears most frequently. There may be more than 1 mode in a number sequence. The median is the number at “Middle” position of the sequence after sorting. The median is at the “Middle” position of (n-­‐1)/2+1 when n is odd, or is the average value of numbers at position of n/2 and n/2+1.

Using Array and for statement.

(1) Calculate the average;

  1. Count the numbers and find the number appears max times;

  1. Sort all numbers from small to big, and find the “Middle”;

Tips: args.length shows how many parameters inputted.

The output has three lines for each test case, the first line is average, the second line is mode and the third line is median, and all of the output should be accurate to two decimal places.

Sample output:

Sample code:

Null

A2Q3: Grading system [25 points]

Please write a program to calculate the GPA at SUSTech:

Input a serials of percentage grading and credit hour, and to calculate the GPA.

Sample output

Sample code

Null

Question 4: Calculate [25 points]

Write a program using basic arrays to calculate the value of an arithmetic expression consisting of numbers(could be floating-­‐point) and operators +,-­‐,*and

  • . The arithmetic expression is passed to the program from the command line as a string.

Tips:

(1) We can assume that the input string always represents a valid arithmetic expression;

(2) Only 3 numbers and 2 operators; maybe with a pair of bracket;

Sample output:

java A2Q4 (2.1+6.4)*2.3

19.55

Sample code:

Null

Rules

  1. Please submit “.java” file of these four questions.

  1. The class name of each “.java” file should be A2Q1, A2Q2, A2Q3, A2Q4 respectively to represent these four questions.

  1. No Chinese characters are allowed to appear in your code.

  1. No package included.

  1. The arguments and the output must strictly follow the sample output of each question.

  1. Please submit your assignment on the SAKAI site of your lab section. Marks will be deducted if you submit later than the deadline. If you submit your assignment within 24 hours after the deadline (grace period), your score will be half of the score you could get if the submission was made before the deadline. Assignments submitted after the grace period will not be graded (meaning you will get a zero for the assignment).

Assignment-2 Solution
$30.00 $24.00