HW1 CH 1 and CH 2
HW1 CH 1 and CH 2
HW1 CH 1 and CH 2
Instructions: Please submit a single IntelliJ Java Project which contains a Java class for each
problem. Zip your project for submission.
1. Create a Java program that prints your name, your major, and your favorite food. For
example, for Belinda, the program would display:
Belinda
Computer Science
Lasagna
2. Problem 1.3 from the textbook. Write a program that displays the following pattern as
shown in the text:
J A V V A
J A A V V A A
J J AAAAA VV AAAAA
J J A A V A A
5. Create a Java program that will calculate the volume and area of a sphere. To calculate
the area, use this formula
area = 4 π r2
4
volume = 𝜋𝜋𝑟𝑟 3
3
• Your program will need to read a value for the radius (r) for the console. Radius
should be a double.
For example, if the user enters a value of 5.5 for radius, your program should display
Area is 380.13239
Volume is 696.909381666666
6. You are in a job where you earn a tip for service. You need a program that will calculate
how much to add to the bill after calculating gratuity. Your program will read the subtotal
and the gratuity rate from the user, computes the gratuity and total and displays the
results to the user.
For example, if the user enters 10 for subtotal and 15 for gratuity rate, the program
displays $1.5 for gratuity and $11.5 as total. Don’t worry that the format of the output is
“$X.X” rather than “$X.XX”.
Sample run:
Enter the subtotal or the bill 10
Enter the gratuity rate 15
The amount for gratuity is $1.5
The total final bill is $11.5