Hack 1

public class Car {
    public static void main(String[] args) {
        int year = 2023;
        double price = 30000.00;
        boolean isElectric = true;
        
        System.out.println("Year: " + year);
        System.out.println("Price: $" + price);
        System.out.println("Is Electric: " + isElectric);
    }
}
import java.util.Scanner;

public class CarPrice {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the price of the car: ");
        double price = scanner.nextDouble();

        System.out.println("The price of the car is $" + price);

        scanner.close();
    }
}
int cars = 0; // starting number of cars
int numCarsEntering = 2; // number of cars entering at a time
int numIterations = 5; // number of times to loop

for (int i = 0; i < numIterations; i++) {
    cars += numCarsEntering; // use compound operator to add cars
    System.out.println("Number of cars on highway: " + cars);
}
Number of cars on highway: 2
Number of cars on highway: 4
Number of cars on highway: 6
Number of cars on highway: 8
Number of cars on highway: 10
public class Hack1 {
    public static void main(String[] args) {
        int cars = 0; // starting number of cars
        int numCarsEntering = 2; // number of cars entering at a time
        int numIterations = 5; // number of times to loop

        for (int i = 0; i < numIterations; i++) {
            cars += numCarsEntering; // use compound operator to add cars
            //System.out.println("Number of cars on highway: " + cars);
            int wheels = cars*4; 
                System.out.println("wheels: " + wheels);
        }
        
        //calculate cars
        int wheels = cars*4; 
        System.out.println("total wheels: " + wheels);

    }
}

Hack1.main(null);
wheels: 8
wheels: 16
wheels: 24
wheels: 32
wheels: 40
total wheels: 40

Hack 2

public class Car {
    // create constructor
    private String make;
    private String model;
    private int year;
    private double price;
    private boolean isUsed;

    public Car(String make2, String model2, int year2, double price2, boolean isUsed2){
        make = make2;
        model = model2;
        year = year2;
        price = price2;
        isUsed = isUsed2;
    }
    public String printCarDetails() {
        // method to print car details
        String return_s = "Make: " + make + " Model: " + model + " year: " + year + " price: " + price + " is it used? " + isUsed;
        return return_s;
      }

    public static void main(String[] args){
        Car car1 = new Car("Toyota", "Corolla", 2022, 24999.99, false);
        Car car2 = new Car("Honda", "Accord", 2018, 18999.99, true);
        Car car3 = new Car("Ford", "Mustang", 2020, 34999.99, true );
        //ArrayList<Car> cars = new ArrayList<Car>();
        Car[] cars = new Car[3];
        cars[0] = car1;
        cars[1] = car2;
        cars[2] = car3;
        for (int i=0; i<cars.length; i++){
           // String car_print = cars[i].printCarDetails();
            System.out.println(cars[i].printCarDetails());
        }
    }
}

Car.main(null);
Make: Toyota Model: Corolla year: 2022 price: 24999.99 is it used? false
Make: Honda Model: Accord year: 2018 price: 18999.99 is it used? true
Make: Ford Model: Mustang year: 2020 price: 34999.99 is it used? true

Hack 3

public class Car2 {
    
    private String make;
    private String model;
    private int year;
    private double price;
    private String result;
    
    // Constructor
    public Car2(String make2, String model2, int year2, double price2) {
        make = make2;
        model = model2;
        year = year2;
        price = price2;
        result = "The car is an affordable car.";

    }
    
    // Getter methods
    public String getMake() {
        return make;
    }
    
    public String getModel() {
        return model;
    }
    
    public int getYear() {
        return year;
    }
    
    public double getPrice() {
        return price;
    }
    
    // Method to determine if the car is affordable or not

    public boolean isAffordable(double budget) {
        if (price < budget) {
            return true;
        } else {
            return false;
        }
    }
   

    public String classification(){
        if(price>50000){
            result = "The car is a luxury car.";
            return result;
        }
        else if(price>30000){
            result = "The car is a mid-range car.";
            return result;
        }
        else{
            return result;
        }
    }
    
    // Main method
    public static void main(String[] args) {
        // Create a new Car object
        Car2 myCar = new Car2("Toyota", "Camry", 2019, 25000.0);

        // Print the car details
        System.out.println("Make: " + myCar.getMake());
        System.out.println("Model: " + myCar.getModel());
        System.out.println("Year: " + myCar.getYear());
        System.out.println("Price: " + myCar.getPrice());
        // Check if the car is affordable with a budget of $20000 using an if-else statement
        System.out.println("Affordable? " + myCar.isAffordable(20000.0));
        // Check if the car is a luxury car based on its price using if-else-if statement
        System.out.println(myCar.classification());
        
    
    }
}
Car2.main(null);
Make: Toyota
Model: Camry
Year: 2019
Price: 25000.0
Affordable? false
The car is an affordable car.

Hack 4

import java.util.Scanner; 
public class hackCar{
    private static int car;

    public hackCar(int car2){
        car = car2;
    }

    public static void prompter(){
        while(car>0){
           
            try{
                Scanner myObj = new Scanner(System.in);  // Create a Scanner object
                System.out.println("Car make: ");
                String make = myObj.nextLine();  // Read user input
                System.out.println("Make is: " + make);  // Output user input

                
                Scanner myObj2 = new Scanner(System.in);  // Create a Scanner object
                System.out.println("Car model: ");
                String model = myObj2
                .nextLine();  // Read user input
                System.out.println("Model is: " + model);  // Output user input
                System.out.println();
                car--;

            }

            catch(Exception e) {
                System.out.println("Input not valid");
            }
            


        }

    }

    public static void main(String[] args){
        hackCar a = new hackCar(5);
        a.prompter();
    }


}

hackCar.main(null);
Car make: 
Make is: toyota
Car model: 
Model is: camary

Car make: 
Make is: tesla
Car model: 
Model is: X

Car make: 
Make is: nissan
Car model: 
Model is: rogue

Car make: 
Make is: nissan
Car model: 
Model is: altima

Car make: 
Make is: nissan
Car model: 
Model is: Input not valid