# FP-OOP
Eric Azka Nugroho
5025211064
To see my progress on this project, you must select MASTER BRANCH.
[IMPORTANT NOTES]
There are few classes that I actually dont use, because it is not efficient. The classes that are not used -> (Calculation.java, Drinks.java, and restaurant.java)
REFERENCES:
- Oracle Fundamental Programming (Where I implemented the OOP Materials into my Program)
- https://www.youtube.com/watch?v=oxSlUFGx-SM (Tutorial how to create GUI Form in Intellij)
Applied Topic in My Program:
- Casting/Conversion
|
burger = Double.parseDouble(nburger.getText()); |
|
pizza = Double.parseDouble(npizza.getText()); |
|
cola = Double.parseDouble(ncola.getText()); |
|
water = Double.parseDouble(nwater.getText()); |
|
String str = Double.toString(a); |
|
double b = pizza * pizzadefault; |
|
String str1 = Double.toString(b); |
|
double c = water * waterdefault; |
|
String str2 = Double.toString(c); |
|
double d = cola * coladefault; |
|
String str3 = Double.toString(d); |
|
String str4 = Double.toString(result); |
- Constructor
|
public Employee(String Name, String pass) { |
|
this.Name = Name; |
|
this.setPass(pass); |
|
} |
- Overloading
|
public class Burger extends FoodDescription{ |
|
public void FoodDesc() { |
|
System.out.println("Burger: a flat round mass of minced meat or vegetables, which is fried and often eaten in a bread roll.\n"); |
|
} |
|
} |
|
public class Pizza extends FoodDescription{ |
|
public void FoodDesc() { |
|
System.out.println("Pizza: dish of Italian origin consisting of a flattened disk of bread dough topped with some combination\n"); |
|
} |
|
} |
- Overriding
|
public Food(String Name, Double Price, String Description){ |
|
this.Name = Name; |
|
this.Price = Price; |
|
this.Description = Description; |
|
} |
|
|
|
public Food(String Name, Double Price, String Description, Double Discount){ |
|
this.Name = Name; |
|
this.Price = Price; |
|
this.Description = Description; |
|
this.Discount = Discount; |
|
} |
- Encapsulation
|
public String getPass() { |
|
return pass; |
|
} |
|
|
|
public void setPass(String pass) { |
|
this.pass = pass; |
|
} |
- Inheritance
|
public class Water extends DrinksDescription{ |
|
@Override |
|
public void DrinksDesc() { |
|
System.out.println("Water: Pure Mineral Water to Enlighten your Thirst!\n"); |
|
} |
|
} |
|
public class Cola extends DrinksDescription{ |
|
@Override |
|
public void DrinksDesc() { |
|
|
|
System.out.println("Cola: Refreshing!\n"); |
|
} |
|
} |
- Polymorphism
|
public class DrinksDescription { |
|
public void DrinksDesc(){ |
|
System.out.println("Here are the description for the drinks: \n"); |
|
} |
|
} |
|
public class Water extends DrinksDescription{ |
|
@Override |
|
public void DrinksDesc() { |
|
System.out.println("Water: Pure Mineral Water to Enlighten your Thirst!\n"); |
|
} |
|
} |
|
public class Cola extends DrinksDescription{ |
|
@Override |
|
public void DrinksDesc() { |
|
|
|
System.out.println("Cola: Refreshing!\n"); |
|
} |
|
} |
|
DrinksDescription mydrinksdesc = new DrinksDescription(); |
|
DrinksDescription mycola = new Cola(); |
|
DrinksDescription mywater = new Water(); |
- ArrayList
|
ArrayList<String> MyEmployeeArray = new ArrayList<> |
|
(List.of("Bobby", "Tony", "Bob\n")); |
|
|
|
MyEmployeeArray.forEach(employeelist -> { |
|
System.out.println(employeelist); |
|
}); |
- Exception Handling
|
try { |
|
File data = new File ("data.txt"); |
|
Scanner dataScanner = new Scanner(data); |
|
while (dataScanner.hasNextLine()) { |
|
String[] keyValue = dataScanner.nextLine().split(":"); |
|
ReceiptText.setText( |
|
|
|
"---TOTAL---\n" + "Burger Price: " + keyValue[0] + "\nPizza Price: " + keyValue[1] + "\nWater Price: " |
|
+ keyValue[2] + "\nCola Price: " + keyValue[3] + "\nGrand Total: " + keyValue[4] |
|
); |
|
} |
|
dataScanner.close(); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
} |
|
} |
- GUI
|
public class Receipt extends JFrame{ |
|
private JTextArea ReceiptText; |
|
private JButton backButton; |
|
private JPanel ReceiptForm; |
|
|
|
public Receipt() { |
|
setContentPane(ReceiptForm); |
|
|
|
setTitle("Bills"); |
|
|
|
setSize(450,300); |
|
|
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
|
|
setVisible(true); |
|
backButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
if(e.getSource() == backButton){ |
|
Form myform1 = new Form(); |
|
|
|
} |
|
} |
|
}); |
|
public Form() { |
|
setContentPane(welcome); |
|
setTitle("WELCOME!"); |
|
setSize(450, 300); |
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
setVisible(true); |
|
calculateButton1.addActionListener(new ActionListener() { |
- Interface
|
public interface MenuFood { |
|
public void food(); |
|
|
|
class restaurant implements MenuFood { |
|
|
|
@Override |
|
public void food() { |
|
System.out.println("List of Foods: \n"); |
|
System.out.println("1. Burger \n2. Pizza\n"); |
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
- Abstract Class
|
abstract class MenuDrinks { |
|
public abstract void drinks(); |
|
} |
|
|
|
class drink extends MenuDrinks{ |
|
|
|
@Override |
|
public void drinks() { |
|
System.out.println("List of Drinks\n"); |
|
System.out.println("1. Water \n2. Cola\n"); |
|
} |
|
} |
- Generics
|
public static class employeee<T> { |
|
T employeename; |
|
|
|
employeee(T employeename) { |
|
this.employeename = employeename; |
|
} |
|
|
|
public T getEmployeename() { |
|
return employeename; |
|
} |
|
} |
|
} |
- Collection
|
ArrayList<String> list1 = new ArrayList<>(); |
|
list1.add("W"); |
|
list1.add("E"); |
|
list1.add("L"); |
|
list1.add("C"); |
|
list1.add("O"); |
|
list1.add("M"); |
|
list1.add("E"); |
|
System.out.println(" " + list1); |
|
Collections.sort(list1); |
- Input Output
|
new Thread(() -> { |
|
try { |
|
FileWriter fileWriter = new FileWriter(data, true); |
|
PrintWriter printWriter = new PrintWriter(fileWriter, false); |
|
|
|
double a = burger*burgerdefault; |
|
String str = Double.toString(a); |
|
double b = pizza * pizzadefault; |
|
String str1 = Double.toString(b); |
|
double c = water * waterdefault; |
|
String str2 = Double.toString(c); |
|
double d = cola * coladefault; |
|
String str3 = Double.toString(d); |
|
String str4 = Double.toString(result); |
|
|
|
printWriter.println(str + ":" + str1 + ":" + str2 + ":" + str3 + ":" + str4); |
|
|
|
printWriter.close(); |
|
} catch (Exception ignored) { |
|
ignored.printStackTrace(); |
|
} |
|
}).start(); |
|
File data = new File ("data.txt"); |
|
Scanner dataScanner = new Scanner(data); |
|
while (dataScanner.hasNextLine()) { |
|
String[] keyValue = dataScanner.nextLine().split(":"); |
|
ReceiptText.setText( |
|
|
|
"---TOTAL---\n" + "Burger Price: " + keyValue[0] + "\nPizza Price: " + keyValue[1] + "\nWater Price: " |
|
+ keyValue[2] + "\nCola Price: " + keyValue[3] + "\nGrand Total: " + keyValue[4] |
|
); |
|
} |
|
dataScanner.close(); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
} |