Question

In: Computer Science

Good Evening Guys, It was given an assignment in which I have to implement iava object...

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!");

       }

}

Solutions

Expert Solution

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!");
}
}


Related Solutions

Hi Guys, The assignment in Process Scheduling Operating System to write C code that implement FCFS...
Hi Guys, The assignment in Process Scheduling Operating System to write C code that implement FCFS & Round-Robin ( Without using any array) but we can use linkedlist
Good evening! I have synthetized benzocaine by Fischer esterification of para-aminobenzoic acid with ethanol and concentrated...
Good evening! I have synthetized benzocaine by Fischer esterification of para-aminobenzoic acid with ethanol and concentrated H2SO4 . Product was collected by vacuum filtration and tested for melting point. Results is 79-81 while literature value is 88-90. Also Yield was 59%. Could you please describe the way how this compound could be purified further (in detail please if it possible) Many thanks!
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I cannot find the solution for. It involves expressions with Infix I'll need a Java Program to convert an expression, eg. 3+6*(x-y)+x^2 to ((3 + (6 * (x-y))) + (x ^ 2)) Kindly assist. Thanks
I'm in a computer science course and I have an assignment that asks me to implement...
I'm in a computer science course and I have an assignment that asks me to implement a CPU scheduler in Java. Here are some details for the task: The program should ask for the number of processes. Then the program will ask for burst and arrival times for each process. Using that information, the program should schedule the processes using the following scheduling algorithms: First Come First Serve (FCFS) Shortest Jobs First (SJF) Shortest Remaining Time First (SRTF) The output...
Good evening, below there is a poem I need a summary of 5 sentences from the...
Good evening, below there is a poem I need a summary of 5 sentences from the below poem. Thank you [Stanza 1] So you want... to get a degree Why? Let me tell you what society will tell you: Increases your chances of getting a job, Provides you an opportunity to be successful, Be a lot less stressful, Education is the key. [Stanza 2] Now let me tell you something your parents will tell you: Make me proud, Increases your...
I am an enginnering student and I have been given an assignment on how to model...
I am an enginnering student and I have been given an assignment on how to model a stormwater management system. Can you please provide me with some help and the steps necessary to complete the assignment A simple example of a drawing would be much appreciated. I have all information on porosity and permeability of the materials through which the rainwater will pass through. State also any assumption that can be made to facilitate this task.
this is a workplace skill assignment. You have been promoted to Evening Team Lead at a...
this is a workplace skill assignment. You have been promoted to Evening Team Lead at a data center. You have reviewed the current infrastructure to ensure that operational procedures, maintenance and support of critical systems are in place.    You feel you have a well-trained, responsible staff in place and are confident that they are providing high quality operational support. If you could do anything, you would add more support staff to the team. Although you are getting by, you...
So this is my assignment. My question is, what makes an object a good insulator? Does...
So this is my assignment. My question is, what makes an object a good insulator? Does having a high specific heat alone make a good insulator? Water has a very high specific heat, would it make a good insulator for the material? Please list off a bunch of common household items with why they are good insulators! Objective: Construct an insulated device that is designed to retain heat. Heated water will be put into a beaker and the beaker will...
Given the following statements, which describe best an object with increasing kinetic energy? I. A ball...
Given the following statements, which describe best an object with increasing kinetic energy? I. A ball dropped from 10 meters II. A ball thrown vertically upwards III. A tennis ball rolling across the court
Assignment Question(s): Q1- A company wants to implement good internal control. What are the policies and...
Assignment Question(s): Q1- A company wants to implement good internal control. What are the policies and procedures you can suggest to minimize human frauds and errors? Q2- Assume that you have a company. And the management team estimates that 3% of sales will be uncollectible. Give any amount of sales and prepare the journal entry using the percent of sales method. Q3- A company that uses a perpetual inventory system made the following cash purchases and sales. There was no...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT