HW1 CH 1 and CH 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CS 4150 Chapter 1 & 2 Due Date: 8/25/2021, 11:59 pm Total points: 60 points

(10 points each problem)

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

3. Write a program that displays the sum of 5 and 10.

The output from running the program will be:


15

4. (Area and perimeter of a rectangle)


Write a program that prompts and reads user input for the width and height of a rectangle.
You program will calculate and display the area and perimeter of the rectangle. The
values for width and height should be treated a a number with a decimal point. Area and
perimeter are calculated as shown below.

area = width × height


perimeter = (2 x width) + (2 x height)
The output from running the program with a width of 5.5 and height of 2.2
will be:
Please enter the width: 5.5
Please enter the height: 2.2
(you will likely have more to the right of the decimal point, and that is ok.)
Area is 12.100000
Perimeter is 15.4

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.

• Create a constant for π with the value 3.14159.

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”.

To calculate a tip, calculate subtotal * rate / 100


To calculate the total bill, use the above calculation and add to the subtotal.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy