Skip to content

Instantly share code, notes, and snippets.

@Ellpeck

Ellpeck/Car.java Secret

Created October 17, 2019 18:08
Show Gist options
  • Save Ellpeck/595b929ce666fca6fb0ed792ca98d71e to your computer and use it in GitHub Desktop.
Save Ellpeck/595b929ce666fca6fb0ed792ca98d71e to your computer and use it in GitHub Desktop.
public class Car {
public String brandName;
public int horsepower;
public String licensePlate;
public int mileage;
public Car(String brandName, int horsepower, String licensePlate, int mileage) {
this.brandName = brandName;
this.horsepower = horsepower;
this.licensePlate = licensePlate;
this.mileage = mileage;
}
// Some code to see the information
public void printInformation() {
System.out.println(this.brandName + ", " + this.horsepower + " HP, License Plate: " + this.licensePlate + ", " + this.mileage + " miles");
}
}
public class Customer {
public String firstName;
public String lastName;
public String city;
public Customer(String firstName, String lastName, String city) {
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
}
// Some code to see the information
public void printInformation() {
System.out.println(this.firstName + " " + this.lastName + " from " + this.city);
}
}
import java.util.ArrayList;
public class Main {
public static Car[] cars = new Car[15];
public static ArrayList<Customer> customers = new ArrayList<>();
public static void main(String[] args) {
addCar(new Car("Honda", 120, "AC-HI 1234", 1000));
addCar(new Car("Fiat", 200, "AC-HI 2345", 2000));
addCar(new Car("Volkswagen", 150, "AC-HI 3456", 0));
addCar(new Car("BMW", 200, "AC-HI 4567", 3000));
addCustomer(new Customer("Justus", "Jonas", "Rocky Beach"));
addCustomer(new Customer("Peter", "Shaw", "Rocky Beach"));
addCustomer(new Customer("Bob", "Andrews", "Rocky Beach"));
// Some code to see the information
cars[3].printInformation();
customers.get(1).printInformation();
}
public static void addCar(Car car) {
for (int i = 0; i < cars.length; i++) {
if (cars[i] == null) {
cars[i] = car;
break;
}
}
}
public static void addCustomer(Customer customer) {
customers.add(customer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment