chore: Lab02

This commit is contained in:
Fándly Gergő 2020-10-28 08:49:08 +02:00
parent c5969f3f0a
commit d823679db2
5 changed files with 104 additions and 0 deletions

10
Lab02/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Lab02/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Lab02</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

45
Lab02/src/lab02/Car.java Normal file
View File

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

View File

@ -0,0 +1,6 @@
package lab02;
public enum Fuel {
Diesel,
Petrol
}

View File

@ -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<Car> cars = new ArrayList<Car>();
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());
}
}
}