Reference no: EM133516226
Homework
Read the following instructions before working on the homework:
I. Homework will be given and returned via the D2L as a convenience to the students and the instructor. Do not send homeworks via email.
II. It is the student's responsibility to have all homeworks ready on time by the given due date. Late homework may not be accepted.
III. Discussion is allowed and encouraged, but no cheating. Homework with copied answers or other cheating (all or in part) receive a grade of 0.
IV. Homeworks or programs with extra features, and fancy output, you may receive extra scores.
V. The first lines of the source code of the program should include a comment with the following information and format:
/**
* A short description of the program.
*
* @author's last name, first Name
* @homework CSCI 428 Homework X -Qn M
* @date MM/DD/ YYYY
*/
VI. For all programming questions (e.g., Qns 3-4), copy the Java source code into the word file named "CSCI428-AssignX-XX.doc(x)"and screenshots of the program's output. Please replace the first `X' with the Homework number and "XX" with your first name and last name. For instance, the title for homework 01 should be "CSCI428- Assign01-JessicaRuby.doc(x)".
VII. List answers to all short-answer questions.
Task
I. Write declarations for storing the following quantities. Choose between integers and floating-point numbers. Declare constants when appropriate.
1. The number of days per week
2. The number of days until the end of the semester
3. The number of centimeters in an inch
4. The height of the tallest person that you think in your class, in centimeters.
5. The price of a single can of Coca-Cola
6. Fringe benefit rate for student workers (Fringe benefit rate for student workers is 3%)
7. Your current age
8. The number of students in CSCI 428
9. The minimum hourly rate for student workers that you may know or guess.
10. The length of a football field
II. Write Java statements that accomplish the following.
1. Declare int variables x and y.
2. Declare Stringvariables firstName and lastName.
3. Initialize an int variable x to the last two digits of your CWID.
4. Declare and initialize a char variable ch to the first letter of your first name.
5. Initialize the String variables to your first name and last name.
6. Update the value of an int variable x by adding 5 to it.
7. Declare and initialize a double variable payRate to 12.50.
8. Copy the value of an int variable firstNum into an int variabletempNum.
9. Swap the contents of the int variables x and y. (Declare additionalvariables, if necessary.)
10. Declare and initialize a String variable fullName by using the variables firstName and lastName.
11. Output the values of x, y, andthe expression x + 12 / y - 18.
12. Declare a char variable grade and set the value of the grade to 'A'.
13. Declare int variables to store four integers.
14. Copy the value of a double variable z to the nearest integer intoan int variable x.
15. Update the variable ch to represent the last digit of your CWID and print out its ASCII value. (The ASCII table can be found on P40 of the file "01-csci428_lecture_Introduction of Java")
III. Write a program that prompts the user for two integers and then prints
1. The sum
2. The difference
3. The product
4. The average
5. The distance (absolute value of the difference)
6. The maximum (the larger of the two)
7. The minimum (the smaller of the two)
8. Suppose the two integers are the lengths of a rectangle's sides. Print the area and perimeter of the rectangle andthe length of the diagonal (use the Pythagorean theorem)
Hint: The max and min functions are declared in the Math class.
IV. Write a program that reads an integerthat is your CWIDand breaks it into a sequence of individualdigits. For example, your CWID is12345678 and can be displayed as
1 2 3 4 5 6 7 8
Calculate and print the total and average of the digits. Here is a sample run; the user input is in color.
Please enter your 8-digit CWID: 12345678
The digits are: 1 2 3 4 5 6 7 8
The total is: 36
The average is: 4.5
You may assume that the input has no more than eight digits and is not negative.