Assignment 5

Due Tuesday, January 29 at 11:20am on Canvas

Assignment 5.1: Collecting Student Data (10 pts)

• The goal of this program is to collect student data and print it to the screen.
• The program should first print out the message "Collecting Student Data!" and then move down two lines.
• Your program should prompt the user for his or her GPA.
• It should then ask for the student ID number of the user.
• It should ask the user how many years he or she has attended De Anza.
• Notice how the user input and the prompt are on THE SAME LINE.
• Note that this program should use a Scanner to read in the data input by the user. Later, your program should display the data entered by the user in the format shown below.
• Make sure to display the same blank lines in your output, as I show in my sample output.
• Think carefully about what type of variables you will use to store each piece of information.
• Will need input.nextInt() or input.nextDouble() to read in each piece of information?
• Please include your name and section information in the block comment at the start of your program.
• Your program output should look identical to the following (except for the user input which will vary):

Collecting Student Data!

Please enter the number of years you have attended De Anza: 2.5

Your student ID number is 100066.
You have attended De Anza for 2.5 years.

#### Assignment 5.2: Applying Integer Division and Modulus (10 pts)

• In Java dividing one integer by another truncates the remainder, which removes the decimal part. To compute the integer remainder, we use the remainder operator (`%`), also known as the modulus operator.
• The `%` operator finds the remainder after division of one number by another. The Java expression `a % b` (pronounced a mod b) returns the remainder of the division of `a` by `b` if both numbers are positive. For example:
```   3  r 1
2 ) 7
-6
1 remainder```
• For this assignment we will use both the division and remainder operators to extract single digits form an integer number.
• Write a program that gets three numbers from the user and then sums:
• the hundreds digit of the first number
• with the tens digit of the second number and
• the unit digit of the third number.
• For example, the sum of the diagonal digits of the following three numbers is 3 because the numbers are all 1 on the diagonal as shown by the highlight.
```123
416
781
```
• Name the source code file SumDiagonal.java and include all your code in this single file.
• Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
```Enter first number:  123
Enter second number: 416
Enter third number:  781
Sum of diagonal digits is 3
```
```Enter first number:  123
Enter second number: 456
Enter third number:  789
Sum of diagonal digits is 15
```
```Enter first number:  1234
Enter second number: 56
Enter third number:  789
Sum of diagonal digits is 16
```
```Enter first number:  1
Enter second number: 2
Enter third number:  3
Sum of diagonal digits is 3
```

In the above example output, the user entered the values shown in aqua italics (for emphasis) to produce the output. Your program does NOT print the characters in aqua italics, nor does the user input appear in aqua italics.

Notice the fourth example. Entering a 1 is the same as 001. Similarly, entering a 2 is the same as entering 002 and entering a 3 is the same as entering 003. Thus arranging the three numbers in a matrix of rows and columns shows us how the answer was derived.

```001
002
003
```
• Ask the user for the three integer numbers, and no other input, as shown in the Example Run.
• Use the division operator (`/`) and remainder operator (`%`) to extract digits from the numbers entered by the user.
• Example Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and same wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
• After displaying the output, exit the program.
• Do not use `if`-statements, strings or techniques we have not covered.
• Submit SumDiagonal.java to Canvas when your program works as shown.

Assignment 5.3: Calculator Part 2 (10 pts)
• We are going to create a calculator program using the math methods from the Math class.
• Open a new Java class in Eclipse called Maths.java
• Create a program that prompts the user to input a number, and then performs calculations on that number.
• Your calculator is going to perform the following operations on that number:
• Raise the number to the power of 2, 3, and 4 (square, cube, quartic)
• Calculate the floor of the number
• Calculate the ceiling of the number
• Calculate the square root of the number
• Calculate the natural log of the number (hint: use the log function)
• Your program should give output as shown below when the user enters 2.5. However, if the user enters another number, the output should change.