Beruflich Dokumente
Kultur Dokumente
1. Restaurant class
2. Database class (aka test program to add restaurant)
Day 2 plan (wow this should be the plan we’re sticking with)
- Main (driver class)
- BackStage:
- Create an array for collecting all restaurant object
- Define all restaurants and the promotions
- Adds each of the restaurant object into the array
- Class Restaurant
- (Static array called allRestaurant // to gather all restaurant’s data)
- Object’s variables / parameters
- String name
- 2d array of discount% and time
- Optional: list of tags
- Constructor(name, array):
- Set name
- addToArray(array)
- Method
- addToArray(array)
- array.append(this)
- getAllDiscount()
- Print all the discount of this restaurant
- addRestaurantPromotion(time, discount)
- add into the 2d array of the discount list
First progress
- Main (driver class)
- BackStage:
- Create an array for collecting all restaurant object (O)
- Define all restaurants and the promotions (O)
- Adds each of the restaurant object into the array (O)
- Class Restaurant
- Object’s variables / parameters
- String name
- 2d array of discount% and time
- Constructor(name):
- Set name
- Method
- addPromotion(time, discount)
- add into the 2d array of the discount list
- printAll()
- Print all the discount of this restaurant
- *Added* will not print the array that has not been set a promotion
- printPromotion()
- Print the discount at a specific row
Added stuff:
● toTime()
- In case invalid time (12:60, -12:00, 25:00) is inputted, it will justify the user that this is
not valid: so that the time matches
● Used a sleep method from the Thread class
Portal to Repl.it
https://repl.it/@ThanawinBoonpoj/TheProject
Main.java
import java.util.Arrays;
import java.lang.Thread;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws InterruptedException {
// this is how to deal with sleep method bc it always throw an
InterruptedException error
//=====================================================
// Set up for restaurant info
//Greetings
System.out.println();
System.out.println("Good day, my mate!");
System.out.println("Welcome to YEETIGO,");
System.out.println("where you get imaginary discounts in Mr.Task's
class");
System.out.println();
Thread.sleep(5000);
//Confirm Answer
if (answer1 - 1 < allRestaurant.length){
Thread.sleep(1000);
System.out.println("Detail of your reservation: ");
System.out.println("Restaurant: " + allRestaurant[answer1 -
1].name);
System.out.println("Discount: ");
allRestaurant[answer1 - 1].printPromotion(answer2);
Thread.sleep(1000);
System.out.println();
}
else{
System.out.println("Invalid number.");
System.out.println("Make sure you read the instruction carefully
next time!");
}
Thread.sleep(500);
System.out.println(answer3);
Restaurant.java
import java.util.Arrays;
public boolean toTime(double x) { // this is a function made in case
of more performance improvement or added function to the program (eg.
search for promotion using time)
if (x < 0) {
//Negative time
System.out.println("Invalid time: Negative value. Please
re-enter.");
return false;
} else{
return true;
}
}