In: Computer Science
Good Evening Guys,
It was given an assignment in which I have to implement iava object oriented programing. What I'm saying is that I wrote a restaurant order program in java but the whole code is located in main. Now, they want me to implement diferent classes (super), constructors, accesors, mutators, methods, objects, inheritance, polymorfism, overloading, overring, interfaces, and exceptions. I already wrote my program which works perfectly, I do not know how to implement all this object oriented features in my existing code, the date line is coming up pretty soon. Please help!!!!!
This is my existing code:
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;
public class Mac190Restaurant {
public static void main(String[] args) {
Scanner CashierInput = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
Date dateCreated = new Date();
int Choice = 0;
double CheeseBurger = 4.45;
double ChickenBurger = 5.25;
double SuperHotDog = 3.55;
double MiniHotDog = 2.99;
double Fries = 1.75;
double OnionRings = 1.75;
double Soda = 1.55;
double BottleWater = 1.25;
int CheeseBCount = 0;
int ChickenBCount = 0;
int SuperHDCount = 0;
int MiniHDCount = 0;
int FriesCount = 0;
int OnionRCount = 0;
int SodaCount = 0;
int BottleWCount = 0;
int ItemNum = 0;
double Tax = 0;
double NYTax = 8.78;
double SubTotal= 0;
double Total =0;
double TotalFinal = 0;
System.out.println("//////////////// Mac King Fast Food ////////////////");
System.out.println(" \nBurgers:" + " " + "Side Orders: ");
System.out.println(" 1. CheeseBurger $" + df.format(CheeseBurger) + " " + "5. Fries $" + df.format(Fries));
System.out.println(" 2. ChickenBurger $" + df.format(ChickenBurger) + " " + "6. Onion Rings $" + df.format(OnionRings));
System.out.println(" \nHot Dogs:" + " " + "Beverages: ");
System.out.println(" 3. Super HotDog $" + df.format(SuperHotDog) + " " + "7. Soda $" + df.format(Soda));
System.out.println(" 4. Mini HotDog $" + df.format(MiniHotDog) + " " + "8. Bottle of Water $" + df.format(BottleWater));
do {
if (Choice != 0)
{
System.out.print(" !!Enter (0) to finish Order!!\n");
}
System.out.print(" \nEnter menu selection: ");
Choice = CashierInput.nextInt();
if (Choice == 1)
{
System.out.println("\nCheeseBurger added");
SubTotal = CheeseBurger;
++CheeseBCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 2)
{
System.out.println("\nChickenBurger added");
SubTotal = ChickenBurger;
++ChickenBCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 3)
{
System.out.println("\nSuper HotDog added");
SubTotal = SuperHotDog;
++SuperHDCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 4)
{
System.out.println("\nMini HotDog added");
SubTotal = MiniHotDog;
++MiniHDCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 5)
{
System.out.println("\nFries added");
SubTotal = Fries;
++FriesCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println ("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 6)
{
System.out.println("\nOnion Rings added");
SubTotal = OnionRings;
++OnionRCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 7)
{
System.out.println("\nSoda added");
SubTotal = Soda;
++SodaCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" + (df.format(Total)));
}
else if (Choice == 8)
{
System.out.println("\nBottle Water added");
SubTotal = BottleWater;
++BottleWCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println ("Current Subtotal $" + (df.format(Total)));
}
else if (Choice > 8 || Choice < 0)
{
System.out.println("\nWrong choice!!! Please enter a choice again");
}
}
while(Choice != 0);
CashierInput.close();
Tax = ((Total * NYTax) / 100);
TotalFinal = Total + Tax;
System.out.println("\n\tRECEIPT\n\n" + dateCreated + "\n");
Random RanNum = new Random();
for(int i = 0; i < 1; i++)
{
int Number = RanNum.nextInt(99) + 1;
System.out.println("Order number: "+ Number);
}
if (CheeseBCount != 0 || Choice == 1)
{
System.out.println(CheeseBCount + " CheeseBurger");
}
if (ChickenBCount != 0 || Choice == 2)
{
System.out.println(ChickenBCount + " ChickenBurger");
}
if (SuperHDCount != 0 || Choice == 3)
{
System.out.println(SuperHDCount + " Super HotDog");
}
if (MiniHDCount != 0 || Choice == 4)
{
System.out.println(MiniHDCount + " Mini HotDog");
}
if (FriesCount != 0 || Choice == 5)
{
System.out.println(FriesCount + " Fries");
}
if (OnionRCount != 0 || Choice == 6)
{
System.out.println(OnionRCount + " Onion Rings");
}
if (SodaCount != 0 || Choice == 7)
{
System.out.println(SodaCount + " Soda");
}
if (BottleWCount != 0 || Choice == 8)
{
System.out.println(BottleWCount + " Bottle of Water");
}
System.out.println("Items ordered: " + ItemNum +" Items");
System.out.println("Subtotal: $" + (df.format(Total)));
System.out.println("NY Tax 8.78%: $" + (df.format(Tax)));
System.out.println("Total: $ " + (df.format(TotalFinal)));
System.out.println("\nThank you. Please come again!");
}
}
package javaapplication6;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author Rashmi Tiwari
*/
interface Restaurant{ //Interface
void addItem();
}
class Burger implements Restaurant{ //Inheritance
static int burgerCount;
Burger(){
burgerCount=0;
}
public void addItem() {
++burgerCount;
}
}
class CheeseBurger extends Burger{
double cheeseBurger;
static int cheeseBCount;
public CheeseBurger() {
cheeseBurger=0;
cheeseBCount=0;
}
public CheeseBurger(double cheeseBurger){
this.cheeseBurger=cheeseBurger;
}
}
class ChickenBurger extends Burger{
double chickenBurger;
static int chickenBCount;
public ChickenBurger() {
chickenBurger=0;
chickenBCount=0;
}
public ChickenBurger(double chickenBurger){
this.chickenBurger=chickenBurger;
}
}
class SideOrder implements Restaurant{
static int sideOrderCount;
SideOrder(){
sideOrderCount=0;
}
public void addItem() {
++sideOrderCount;
}
}
class Fries extends SideOrder{
double fries;
static int friesCount;
Fries(){
fries=0;
friesCount=0;
}
Fries(double fries){
this.fries=fries;
}
}
class OnionRings extends SideOrder{
double onionRings;
static int onionRCount;
OnionRings(){
onionRings=0;
onionRCount=0;
}
OnionRings(double onionRings){
this.onionRings=onionRings;
}
}
class HotDog implements Restaurant{
static int hotDogCount;
HotDog(){
hotDogCount=0;
}
public void addItem() {
++hotDogCount;
}
}
class SuperHotDog extends HotDog{
double superHotDog;
static int superHotDogCount;
SuperHotDog(){
superHotDog=0;
superHotDogCount=0;
}
SuperHotDog(double superHotDog){
this.superHotDog=superHotDog;
}
}
class MiniHotDog extends HotDog{
double miniHotDog;
static int miniHotDogCount;
MiniHotDog(){
miniHotDog=0;
miniHotDogCount=0;
}
MiniHotDog(double miniHotDog){
this.miniHotDog=miniHotDog;
}
}
class Beverage implements Restaurant{
static int beverageOrderCount;
Beverage(){
beverageOrderCount=0;
}
public void addItem() {
++beverageOrderCount;
}
}
class Soda extends Beverage{
double soda;
static int sodaCount;
Soda(){
soda=0;
sodaCount=0;
}
Soda(double soda){
this.soda=soda;
}
}
class BottleWater extends Beverage{
double bottleWater;
static int bottleWaterRCount;
BottleWater(){
bottleWater=0;
bottleWaterRCount=0;
}
BottleWater(double bottleWater){
this.bottleWater=bottleWater;
}
}
public class Mac190Restaurant1 {
public static void main(String args[]){
Scanner CashierInput = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
Date dateCreated = new Date();
int Choice = 0;
CheeseBurger cheeseB=new CheeseBurger(4.45);
ChickenBurger chickenB=new ChickenBurger(5.25);
Fries friesS=new Fries(1.75);
OnionRings onionR=new OnionRings(1.75);
SuperHotDog superHotDog=new SuperHotDog(3.55);
MiniHotDog miniHotDog=new MiniHotDog(2.99);
Soda sodaB=new Soda(1.55);
BottleWater bottleWaterB=new BottleWater(1.25);
int ItemNum = 0;
double Tax = 0;
double NYTax = 8.78;
double SubTotal= 0;
double Total =0;
double TotalFinal = 0;
System.out.println("//////////////// Mac King Fast Food
////////////////");
System.out.println(" \nBurgers:" + " " + "Side Orders: ");
System.out.println(" 1. CheeseBurger $" +
df.format(cheeseB.cheeseBurger) + " " + "5. Fries $" +
df.format(friesS.fries));
System.out.println(" 2. ChickenBurger $" +
df.format(chickenB.chickenBurger) + " " + "6. Onion Rings $" +
df.format(onionR.onionRings));
System.out.println(" \nHot Dogs:" + " " + "Beverages: ");
System.out.println(" 3. Super HotDog $" +
df.format(superHotDog.superHotDog) + " " + "7. Soda $" +
df.format(sodaB.soda));
System.out.println(" 4. Mini HotDog $" +
df.format(miniHotDog.miniHotDog) + " " + "8. Bottle of Water $" +
df.format(bottleWaterB.bottleWater));
do {
if (Choice != 0)
{
System.out.print(" !!Enter (0) to finish Order!!\n");
}
System.out.print(" \nEnter menu selection: ");
Choice = CashierInput.nextInt();
if (Choice == 1)
{
System.out.println("\nCheeseBurger added");
SubTotal = cheeseB.cheeseBurger;
cheeseB.addItem();
++CheeseBurger.cheeseBCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 2)
{
System.out.println("\nChickenBurger added");
SubTotal = chickenB.chickenBurger;
chickenB.addItem();
++ChickenBurger.chickenBCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 3)
{
System.out.println("\nSuper HotDog added");
SubTotal = superHotDog.superHotDog;
superHotDog.addItem();
++superHotDog.superHotDogCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 4)
{
System.out.println("\nMini HotDog added");
SubTotal = miniHotDog.miniHotDog;
miniHotDog.addItem();
++miniHotDog.miniHotDogCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 5)
{
System.out.println("\nFries added");
SubTotal = friesS.fries;
friesS.addItem();
++friesS.friesCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println ("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 6)
{
System.out.println("\nOnion Rings added");
SubTotal = onionR.onionRings;
onionR.addItem();
++onionR.onionRCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 7)
{
System.out.println("\nSoda added");
SubTotal = sodaB.soda;
sodaB.addItem();
++sodaB.sodaCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice == 8)
{
System.out.println("\nBottle Water added");
SubTotal = bottleWaterB.bottleWater;
bottleWaterB.addItem();
++bottleWaterB.bottleWaterRCount;
++ItemNum;
Total = Total + SubTotal;
System.out.println ("Current Subtotal $" +
(df.format(Total)));
}
else if (Choice > 8 || Choice < 0)
{
System.out.println("\nWrong choice!!! Please enter a choice
again");
}
}
while(Choice != 0);
CashierInput.close();
Tax = ((Total * NYTax) / 100);
TotalFinal = Total + Tax;
System.out.println("\n\tRECEIPT\n\n" + dateCreated + "\n");
Random RanNum = new Random();
for(int i = 0; i < 1; i++)
{
int Number = RanNum.nextInt(99) + 1;
System.out.println("Order number: "+ Number);
}
if(Burger.burgerCount!=0){
if (CheeseBurger.cheeseBCount != 0 || Choice == 1){
System.out.println(CheeseBurger.cheeseBCount + "
CheeseBurger");
}
if (ChickenBurger.chickenBCount != 0 || Choice == 2){
System.out.println(ChickenBurger.chickenBCount + "
ChickenBurger");
}
System.out.println("Total Burger Ordered
="+Burger.burgerCount);
}
if(HotDog.hotDogCount!=0){
if (SuperHotDog.superHotDogCount != 0 || Choice == 3)
{
System.out.println(SuperHotDog.superHotDogCount + " Super
HotDog");
}
if (MiniHotDog.miniHotDogCount != 0 || Choice == 4)
{
System.out.println(MiniHotDog.miniHotDogCount + " Mini
HotDog");
}
System.out.println("Total HotDog Ordered
="+HotDog.hotDogCount);
}
if(SideOrder.sideOrderCount!=0){
if (Fries.friesCount != 0 || Choice == 5)
{
System.out.println(Fries.friesCount + " Fries");
}
if (OnionRings.onionRCount != 0 || Choice == 6)
{
System.out.println(OnionRings.onionRCount + " Onion Rings");
}
System.out.println("Total Side Order Ordered
="+SideOrder.sideOrderCount);
}
if(Beverage.beverageOrderCount!=0){
if (Soda.sodaCount != 0 || Choice == 7)
{
System.out.println(Soda.sodaCount + " Soda");
}
if (BottleWater.bottleWaterRCount != 0 || Choice == 8)
{
System.out.println(BottleWater.bottleWaterRCount + " Bottle of
Water");
}
System.out.println("Total Beverage Ordered
="+Beverage.beverageOrderCount);
}
System.out.println("Items ordered: " + ItemNum +" Items");
System.out.println("Subtotal: $" + (df.format(Total)));
System.out.println("NY Tax 8.78%: $" + (df.format(Tax)));
System.out.println("Total: $ " + (df.format(TotalFinal)));
System.out.println("\nThank you. Please come again!");
}
}