chore: Lab02
This commit is contained in:
		
							
								
								
									
										10
									
								
								Lab02/.classpath
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Lab02/.classpath
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										17
									
								
								Lab02/.project
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										45
									
								
								Lab02/src/lab02/Car.java
									
									
									
									
									
										Normal 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); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										6
									
								
								Lab02/src/lab02/Fuel.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Lab02/src/lab02/Fuel.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| package lab02; | ||||
|  | ||||
| public enum Fuel { | ||||
| 	Diesel, | ||||
| 	Petrol | ||||
| } | ||||
							
								
								
									
										26
									
								
								Lab02/src/lab02/Lab02.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Lab02/src/lab02/Lab02.java
									
									
									
									
									
										Normal 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()); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user