0% found this document useful (0 votes)
2 views

ROCODE

The document contains Java code for a console application that simulates various functionalities such as concert ticket purchasing, patient management in a hospital, and banking transactions. It includes classes for handling movies, patients, and bank accounts, along with methods for displaying details, processing transactions, and applying discounts. The code is structured with user input prompts and validation to ensure correct operations.

Uploaded by

jhndmtvd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ROCODE

The document contains Java code for a console application that simulates various functionalities such as concert ticket purchasing, patient management in a hospital, and banking transactions. It includes classes for handling movies, patients, and bank accounts, along with methods for displaying details, processing transactions, and applying discounts. The code is structured with user input prompts and validation to ensure correct operations.

Uploaded by

jhndmtvd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

System.out.

println("PhilHealth: " +
philhealthDeduction);
8
System.out.println("Total Deductions: " +
totalDeductions);
System.out.println("\nyour amount: " + netPay);
}
}
import java.util.Scanner; int finalPrice = price;
2
public class Main { if (vipChoice.equals("yes")) {
public static void main(String[] args) { finalPrice += 200;
Scanner scanner = new Scanner(System.in); }

String[] MovieNames = { System.out.print("\nHow many tickets do you


want to buy? ");
"BTS", "BINI", "BLACKPINK", "SB19", "Sarah G"
int quantity = scanner.nextInt();
};
int[] prices = {400, 450, 500, 600, 550};
System.out.println("\nYour Selected Concert");
String[] times = {
System.out.println(MovieName + " \nEntrance fee:
"6:00 PM", "7:30 PM", "8:00 PM", "9:00 PM",
" + finalPrice + " \nTime: " + time + " \nDate: " + date +
"7:00 PM"
"\n");
};
String[] dates = {
int totalPrice = finalPrice * quantity;
"2025-01-15", "2025-01-16", "2025-01-17",
System.out.println("\nTotal Price: " + totalPrice);
"2025-01-18", "2025-01-19"
};
System.out.println("Thank you for your
purchase!");
System.out.println("\nAvailable Movie!!");
}
for (int i = 0; i < MovieNames.length; i++) {
}
System.out.println((i + 1) + ". " +
package main;
MovieNames[i]);
class UIFruits {
}
String concertName;
int price;
System.out.print("\nEnter the number of the
concert you want: "); String time;
int choice = scanner.nextInt(); String date;

if (choice < 1 || choice > MovieNames.length) { UIFruits(String concertName, int price, String time,
String date) {
System.out.println("Invalid choice.");
this.concertName = concertName;
return;
this.price = price;
}
this.time = time;
String MovieName = MovieNames[choice - 1];
this.date = date;
int price = prices[choice - 1];
}
String time = times[choice - 1];
void displayDetails() {
String date = dates[choice - 1];
System.out.println("Movie: " + concertName);
}
System.out.print("\nIf you want VIP? (yes or no): ");
}
String vipChoice = scanner.next().toLowerCase();
package main; displayMovieDetails(e4); 3

import java.util.Scanner; break;

public class Main { case 5:

public static void main(String[] args) { Employeee e5 = new Employeee("\nFruit


Basket", "Yoshihide Ibata", "5/5", "Animation", "Tohru,
Scanner scanner = new Scanner(System.in);
Yuki, Kyo, Akito\n");
while (true) {
displayMovieDetails(e5);
System.out.println("\nTICKET FOR Movie");
break;
System.out.println("SELECT Movie:");
case 6:
System.out.println("1. Coco");
Employeee e6 = new Employeee("\nThe
System.out.println("2. Jumanji"); Kingdom", "Michael Tuviera", "5/5", "Drama\n");

System.out.println("3. Hunter x Hunter"); displayMovieDetails(e6);

System.out.println("4. Black Clover"); break;

System.out.println("5. Fruit Basket"); default:

System.out.println("6. The Kingdom"); System.out.println("Invalid choice.");

System.out.print("\nEnter the Movie number (1- }


6): ");
System.out.print("\nDo you want to choose
int movieNumber = scanner.nextInt(); another movie? (yes or no): ");

switch (movieNumber) { scanner.nextLine();

case 1: String choice = scanner.nextLine();

Employeee e1 = new Employeee("\nCoco", if (choice.equalsIgnoreCase("No")) {


"Lee Unkrich", "5/5", "Action", "mama coco, ernesto,
System.out.println();
tia rosita", "2017", "PG\n");
System.out.println(" Thank you for
displayMovieDetails(e1);
reviewing. \n Exiting...");
break;
Break;
case 2:
} else if (choice.equalsIgnoreCase("Yes")) {
Employeee e2 = new Employeee("\
System.out.println("\n Select another movie.\
nJumanji", "Jake Kasdan", "5/5", "Adventure", "Dr.
n");
Smolder, Ruby, Bethany, Spencer", "2017", "PG\n");
} else{
displayMovieDetails(e2);
System.out.println("\n Invalid! pls Repeat.");
break;
}
case 3:
}
Employeee e3 = new Employeee("\nHunter
x Hunter", "Hiroshi Kōjina", "5/5", "Suspense", "Killua, }
Gon, Hisoka, Kurapika", "2011", "SPG\n");
private static void displayMovieDetails(Employeee
displayMovieDetails(e3); movie) {

break; System.out.println("\nTitle: " + movie.TITLE);

case 4: System.out.println("Director: " + movie.director);

Employeee e4 = new Employeee("\nBlack System.out.println("Ratings: " + movie.ratings);


Clover", "Tatsuya Yoshihara", "5/5", "Fantasy", "Asta,
System.out.println("Genre: " + movie.genre);
Noelle, Yami, Julius", "2020", "SPG\n");
System.out.println("Characters: " +
movie.character);
System.out.println("Year: " + movie.year); this.TITLE = TITLE;
System.out.println("SPG: " + movie.SPG); this.director = director;
} this.ratings = ratings;
} this.genre = genre;
package main; this.character = character;
public class MOVIE { this.year = year;
String TITLE,director; this.SPG=SPG;
String ratings,genre,character; }
String year,SPG; }
Employeee(String TITLE,String director,String
ratings,String genre,String character ) {
this.TITLE = TITLE;
this.director = director;
this.ratings = ratings;
this.genre = genre;
this.character = character;
year = "N/A";
SPG="N/A";
}
Employeee( String TITLE, String director, String
ratings,String genre)
{
this.TITLE = TITLE;
this.director = director;
this.ratings = ratings;
this.genre = genre;
character = "N/A";
year = "N/A";
SPG="N/A";
}
Employeee (String TITLE,
String director,
String ratings,
String genre,
String character,
String year,
String SPG)
{
package main; if (!again.equals("yes")) { 4
import java.util.Scanner; System.out.println("Thank you!");

public class Main { break;

public static void main(String[] args) { }

Scanner van = new Scanner(System.in); }

System.out.println("~~Welcome to Hospital van.close();


Record~~~");
}
System.out.println("\n PATIENT LIST: ");
}
Hospital patient1 = new Hospital("Bornales, Harvey",
package main;
18, "Toneo", "0929572948283", "Kidney disease",
"Private", 14); import java.util.Scanner;

Hospital patient2 = new Hospital("Parido, Rowena", public class Hospital {


6, "Antipolo", "027288289178", "Heart failure", "Private",
String name, address, contactPerson, diagnosis,
3);
roomType;
Hospital patient3 = new Hospital("Paglinawan,
int age, hours;
Maica", 80, "Parañaque", "0983383838688", "Fever",
"Private", 5); Hospital(String name, int age, String address, String
contactPerson, String diagnosis, String roomType, int
Hospital patient4 = new Hospital("Marcos, Requillas",
hours) {
29, "Rizal", "094878489999", "Cancer", "Ward", 1);
this.name = name;
Hospital patient5 = new Hospital("Rudinas, Neckol",
15, "Visayas", "0947372282888", "Dengue", "Ward", 8); this.age = age;
Hospital[] patients = {patient1, patient2, patient3, this.address = address;
patient4, patient5};
this.contactPerson = contactPerson;
while (true) {
this.diagnosis = diagnosis;
for (int i = 0; i < patients.length; i++) {
this.roomType = roomType;
System.out.println((i + 1075376987) + ". " +
this.hours = hours;
patients[i].getName());
}
}
void displayDetails() {
System.out.print("\nChoose a patient use the
(Patient Code): "); System.out.println("\nDetails about the Patient:");

int choice = van.nextInt(); System.out.println("Name: " + name);

if (choice < 1075376987 || choice > 1075376991) { System.out.println("Age: " + age);

System.out.println("Invalid input\n"); System.out.println("Address: " + address);

continue; System.out.println("Contact Person: " +


contactPerson);
}
System.out.println("Diagnosis: " + diagnosis);
Hospital patient = patients[choice - 1075376987];
System.out.println("Type of Room: " + roomType);
patient.displayDetails();
System.out.println("Number of Hours: " + hours);
patient.Category();
}
patient.AgeGroup();

patient.billingWithDiscount(); void Category() {

System.out.print("\nWould you want to select another if (hours >= 1 && hours <= 2) {
patient? (yes/no): "); System.out.println("Category 1: Self-care (1 to 2
van.nextLine();

String again = van.nextLine().toLowerCase();


4
hours per day)"); void AgeGroup() {
} else if (hours >= 3 && hours <= 4) { if (age >= 0 && age <= 1) {
System.out.println("Category 2: Minimal care (3 to System.out.println("Age Group: Baby/Infant");
4 hours)");
} else if (age >= 4 && age <= 6) {
} else if (hours >= 5 && hours <= 6) {
System.out.println("Age Group: Toddler");
System.out.println("Category 3: Intermediate care
(5 to 6 hours)"); } else if (age >= 7 && age <= 9) {

} else if (hours >= 7 && hours <= 8 { System.out.println("Age Group: Preschooler");

System.out.println("Category 4: Modified intensive } else if (age >= 12 && age <= 14) {
care (7 to 8 hours)");
System.out.println("Age Group: Primary School
} else if (hours <= 10) { Boy");
System.out.println("Category 5: Intensive care (up } else if (age >= 18 && age <= 25) {
to 10 hours)");
System.out.println("Age Group:
} Adolescent/Teenager");
} } else if (age >= 30 && age <= 35) {
System.out.println("Age Group: Adult");
void billingWithDiscount() { } else if (age >= 40 && age <= 55) {
Scanner scanner = new Scanner(System.in); System.out.println("Age Group: Middle
System.out.print("Is the patient a PWD or Senior adulthood");
Citizen? (yes/no): ");
} else if (age >= 60 && age <= 70) {
String isDiscounted =
System.out.println("Age Group: Old Person");
scanner.nextLine().toLowerCase();
} else {
int rate = roomType.equalsIgnoreCase("Private") ?
1000 : 400; System.out.println("Age Group: Unidentified");
int totalCost = rate * hours; }
if (isDiscounted.equals("yes")) { }
double discount = totalCost * 0.20;

double discountedCost = totalCost - discount; String getName() {


System.out.println("\nBill per hour: " + rate + " return name;
PHP");
}
System.out.println("Discount: " + discount + "
PHP"); }

System.out.println("Total Billing Cost after


Discount: " + discountedCost + " PHP");

} else {

System.out.println("\nBill per hour: " + rate + "


PHP");

System.out.println("No discount applied.");

System.out.println("Total Billing Cost: " + totalCost


+ " PHP");

}
package main; System.out.println("4. Close/Exit");
5
import java.util.Scanner; System.out.print("Enter your choice: ");
public class Main { int choice = user.nextInt();
public static void main(String[] args) { if (choice < 1075376987 || choice >
1075376991) {
Scanner user = new Scanner(System.in);
System.out.println("Invalid input\n");
System.out.println("~~~~Welcome to BDO San
Mateo~~~"); continue;
System.out.println("Branch Number: 1234579"); }
System.out.println("Branch Address: Ampid Uno, switch (choice) {
San Mateo, Rizal");
case 1:
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.out.print("\nEnter amount to
~~");
withdraw: Php ");
System.out.println("\n97629 Kathryn Bernardo\
int withdrawAmount = user.nextInt();
n74927 Enn Botardo\n73619 Yunna Labbao");
if (withdrawAmount >
System.out.print("Enter the Account Number: ");
selectedAccount.getAmount()) {
int accnum = user.nextInt();
System.out.println("Insufficient
acc selectedAccount = null; balance.");
if (accnum == 97629) { continue;
selectedAccount = new acc("\nKathryn } else {
Bernardo", "May 14, 2005", 3976, 97629, "Kathryn",
selectedAccount.withdraw(withdrawAmount);
"12345", "[email protected]", 1000);
System.out.println("Withdrawal
} else if (accnum == 74927) {
successful. Updated balance: Php " +
selectedAccount = new acc("\nEnn Botardo", selectedAccount.getAmount());
"July 30, 2007", 4782, 74927, "Enn", "38626",
}
"[email protected]", 5000);
break;
} else if (accnum == 73619) {
case 2:
selectedAccount = new acc("\nYunna Labbao",
"July 9, 2007", 8652, 73619, "Yunna", "07526", System.out.print("\nEnter amount to
"[email protected]", 1200); deposit: Php ");
} else { int depositAmount = user.nextInt();
System.out.println("No fund user with this selectedAccount.deposit(depositAmount);
account number.");
System.out.println("Deposit successful.
return; Updated balance: Php " +
selectedAccount.getAmount());
}
break;
System.out.println("\nAccount Details:");
case 3:
System.out.println(selectedAccount);
System.out.println("\nYour current balance
while (true) {
is: Php " + selectedAccount.getAmount());
System.out.println("\nSelect a Transaction:");
break;
System.out.println("1. Withdraw");
case 4:
System.out.println("2. Deposit");
System.out.println("\nThank you for
System.out.println("3. Check Balance"); banking with BDO San Mateo. Have a great day!");
return;
default: 5
System.out.println("\nInvalid choice. Please "Birth Date: " + birthDate + "\n" +
try again.");
"Card Number: " + cardNumber + "\n" +
}
"Account Number: " + accountNumber + "\n" +
} "User Name: " + uusername + "\n" +
} "Password: " + password + "\n" +
} "Email: " + email + "\n" +
private int cardNumber; "Amount: Php" + amount + "\n";
private int accountNumber; }

private int amount; }

private String uusername;


private String password;
private String email;
acc(String userName, String birthDate, int
cardNumber, int accountNumber, String uusername,
String password, String email, int amount) {
this.userName = userName;
this.birthDate = birthDate;
this.cardNumber = cardNumber;
this.accountNumber = accountNumber;
this.uusername = uusername;
this.password = password;
this.email = email;
this.amount = amount;
}
int setAmount() {
return amount;
}
int getAmount() {
return amount;
}
void withdraw(int amount) {
this.amount -= amount;
}
void deposit(int amount) {
this.amount += amount;
}
public String toString() {
return "Name: " + userName + "\n" +
package main; @Override 8

abstract class Employe { double calculateTotalSalary() {

protected String name; return basicSalary + internetAllowance +


transpoAllowance + riceAllowance;
protected String employeeNumber;
}
protected String TIN;

protected final double basicSalary = 20000;


umber, TIN);
public Employe(String name, String employeeNumber,
String TIN) { }

this.name = name; @Override

this.employeeNumber = employeeNumber; double calculateDeductions() {

this.TIN = TIN; return sssDeduction + taxDeduction +


pagibigDeduction + philhealthDeduction;
}
}
abstract double calculateTotalSalary();
@Override
abstract double calculateDeductions();

abstract void displayPayslip();


void displayPayslip(){}

abstract void displayPay(); @Override

} void displayPay() {
double totalSalary = calculateTotalSalary();

package main; double totalDeductions = calculateDeductions();

public class FullTimeEmployee extends Employe { double netPay = totalSalary - totalDeductions;

private final double internetAllowance = 1000; System.out.println("Name: " + name);

private final double transpoAllowance = 3500; System.out.println("Employee Number: " +


employeeNumber);
private final double riceAllowance = 2500;
System.out.println("TIN: " + TIN);
private final double sssDeduction = 1000;
System.out.println("Basic Salary: " + basicSalary);
private final double taxDeduction = 500;
System.out.println("Incentives:");
private final double pagibigDeduction = 100;
System.out.println("Internet: " +
private final double philhealthDeduction = 200;
internetAllowance);
public FullTimeEmployee(String name, String
employeeNumber, String TIN) { System.out.println("Transport: " +
transpoAllowance);
super(name, employeeNumber, TIN);
System.out.println("Rice Allowance: " +
} riceAllowance);
@Override System.out.println("Total Salary: " + totalSalary);
double calculateTotalSalary() { System.out.println("\nDeductions:");
return basicSalary + internetAllowance +
System.out.println("SSS: " + sssDeduction);
transpoAllowance + riceAllowance;
System.out.println("Tax: " + taxDeduction);
}
System.out.println("Pag-ibig: " +
@Override
pagibigDeduction);
void displayPay(){}

@Override
} package main; 8
7
package main; import java.util.Scanner;

public class Amenity { public class Main {

private String name; public static void main(String[] args) {

private double price; Scanner scanner = new Scanner(System.in);

public Amenity(String name, double price) { System.out.println("Enter details of Employee");

this.name = name; System.out.print("Name: ");

this.price = price; String name1 = scanner.nextLine();

} System.out.print("Employee Number: ");

public double getPrice() { String empNum1 = scanner.nextLine();

return price; System.out.print("TIN: ");

public String getName() { String tin1 = scanner.nextLine();

return name; Employe emp1 = new FullTimeEmployee(name1,


empNum1, tin1);
}
System.out.println("\n----------------------------");
}
emp1.displayPayslip();
class Spa extends Amenity {
while (true) {
public Spa() {
System.out.print("\nWould you want to check
super("Spa Service", 3400.00); Highest employee account? (yes/no): ");
} String again = scanner.nextLine().toLowerCase();
} if (again.equals("yes")) {
class Gym extends Amenity { System.out.println("Enter details of Highest
Employee");
public Gym() {
System.out.print("Name: ");
super("Gym Access", 2500.00);
String name2 = scanner.nextLine();
}
System.out.print("Employee Number: ");
}
String empNum2 = scanner.nextLine();
class Pool extends Amenity {
System.out.print("TIN: ");
public Pool() {
String tin2 = scanner.nextLine();
super("Pool Access", 1500.00);
Employe emp2 = new FullTimeEmployee(name2,
}
empNum2, tin2);
}
System.out.println("\n----------------------------");
super("Family Room", 10000.00);
emp2.displayPay();
}
} else if (again.equals("no")) {
} extends room {
System.out.println("Thank you!");
public RegularRoom() {
break;
super("Regular Room", 3500.00);
} else {
}
System.out.println("Invalid input. Please enter
'yes' or 'no'.");

}
case 2: case 2:

paymentMethod = "Card Payment"; room = new FamilyRoom(); 7

break; break;

System.out.print("Enter choice: "); case 3:

int paymentChoice = scanner.nextInt(); room = new KingRoom();

switch (paymentChoice) { break;

default:
case 1:
System.out.println("Invalid input! Please try
paymentMethod = "Cash";
again.");
break;
}
case 2:
}
paymentMethod = "Card Payment";
return room;
break;
}
default: }
System.out.println("Invalid input! Please try package main;
again.");
public class room {
}
private String type;
}
private double price;
System.out.println("\nPayment Method: " +
paymentMethod); public room(String type, double price) {

this.type = type;
System.out.println("Thank you for staying with us!
Come back again!"); this.price = price;
scanner.close(); }

} public double getPrice() {

public static room selectRoom(Scanner scanner) { return price;

room room = null; }

while (room == null) { public String getType() {

System.out.println(" Welcome to my hotel return type;


"); }
System.out.println("Select a room type:"); }
System.out.println("1. Regular Room class KingRoom extends room {
(Php3500)");
public KingRoom() {
System.out.println("2. Family Room
super("King Room", 15000.00);
(Php10000)");
}
System.out.println("3. King Room (Php15000)");
}
System.out.print("Enter choice: ");
class FamilyRoom extends room {
int roomChoice = scanner.nextInt();
public FamilyRoom() {
switch (roomChoice) {
case 1:
room = new RegularRoom();
break;
package main; break;

import java.util.ArrayList; case 3: 7

import java.util.Scanner; amenities.add(new Pool());

public class Main { break;

public static void main(String[] args) { default:

Scanner scanner = new Scanner(System.in); System.out.println("Invalid choice! Please


try again.");
ArrayList<room> selectedRooms = new
ArrayList<>(); }

ArrayList<Amenity> amenities = new ArrayList<>(); }

while (true) { }

room room = selectRoom(scanner); double totalPrice = 0;

selectedRooms.add(room); System.out.println("\n -------- HOTEL RECEIPT


--------");
System.out.println("\nDo you want to choose
another room? (yes/no)"); for (room room : selectedRooms) {

String anotherRoom = System.out.printf("%-20s %10.2f%n",


scanner.next().toLowerCase(); room.getType(), room.getPrice());

if (!anotherRoom.equals("yes")) break; totalPrice += room.getPrice();

} }

System.out.println("\nDo you want to add for (Amenity amenity : amenities) {


amenities? (yes/no)");
System.out.printf("%-20s %10.2f%n",
String amenityResponse = amenity.getName(), amenity.getPrice());
scanner.next().toLowerCase();
totalPrice += amenity.getPrice();
if (amenityResponse.equals("yes")) {
}
while (true) {
System.out.printf("\n%-20s %10.2f%n", "Total:",
System.out.println("\nSelect amenities:\n0. totalPrice);
Display Receipt");
String paymentMethod = "";
System.out.println("1. Spa Service
while (paymentMethod.isEmpty()) {
(Php3400)");
System.out.println("\nSelect a payment
System.out.println("2. Gym Access
method:");
(Php2500)");
System.out.println("1. Cash");
System.out.println("3. Pool Access
(Php1500)"); System.out.println("2. Card Payment");

System.out.print("Enter choice: "); System.out.print("Enter choice: ");

int amenityChoice = scanner.nextInt(); int paymentChoice = scanner.nextInt();

if (amenityChoice == 0) break; switch (paymentChoice) {

switch (amenityChoice) { case 1:

case 1: paymentMethod = "Cash";

amenities.add(new Spa()); break;

break;
case 2:
amenities.add(new Gym());
System.out.println("2. Peach Mango Pie - 80.00"); }
6
System.out.println("3. Coke Float - 90.00"); private static double getValidPayment(Scanner
scanner, double totalCost) {
System.out.println("0. Receipt");
while (true) {
while (true) {
System.out.print("\nEnter payment amount: ");
System.out.print("Enter choice: ");
try {
int choice = getValidInteger(scanner);
double payment = scanner.nextDouble();
switch (choice) {
if (payment >= totalCost) return payment;
case 1: return new Desserts("Sundae", 100.0,
getQuantity(scanner, "Sundae")); System.out.println("Insufficient amount.
Please enter again.");
case 2: return new Desserts("Peach Mango
Pie", 80.0, getQuantity(scanner, "Peach Mango Pie")); } catch (InputMismatchException e) {

case 3: return new Desserts("Coke Float", System.out.println("Invalid input. Please enter


90.0, getQuantity(scanner, "Coke Float")); a valid amount.");

case 0: return null; scanner.next();

default: System.out.println("Invalid choice. }


Please try again.");
}
}
}
}
}
}
private static int getValidInteger(Scanner scanner) { package main;
while (true) { public class Drinks {
try { private String name;
return scanner.nextInt(); private double price;
} catch (InputMismatchException e) { private int quantity;
System.out.println("Invalid input. Please enter public Drinks(String name, double price, int quantity)
a number."); {
scanner.next(); this.name = name;
} this.price = price;
} this.quantity = quantity;
} }
private static int getQuantity(Scanner scanner, String public void display() {
itemName) {
System.out.println(quantity + "x " + name + " - " +
while (true) { computeTotal());
System.out.print("Enter quantity for " + }
itemName + ": ");
public double computeTotal() {
int quantity = getValidInteger(scanner);
return price * quantity;
if (quantity > 0) return quantity;
}
System.out.println("Invalid quantity. Please
enter a positive number."); public int getQuantity() {

} return quantity;
}
package main; public double computeTotal() { 6

public class Foods { return price * quantity;


private String name; }
private double price; public int getQuantity() {
private int quantity; return quantity;
public Foods(String name, double price, int quantity) }
{
}
this.name = name;
this.price = price;
this.quantity = quantity;
}
public void display() {
System.out.println(quantity + "x " + name + " - " +
computeTotal());
}
public double computeTotal() {
return price * quantity;
}
public int getQuantity() {
return quantity;
}
}
package main;
public class Desserts {
private String name;
private double price;
private int quantity;
public Desserts(String name, double price, int
quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
}
public void display() {
System.out.println(quantity + "x " + name + " - " +
computeTotal());
}
6
package main; case 3:

import java.util.InputMismatchException; dessert = getDessertChoice(scanner);

import java.util.Scanner; if (dessert != null) {

public class Main { totalCost += dessert.computeTotal();

public static void main(String[] args) { totalItems += dessert.getQuantity();

Scanner scanner = new Scanner(System.in); }

System.out.println("--- Welcome to the Restaurant break;


---");
case 0:
double totalCost = 0;
if (totalCost > 0) {
int totalItems = 0;
System.out.println("\n Order Summary ");
Foods food = null;
if (food != null) food.display();
Drinks drink = null;
if (drink != null) drink.display();
Desserts dessert = null;
if (dessert != null) dessert.display();
while (true) {
System.out.println("\nTotal Items: " +
System.out.println("\nWhat would you like to totalItems);
order?");
System.out.println("Total Price: " +
System.out.println("1. Food"); totalCost);

System.out.println("2. Drinks"); double payment =


getValidPayment(scanner, totalCost);
System.out.println("3. Desserts");
double change = payment - totalCost;
System.out.println("0. Receipt");
System.out.println("Payment successful!
System.out.print("Enter your choice: ");
Change: " + change);
int choice = getValidInteger(scanner);
} else {
switch (choice) {
System.out.println("No items ordered.
case 1: Thank you for visiting!");

food = getFoodChoice(scanner); }

if (food != null) { scanner.close();

totalCost += food.computeTotal(); return;

totalItems += food.getQuantity(); default:

} System.out.println("Invalid choice. Please


try again.");
break;
}
case 2:
}
drink = getDrinkChoice(scanner);
if (drink != null) {
private static Foods getFoodChoice(Scanner scanner)
totalCost += drink.computeTotal();
{
totalItems += drink.getQuantity();
System.out.println("\n--- Food Menu ---");
}
System.out.println("1. Burger - 120.00");
break;

You might also like