Uploaded by 1287191803

1150Lab2 - Java Basics

advertisement
Langara College
Department of Computing Science & Information Systems
CPSC1150 – Program Design
Lab2: Java Basics
Objectives:
-
Writing algorithms on Java arithmetic
Implementing algorithms
Get input and format output
Creating external documentation
Problems [35 marks]
Instructions:
1. Create a folder named Lab2 to store all the files from this lab
2. Create a single external documentation file for this lab (filename: Lab2Ext.docx). For
information on external documentation, refer to the Lab Guide.
Problem 1: [10 marks] Find denominations (filename: FindDenominations.java)
Design an algorithm (put it in the external documentation file) and then write a program
that asks the user to enter an amount of money from 0 to 99 cents. The program then
calculates and displays the number of coins from each denomination: quarters (25 cents),
dimes (10 cents), nickels (5 cents), and cents.
For example, if the user enters 93, your program should display
There are 3 quarters, 1 dimes, 1 nickels, and 3 cents in 93 cents
Problem 2: [10 marks] Calculate body mass index (filename: CalculateBmi.java)
Design an algorithm (put the algorithm in the same external documentation file created
in Problem 1) and then write a program that gets a person’s weight (kg) and height (m) from
the keyboard and then calculates and displays the person’s BMI on the console (keep two
digits after the decimal point). The formula for calculating BMI is:
1
bmi = weight / height2
A sample run is given below:
Please enter your weight in kg: 74
Please enter your height in meters: 1.7
Your BMI is: 25.61
Problem 3: [15 marks] Shopping Receipt (filename: ShoppingReceipt.java)
Design an algorithm (put the algorithm in the same external documentation file created
in Problem 1) and then write a program that asks the user to enter a shopping item name, unit
price and the quantity of the item, and then calculates and displays the subtotal (which is the
unit price times the quantity but every third piece gets half price), GST (5% of the subtotal),
PST (7% of the subtotal), and the total which is the subtotal plus GST plus PST. Keep two
decimals for all the calculated values.
A sample run is given below:
Enter the item name: Cap
Enter the item price: 20.5
Enter the quantity: 7
Your Receipt
Item name:
Quantity:
Item price:
Subtotal:
GST (5%):
PST (7%):
Total:
$
$
$
$
$
Cap
7
20.50
123.00
6.15
8.61
137.76
What to hand in
Zip the folder Lab2 which contains all the Java source files and the external documentation
file from this lab and upload the zip file to BrightSpace.
When to hand in
By 11:59pm, Monday, January 31, 2022.
2
Download