Problem Set 3
Summary
Solve each exercise so that your output matches the expected output. Each exercise should be written in the main
method of its own class. Follow a file naming convention of ExerciseX.java
, where X
is 1 through 10, for each class file.
Requirements
Create a new repository called
pset-3
.Mark your repository as private, and add me as a collaborator (
ryanjwilson
).Solve each of the exercises, placing each solution in its own file.
Add, commit, and push your code to the
pset-3
repository.
Exercises
The specifications for each exercise are outlined below. Your job is to write code that meets the stated requirements, and matches my output exactly. Work through these exercises on your own. Experiment, make mistakes, ask questions, and fix your mistakes. It's the only way to get good at programming.
Exercise 1
Print a square of text to the console.
Use a single
print
,printf
, orprintln
statement.The use of the
String
concatenation operator is prohibited.The use of any
String
methods is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
H E L L O
E A
L P
L C
O A P C S
Exercise 2
Print a simple message to the console.
Use a single
print
,printf
, orprintln
statement.The use of the
String
concatenation operator is prohibited.The use of any
String
methods is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
"The answer's quite simple," the professor said. "Just think outside the box!"
Exercise 3
Prompt the user to enter the dimensions of a rectangle (in inches).
Height :
Width :
Calculate and print the area of the rectangle in square millimeters.
Display exactly two decimal places.
Format the area with separating commas, as needed.
The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Height : 8.5
Width : 11
60,322.46 square millimeters.
Exercise 4
Prompt the user to enter the dimensions of a rectangle (in inches).
Height :
Width :
Calculate and print the perimeter of the rectangle in centimeters.
Display exactly two decimal places.
Format the perimeter with separating commas, as needed.
The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Height : 8.5
Width : 11
99.06 centimeters.
Exercise 5
A course grading policy defines the following assignment category weights.
Homework, 15%
Quizzes, 35%
Tests, 50%
Prompt the user to enter three homework grades, two quiz grades, and one test grade.
Homework 1 :
Homework 2 :
Homework 3 :
Quiz 1 :
Quiz 2 :
Test 1 :
Calculate and print the user's marking period grade.
Display exactly two decimal places.
Format the grade with a
%
sign.The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Homework 1 : 88
Homework 2 : 84
Homework 3 : 86
Quiz 1 : 80
Quiz 2 : 84
Test 1 : 92
87.60%.
Exercise 6
Prompt the user to enter their hourly wage, as well as the number of hours per day they worked.
Wage :
Monday :
Tuesday :
Wednesday :
Thursday :
Friday :
Saturday :
Sunday :
Calculate and print the user's weekly gross pay.
Display exactly two decimal places.
Format the gross pay with a
$
sign.The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Wage : 15.25
Monday : 8
Tuesday : 8
Wednesday : 8
Thursday : 10
Friday : 6
Saturday : 0
Sunday : 4
$671.00.
Exercise 7
Prompt the user to enter their annual salary, as well as the payroll deductions for their 401(k) contribution (deducted pre-tax), federal taxes, and state taxes, all of which should be in the form of a percentage.
Salary :
401(k) :
Federal :
State :
Calculate and print the net pay for a single paycheck if the user is paid twice per month.
Display exactly two decimal places.
Format the net pay with a
$
sign.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Salary : 112000
401(k) : 7
Federal : 21.43
State : 6.37
$3,133.48.
Exercise 8
Prompt the user to enter the number of students and teachers attending a class trip, as well as the capacity of the buses being used.
Students :
Teachers :
Capacity :
Calculate and print the number of buses required, as well as the number of passengers on a potentially partially filled last bus. There should be an overflow value only if the last bus is partially filled. If all buses are filled to capacity, you should have an overflow value of 0
.
The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Students : 273
Teachers : 28
Capacity : 54
Buses required : 6
Overflow passengers : 31
Exercise 9
Prompt the user to enter a dollar amount.
Amount :
Calculate and print the equivalent number of quarters, dimes, nickels, and pennies.
Maximize larger coin denominations.
The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Amount : 2.43
Quarters : 9
Dimes : 1
Nickels : 1
Pennies : 3
Exercise 10
Prompt the user to enter a temperature (in Fahrenheit).
Fahrenheit :
Calculate and print the equivalent temperature in Celsius and Kelvin.
Display exactly two decimal places.
The use of the
Math
class is prohibited.The use of
if
statements,switch
statements, ternary operators, and loops is prohibited.
Fahrenheit : 32.0
Celsius : 0.00
Kelvin : 273.15
Deliverables
Submit your repository URL.
Your program output should match mine exactly for each of the exercises above.
Deadline
All submissions are due on Canvas by 11:59pm on Sunday, September 27, 2020.
Last updated
Was this helpful?