NCCU-ProgrammingLanguage1- Assignment 2-yourStudentId

35.00 $

Category:

Description

Rate this product

Programming Language1
Assignment 2
Requirements:
• Create a Java project named yourStudentId_HW2
• Write a single class named Tester_HW2 and adding main method in your class.
• For each question below, write your code in the main method.
• Your code must be properly formatted with sensible variable names! Refer to the text for code format examples.
1. Write a program that checks the input year is a leap year or not.
⚫ Rules for checking the year is a leap year or not:
“Leap year occurs mostly every 4 years, but every 100 years we skip a leap year unless the year is divisible by 400.” For example, 2000, 2004 are a leap year, and 1900, 2019 are a common year.”
⚫ Additional requirement: Before the program checks the year is a leap year or not, it should check the input is an integer or not first. If not, print “invalid input”
Sample output:
Please input the year: 2019
Common year
Please input the year: 2016
Leap year
Please input the year: yyyy
Invalid input
2. BMI calculator.
(1) Use Math class to calculate BMI.
(2) Noted that the height variable is in the unit of “centimeter”, but it should be turned into “meter” to calculate BMI.
(3) Round off your result to the 2nd decimal place. (DO NOT use printf)
(4) Use “String concatenation” to create a String as in sample output, and show in the console.
(5) Use “If else statement” to inform the user that he or she is underweight/normal weight/overweight based on the information below:
Underweight: BMI < 18.5
Normal weight: 18.5 <= BMI <= 25.0
Overweight: BMI > 25
Sample output:
Please input the weight(kg): 63
Please input the height(cm): 169
BMI before rounded off: 22.058051188683873
The BMI is 22.06. Normal weight
3. Rewrite the program. Lab4 question 2 is a multiway branch question, you may use if-else or switch to answer the question. If you used if-else in lab4, please use switch to answer the question this time. If you used switch in lab4, please use if-else to answer the question this time.
4. Rewrite the program. In lab4 question 3, the output isn’t formatted. Please use String.format() to formatting the output. Please format the floating-point number up-to 2 decimal places.
Read the Java Docs for the usage of String.format().
Sample output:
Convert from (g, kg, lb)? kg
Value? 6
6.00 kg = 6000.00 g = 13.20 lbs
Programming Language I 2019
2

  • HW2-3s2hyx.zip