Skip to content

Palak6969/Java-project-Guvi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Vehicle Simulation Project Overview This Java project simulates the behavior of different types of vehicles, including cars, motorcycles, and trucks. It demonstrates the use of inheritance, abstract classes, and polymorphism, with each vehicle having distinct behaviors for starting the engine, accelerating, and braking.

Features Abstract Vehicle Class: The Vehicle class serves as a base class for all vehicle types. It defines common properties like brand, year, and speed, and abstract methods for starting the engine, accelerating, and braking.

Car Class: The Car class extends the Vehicle class and adds properties specific to cars, such as the number of doors.

Motorcycle Class: The Motorcycle class extends the Vehicle class and introduces a boolean property to determine if the motorcycle has a sidecar.

Truck Class: The Truck class extends the Vehicle class and adds the cargoCapacity property to represent the truck's load capacity.

Requirements Java 8 or higher.

An IDE or text editor to edit the Java files (e.g., IntelliJ IDEA, Eclipse, or Visual Studio Code).

JDK installed on your machine.

How to Run the Project Clone the repository:

bash Copy code git clone https://github.com/your-username/vehicle-simulation.git Navigate into the project folder:

bash Copy code cd vehicle-simulation Compile and run the Vehicle class:

bash Copy code javac Vehicle.java Car.java Motorcycle.java Truck.java java Vehicle This will run the main method in the Vehicle class, which demonstrates:

Starting the engines of all vehicles.

Accelerating all vehicles.

Braking all vehicles.

Displaying the vehicle details, including brand, year, speed, and specific attributes of each vehicle type (e.g., number of doors for cars, sidecar for motorcycles, cargo capacity for trucks).

Project Structure bash Copy code /vehicle-simulation ├── Vehicle.java # Base class for all vehicle types ├── Car.java # Represents a car with specific attributes ├── Motorcycle.java # Represents a motorcycle with specific attributes ├── Truck.java # Represents a truck with specific attributes ├── README.md # Project documentation (this file) Example Output When you run the project, the following output will be displayed:

yaml Copy code Starting all vehicles: Toyota car's engine is starting with a roar! Harley-Davidson motorcycle's engine is revving up! Volvo truck's heavy-duty engine is starting!

Accelerating all vehicles: Toyota car is accelerating to 50.0 km/h Harley-Davidson motorcycle is accelerating to 60.0 km/h Volvo truck is accelerating to 40.0 km/h

Braking all vehicles: Toyota car is braking to 30.0 km/h Harley-Davidson motorcycle is braking to 54.0 km/h Volvo truck is braking to 36.0 km/h

Vehicle Details: Brand: Toyota, Year: 2023, Current Speed: 30.0 Type: Car, Number of Doors: 4

Brand: Harley-Davidson, Year: 2022, Current Speed: 54.0 Type: Motorcycle, Has Sidecar: false

Brand: Volvo, Year: 2021, Current Speed: 36.0 Type: Truck, Cargo Capacity: 5000.0 kg

Multiple Acceleration Cycles: Cycle 1: Toyota car is accelerating to 40.0 km/h Harley-Davidson motorcycle is accelerating to 66.0 km/h Volvo truck is accelerating to 43.0 km/h

Cycle 2: Toyota car is accelerating to 50.0 km/h Harley-Davidson motorcycle is accelerating to 78.0 km/h Volvo truck is accelerating to 46.0 km/h

Cycle 3: Toyota car is accelerating to 60.0 km/h Harley-Davidson motorcycle is accelerating to 90.0 km/h Volvo truck is accelerating to 49.0 km/h License This project is open-source and available under the MIT License. See the LICENSE file for more details.

Contributing Feel free to submit a pull request or open an issue if you want to contribute or report bugs.

Let me know if you need to modify or add anything!

By messaging ChatGPT, you agree to our Terms and have read our Privacy Policy. See Cookie Preferences. Don't share sensitive info. Chats may be reviewed and used to train our models. Learn more

ChatGPT can make mistakes. Check important info. See Cookie Preferences.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors