EricAzka01 / FP-OOP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

# 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:

  1. Oracle Fundamental Programming (Where I implemented the OOP Materials into my Program)
  2. https://www.youtube.com/watch?v=oxSlUFGx-SM (Tutorial how to create GUI Form in Intellij)

Applied Topic in My Program:

  1. Casting/Conversion

    FP-OOP/src/Form.java

    Lines 49 to 52 in 4594325

    burger = Double.parseDouble(nburger.getText());
    pizza = Double.parseDouble(npizza.getText());
    cola = Double.parseDouble(ncola.getText());
    water = Double.parseDouble(nwater.getText());

    FP-OOP/src/Form.java

    Lines 79 to 86 in 4594325

    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);
  2. Constructor
    public Employee(String Name, String pass) {
    this.Name = Name;
    this.setPass(pass);
    }
  3. 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");
    }
    }

    FP-OOP/src/Pizza.java

    Lines 1 to 5 in 4594325

    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");
    }
    }
  4. Overriding

    FP-OOP/src/Food.java

    Lines 10 to 21 in 4594325

    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;
    }
  5. Encapsulation

    FP-OOP/src/Employee.java

    Lines 14 to 20 in 4594325

    public String getPass() {
    return pass;
    }
    public void setPass(String pass) {
    this.pass = pass;
    }
  6. Inheritance

    FP-OOP/src/Water.java

    Lines 1 to 6 in 4594325

    public class Water extends DrinksDescription{
    @Override
    public void DrinksDesc() {
    System.out.println("Water: Pure Mineral Water to Enlighten your Thirst!\n");
    }
    }

    FP-OOP/src/Cola.java

    Lines 1 to 7 in 4594325

    public class Cola extends DrinksDescription{
    @Override
    public void DrinksDesc() {
    System.out.println("Cola: Refreshing!\n");
    }
    }
  7. Polymorphism
    public class DrinksDescription {
    public void DrinksDesc(){
    System.out.println("Here are the description for the drinks: \n");
    }
    }

    FP-OOP/src/Water.java

    Lines 1 to 6 in 4594325

    public class Water extends DrinksDescription{
    @Override
    public void DrinksDesc() {
    System.out.println("Water: Pure Mineral Water to Enlighten your Thirst!\n");
    }
    }

    FP-OOP/src/Cola.java

    Lines 1 to 7 in 4594325

    public class Cola extends DrinksDescription{
    @Override
    public void DrinksDesc() {
    System.out.println("Cola: Refreshing!\n");
    }
    }

    FP-OOP/src/Main.java

    Lines 33 to 35 in 4594325

    DrinksDescription mydrinksdesc = new DrinksDescription();
    DrinksDescription mycola = new Cola();
    DrinksDescription mywater = new Water();
  8. ArrayList

    FP-OOP/src/Main.java

    Lines 55 to 60 in 4594325

    ArrayList<String> MyEmployeeArray = new ArrayList<>
    (List.of("Bobby", "Tony", "Bob\n"));
    MyEmployeeArray.forEach(employeelist -> {
    System.out.println(employeelist);
    });
  9. Exception Handling

    FP-OOP/src/Receipt.java

    Lines 32 to 47 in 4594325

    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();
    }
    }
  10. GUI

    FP-OOP/src/Receipt.java

    Lines 7 to 30 in 4594325

    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();
    }
    }
    });

    FP-OOP/src/Form.java

    Lines 28 to 34 in 4594325

    public Form() {
    setContentPane(welcome);
    setTitle("WELCOME!");
    setSize(450, 300);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setVisible(true);
    calculateButton1.addActionListener(new ActionListener() {
  11. 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");
    }
    }
    }
  12. 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");
    }
    }
  13. Generics

    FP-OOP/src/Employee.java

    Lines 22 to 33 in 4594325

    public static class employeee<T> {
    T employeename;
    employeee(T employeename) {
    this.employeename = employeename;
    }
    public T getEmployeename() {
    return employeename;
    }
    }
    }
  14. Collection

    FP-OOP/src/Main.java

    Lines 40 to 49 in 4594325

    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);
  15. Input Output

    FP-OOP/src/Form.java

    Lines 73 to 94 in 4594325

    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();

    FP-OOP/src/Receipt.java

    Lines 33 to 46 in 4594325

    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();
    }

About