User Story
As a dealership manager, I want to leverage Apex classes to enhance the vehicle inventory management system in Salesforce. I need to customize the display of vehicle details and calculate the total price based on specific features for cars, motorcycles, and trucks.
Acceptance Criteria:
- As a dealership manager, I want to create a custom Apex class called "Car" that extends the abstract class "Vehicle" and includes additional attributes such as "bodyType".
- The "Car" class should override the "displayDetails()" method to display the car's make, model, year, and body type.
- The "Car" class should also override the "calculateTotalPrice()" method to include custom logic for calculating the total price of a car, considering additional charges for specific features.
- Similarly, I want to create a custom Apex class called "Motorcycle" that extends the abstract class "Vehicle" and includes the "style" attribute.
- The "Motorcycle" class should override the "displayDetails()" method to display the motorcycle's make, model, year, and style.
- The "Motorcycle" class should also override the "calculateTotalPrice()" method to include custom logic for calculating the total price of a motorcycle, considering customization charges.
- Additionally, I want to create a custom Apex class called "Truck" that extends the abstract class "Vehicle" and includes the "loadCapacity" attribute.
- The "Truck" class should override the "displayDetails()" method to display the truck's make, model, year, and load capacity in tons.
- The "Truck" class should also override the "calculateTotalPrice()" method to include custom logic for calculating the total price of a truck, considering additional charges for towing capabilities.
Code
Abstract Class
public abstract class Vehicle {
public String make;
public String model;
public Integer year;
public Decimal price;
public abstract void displayDetails();
public abstract void calculateTotalPrice();
}
Car Class:
public class Car extends Vehicle {
public String bodyType;
public override void displayDetails() {
System.debug('Car Details: ' + make + ' ' + model + ', Year: ' + year + ', Body Type: ' + bodyType);
}
public override void calculateTotalPrice() {
// Custom logic for calculating total price of a car
// Example: price + additional charges for features
}
}
Motorcycle Class:
public class Motorcycle extends Vehicle {
public String style;
public override void displayDetails() {
System.debug('Motorcycle Details: ' + make + ' ' + model + ', Year: ' + year + ', Style: ' + style);
}
public override void calculateTotalPrice() {
// Custom logic for calculating total price of a motorcycle
// Example: price + customization charges
}
}
Truck Class:
public class Truck extends Vehicle {
public Integer loadCapacity;
public override void displayDetails() {
System.debug('Truck Details: ' + make + ' ' + model + ', Year: ' + year + ', Load Capacity: ' + loadCapacity + ' tons');
}
public override void calculateTotalPrice() {
// Custom logic for calculating total price of a truck
// Example: price + additional charges for towing capabilities
}
}
Video
Video does not exists.