1. Car
Purpose: This class holds all the basic details of a car including its make, model, year of manufacture, and base price. It is a foundational entity in the system used to store and retrieve car-specific information.
Attributes:
make: String
– Represents the brand or manufacturer of the car (e.g., Toyota, Honda).model: String
– Indicates the specific model of the car.year: Int
– The manufacturing year of the car.basePrice: Double
– The initial or base price of the car before any calculations.
Methods:
getCarDetails(): String
– Returns a formatted string of the car’s details.getBasePrice(): Double
– Retrieves the base price of the car for pricing logic.
2. Customer
Purpose: This class stores information about the customer or user who is interacting with the system. It supports user-specific operations and serves as a reference for personalized services.
Attributes:
name: String
– Full name of the customer.email: String
– Email address for identification or communication.phone: String
– Contact number for customer support or follow-up.
Methods:
getCustomerInfo(): String
– Returns the complete customer information in a readable format.
3. PriceCalculator
Purpose: This class performs the core logic of calculating the final price of the car. It considers various cost-affecting factors such as taxes, discounts, and insurance.
Attributes:
taxRate: Double
– Percentage rate of applicable tax.discountRate: Double
– Percentage discount based on offers or promotions.insuranceCost: Double
– Additional cost added for vehicle insurance.
Methods:
calculateFinalPrice(car: Car): Double
– Calculates and returns the final car price after applying tax, discount, and insurance.applyDiscount(price: Double): Double
– Returns the discounted price.addTax(price: Double): Double
– Adds tax to the given price and returns the total.addInsurance(): Double
– Adds a fixed insurance amount to the price.
4. FinanceOption
Purpose: An optional class used when the customer wants to buy the car through financing or loan schemes. It calculates EMI based on the total price.
Attributes:
loanTerm: Int
– Duration of the loan in months.interestRate: Double
– Applicable interest rate per annum.
Methods:
calculateMonthlyInstallment(totalPrice: Double): Double
– Computes and returns the EMI (Equated Monthly Installment).getFinanceDetails(): String
– Provides a summary of the loan plan.
5. CarPriceCalculatorSystem (Main Controller)
Purpose: Acts as the central coordinator for the entire application. It manages cars, customers, and delegates pricing and financing tasks.
Attributes:
carList: List<Car>
– A collection of all available car objects.customerList: List<Customer>
– A collection of registered users.
Methods:
addCar(car: Car): void
– Adds a new car to the system.registerCustomer(customer: Customer): void
– Registers a new customer.generateQuote(car: Car, customer: Customer): Double
– Combines all services to provide a final quotation.