Question 1: The Area and Perimeter of a circle [20 points] — Assignment1 Solution

$30.00 $24.00

Question 1: The Area and Perimeter of a circle [20 points] Please write a program to calculate the area and perimeter of a circle according to the radius, which is an argument (args[0]) passed by command line. You can assume pi = 3.14 in your calculation. Please print out the perimeter on the first line…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Question 1: The Area and Perimeter of a circle [20 points]

Please write a program to calculate the area and perimeter of a circle according to the radius, which is an argument (args[0]) passed by command line. You can assume pi = 3.14 in your calculation.

Please print out the perimeter on the first line and the area on the second line.

The print out of both values should be with 2 decimal places.

You can parse the string type to float type by float radius = Float.parseFloat(args[0])

Sample output:

Question 2: Currency exchange [20 points]

Write a program to compute how much money you can get from changing CNY (Chinese Yuan Renminbi) to HKD (Hong Kong Dollar). The ratio between CNY and HKD is 1:1.17. However, in each transaction, 50 CNY is charged for a handling fee.

The amount of CNY should be passed by command line argument. The program should print out the amount of HKD with 2 decimal places. You can assume the user input is a floating-point number.

Sample output:

Question 3: Grading system [20 points]

Please write a program to help printing the total score and the grade of a student.

The total score is calculated by the following ratio:

  • Lecture attendance (10%)

  • Lab attendance (10%)

  • Assignments (30%)

  • Project (20%)

  • Final exam (30%)

  • get an A if total score is >=80

  • get a B if total score is >= 50 and < 80

  • get a C if total score is < 50

All the inputs should be passed by command line arguments.

The usage of your program should be in this way:

java A1Q3 <lecture-attendance> <lab-attendance> <assignments> <project> <exam>

e.g. : java A1Q3 60 50 78 82 90

All input scores should be an integer from 0 to 100. You can parse the string type to int type by

int lecture = Integer.parseInt (args[0])

Your program should print out the total score and the grade on two different lines. The print out of the total score should be a floating-point number with 2 decimal places. The grade should be a single character with capital letter ‘A’, ‘B’ or ‘C’.

Sample output:

Question 4: Summing numbers [20 points]

Write a program using for loop to calculate and print out the sum of first n positive integers where n is another integer entered by users. For example, if n is 10, the output should be 55 (= 1 + 2 + … + 10).

You can assume that the input from user is an integer larger than 1. The input should be passed by command line.

Sample output:

Question 5: Two numbers sum up to 100 [20 points]

Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The program will check if the sum equals 100. If so, the loop should terminate; otherwise it should repeat. You can assume only integers will be entered by the users.

Sample output:

Rules

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

  1. The class name of each “.java” file should be A1Q1, A1Q2, … , A1Q5 respectively to represent these five 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 description 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 your will get a zero for the assignment).

Question 1: The Area and Perimeter of a circle [20 points] -- Assignment1 Solution
$30.00 $24.00