In: Computer Science
Write a program that computes the tax and tip on a restaurant bill for a patron with $44.50 meal charge. The tax should be 6.75% of the meal cost. The tip should be 15% of the total after adding tax. Display the meal cost, tax amount, tip amount, and total bill on the screen. (I need this to be in OOP).
Since you have not mentioned the language of your preference, I am providing the code in Java.
CODE
#include <iostream>
using namespace std;
class Bill {
private:
double mealCharge;
double taxPercentage;
double tipPercentage;
public:
Bill(double mealCharge, double taxPercentage, double tipPercentage) {
this->mealCharge = mealCharge;
this->taxPercentage = taxPercentage;
this->tipPercentage = tipPercentage;
}
double getTaxAmount() {
return taxPercentage/100 * mealCharge;
}
double getTipAmount() {
return tipPercentage/100 * mealCharge;
}
double getMealCost() {
return mealCharge;
}
double getTotalCost() {
return getMealCost() + getTaxAmount() + getTipAmount();
}
};
int main() {
Bill bill(44.5, 6.75, 15);
cout << "Meal cost: $" << bill.getMealCost() << endl;
cout << "Tax amount: $" << bill.getTaxAmount() << endl;
cout << "Tip amount: $" << bill.getTipAmount() << endl;
cout << "Total cost: $" << bill.getTotalCost() << endl;
}
Problems Javadoc Declaration Search Consol <terminated> Main (2) [Java Application] /Library/Java/JavaVirtualMa Meal cost: $44.5 Tax amount: $3.00375 Tip amount: $6.675 Total cost: $54.178749999999994