0% found this document useful (0 votes)
18 views2 pages

Activity Midterm

The document contains a Java class named MyClass that creates instances of a Car class and demonstrates its methods. The Car class has instance variables for make, model, and color, along with methods to start, accelerate, and brake the car. There are issues in the code, such as missing constructor definition and incorrect getter implementations.

Uploaded by

loida.04bautista
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Activity Midterm

The document contains a Java class named MyClass that creates instances of a Car class and demonstrates its methods. The Car class has instance variables for make, model, and color, along with methods to start, accelerate, and brake the car. There are issues in the code, such as missing constructor definition and incorrect getter implementations.

Uploaded by

loida.04bautista
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class MyClass {

public static void main(String[] args) {


// Create instances of the Car class
Car car1 = Car("Toyota", "Camry", "Red");
Car car2 = Car("Honda", "Civic", "Blue");

// Call methods on the car objects


car1.start();
car1.accelerate();
car2.start();
car2.brake();

// Access and print the car information


System.out.println("Car 1 Make: " + car1.getMake());
System.out.println("Car 2 Model: " + car2.getModel());
System.out.println("Car 1 Color: " + car1.getColor());
}
}

class Car {
// Instance variables
private String make;
private String model;
private String color;

// Constructor to initialize the Car object


public (String make, String model, String color) {
make = make;
model = model;
color = color;
}

// Method to start the car


public void start() {
System.out.println(+ " " + model + " is starting...");
}

// Method to accelerate the car


public void accelerate() {
System.out.println(+ " " + model + " is accelerating...");
}

// Method to brake the car


public void brake() {
System.out.println(+ " " + model + " is braking...");
}

// Getter methods
public String getMake() {
make;
}

public String getModel() {


model;
}

public String getColor() {


color;
}
}

You might also like