From d823679db27fb5121bdaf224c84bb52c89e14b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1ndly=20Gerg=C5=91?= Date: Wed, 28 Oct 2020 08:49:08 +0200 Subject: [PATCH] chore: Lab02 --- Lab02/.classpath | 10 +++++++++ Lab02/.project | 17 ++++++++++++++ Lab02/src/lab02/Car.java | 45 ++++++++++++++++++++++++++++++++++++++ Lab02/src/lab02/Fuel.java | 6 +++++ Lab02/src/lab02/Lab02.java | 26 ++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 Lab02/.classpath create mode 100644 Lab02/.project create mode 100644 Lab02/src/lab02/Car.java create mode 100644 Lab02/src/lab02/Fuel.java create mode 100644 Lab02/src/lab02/Lab02.java diff --git a/Lab02/.classpath b/Lab02/.classpath new file mode 100644 index 0000000..9af0373 --- /dev/null +++ b/Lab02/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Lab02/.project b/Lab02/.project new file mode 100644 index 0000000..73024b9 --- /dev/null +++ b/Lab02/.project @@ -0,0 +1,17 @@ + + + Lab02 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Lab02/src/lab02/Car.java b/Lab02/src/lab02/Car.java new file mode 100644 index 0000000..17f8a10 --- /dev/null +++ b/Lab02/src/lab02/Car.java @@ -0,0 +1,45 @@ +package lab02; + +import javax.swing.JOptionPane; + +public class Car { + private String brand; + private int year; + private Fuel fuel; + + public void getBrand() { + JOptionPane.showMessageDialog(null, brand); + } + public void setBrand() { + brand = JOptionPane.showInputDialog("Brand = "); + } + + public void getYear() { + JOptionPane.showMessageDialog(null, year); + } + public void setYear() { + year = Integer.parseInt(JOptionPane.showInputDialog("Year = ")); + } + + public void getFuel() { + JOptionPane.showMessageDialog(null, fuel); + } + public void setFuel() { + Object[] possibilities = {"Diesel", "Petrol"}; + + String response = (String)JOptionPane.showInputDialog(null, "Fuel = ", null, JOptionPane.PLAIN_MESSAGE, null, possibilities, "Diesel"); + + fuel = Fuel.valueOf(response); + } + + public void setAll() { + setBrand(); + setYear(); + setFuel(); + } + + @Override + public String toString() { + return brand + " (" + String.valueOf(year) +") - " + String.valueOf(fuel); + } +} diff --git a/Lab02/src/lab02/Fuel.java b/Lab02/src/lab02/Fuel.java new file mode 100644 index 0000000..3f67922 --- /dev/null +++ b/Lab02/src/lab02/Fuel.java @@ -0,0 +1,6 @@ +package lab02; + +public enum Fuel { + Diesel, + Petrol +} diff --git a/Lab02/src/lab02/Lab02.java b/Lab02/src/lab02/Lab02.java new file mode 100644 index 0000000..03c5d2d --- /dev/null +++ b/Lab02/src/lab02/Lab02.java @@ -0,0 +1,26 @@ +package lab02; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JOptionPane; + +public class Lab02 { + + public static void main(String[] args) { + List cars = new ArrayList(); + + int x = Integer.parseInt(JOptionPane.showInputDialog("x = ")); + + for(int i = 0; i < x; i++) { + Car car = new Car(); + car.setAll(); + cars.add(car); + } + + for(Car car: cars) { + JOptionPane.showMessageDialog(null, car.toString()); + } + } + +}