Professional Documents
Culture Documents
Week1 - Lab 1 - Revision
Week1 - Lab 1 - Revision
Language II
Lab 1: Revision of Java basics
Student Version
Lab Objectives:
In this lab, the student will practice:
✓ Selection statements
✓ Repetition Statements
✓ Methods
P a g e |1
Lab Exercise 1: Products
A Shopping website sells four different designs of a specific t-shirt. Each design has its own name:
Write an application that will display a menu containing the four designs names and descriptions and that
will ask the user for getting the Design name, and the Quantity of the design which the customer would
like to buy.
It also should calculate and display the total price of the t-shirts bought by the customer.
Develop a Java application that uses a method with two parameters (miles, gallons), and using while
statement (the stop condition is when the user inserts -1 for the miles or gallons) to input the miles driven
and gallons used for each trip and outputs the used number of gallons for such trip.
The program should display the user input and calculate and display the miles per gallon obtained for
each trip and print the combined miles per gallon obtained for all trips up to this point.
P a g e |2
Lab Exercise 3: Draw Rectangle
Write a java application that asks the user to input the length and width of a rectangle. Then it should
draw this rectangle on the screen using stars. [Hint: You have to use a method that takes parameters and
just draws the rectangle of stars]
Premium, gold and silver members receive a discount of 20%, 15%, and 10%, respectively. Customers
without membership receive no discount.
The store provides a special offer of 20 years anniversary where all members receive a 15% deduction.
getItemsTotalPrice()
main() displayFinalPrice(total)
calculateFinalPrice(mem
bership,total)
displayFinalPrice(total,discount)
Method Steps
main • Prompt the user to choose the membership type.
(Premium, gold, silver or no membership)
• call methods:
• getItemsTotalPrice()
• calculateFinalPrice(membership, total)
getItemsTotalPrice() • Prompt the user to enter the price of each item then
calculate and return the total. When the user enters -1 the
loop will stop.
P a g e |3
calculateFinalPrice(membership, total) • Find the discount percentage based on the membership
type. (using switch or nested if).
• If there is no discount call displayFinalPrice(total)
otherwise call displayFinalPrice(total,discount)
displayFinalPrice(total) • Check if there is any extra discount
• calculate and print the final price
displayFinalPrice(total,discount) • Check if there is any extra discount
• calculate and print the final price based on the total
discount amount.
P a g e |4