You are on page 1of 4

CS111 Programming

Language II
Lab 1: Revision of Java basics
Student Version

Computer Science Department


Spring 2022-2023

Lab#1 : Revision of Java Basics


Student Manual

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:

DRed: Yellow t-shirt with red sleeves for $17.98.

DWhite: Red t-shirt with white sleeves for $12.98.

DBWhite: Blue t-shirt with white sleeves for $10.98.

DPink: Pink t-shirt with yellow sleeves for $29.98.

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.

Your program should use a switch statement to determine the menu.

It also should calculate and display the total price of the t-shirts bought by the customer.

Lab Exercise 2: Gas Mileage Per Gallon


Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by
recording the miles driven and gallons used for each tankful.

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]

Lab Exercise 4: Printing Matrix:


Write a Java method (takes a number n as input) to displays an n-by-n matrix with random generated
values.

Lab Exercise: Self-Work


Write a discount system for electronics store, which sells all needed electronics products. It offers 3 types
of memberships: Premium, Gold and Silver.

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)

Your program should contain the following methods:

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

You might also like