Question

In: Computer Science

You will use your previous programming project as a starting point. Be sure to copy and...

You will use your previous programming project as a starting point. Be sure to copy and rename your file from that project and edit the internal documentation to reflect the new name and date.

Use your previous working Java program as a starting point (Project 3). Create another function that determines whether the customer should receive a discount. Assume your food truck gives a 10% discount on orders over $50 (the total BEFORE tax). If the order is eligible for a discount, then calculate and display the discount. If the order does not get a discount, then still display the discount, but it should be 0. Include a line before this that tells every customer that your business gives a 10% discount on all orders over $50 so they understand this part of their receipt.

And this was the project 3 to be used to write this program.

import java.util.Scanner;

public class Main

{

static double salesTax, amountDueWithTax, totalAmount, amountTendered, change;

static Scanner sc = new Scanner(System.in);

//get all the information about items ordered

public static int[] readData(String items[])

{

int num[] = new int[5];

for(int i=0; i<5; i++)

{

System.out.print("Enter quantity of " + items[i] + " : ");

//get all the information about items ordered and the amount of money tendered as mentioned in ques

num[i] = sc.nextInt();

}

return num;

}

//method to calculate amount with tax

public static void getAmountWithTax(int num[], double rate[], double amount[])

{

double totalAmount = 0;

//find the amount for all items and totalAmount

for(int i=0; i<5; i++)

{

amount[i] = num[i]*rate[i];

totalAmount = totalAmount + amount[i];

}

//find salesTax, amountDueWithTax

salesTax = totalAmount*0.06;

amountDueWithTax = totalAmount + salesTax;

}

//method to print the receipt

public static void printInfo(int num[], String items[], double rate[], double amount[])

{

System.out.println("Thank you for visiting Roronoa Pizza Place!"); //print the title and Address

System.out.println("109th Avenue, Mount Olympia");

System.out.println("Your Order Was");

for(int i=0; i<5; i++)

System.out.printf("%d %s @ %.4f each: $%.4f\n",num[i], items[i], rate[i] ,amount[i]);

System.out.printf("Amount due for pizzas and drinks is: $%.4f\n", totalAmount);

System.out.printf("Sales tax amount is: $%.4f\n", salesTax);

System.out.printf("Total amount due, including tax is: $%.4f\n", amountDueWithTax);

System.out.printf("Amount tendered: $%.3f\n", amountTendered);

System.out.printf("Change: $%.4f\n", change);

}

//main method

public static void main(String[] args)

{

double rate[] ={8.99, 1.5, 12.99, 2.5, 1.5};

double amount[] = new double[5];

String items[] = {"Small pizzas", "Small pizza toppings", "Large pizzas", "Large pizza toppings", "Soft Drinks" };

///get all the information about items ordered

int num[] = readData(items);

//calculate amountDueWithTax

getAmountWithTax(num, rate, amount);

do{

System.out.print("Enter Amount tendered : ");

amountTendered = sc.nextDouble();

if(amountTendered >= amountDueWithTax)

break;

System.out.println ("Money given is not enough!Try again");

}while(true);

//calculate the change

change = amountTendered - amountDueWithTax;

//print the receipt

printInfo(num, items, rate, amount);

}

}

Solutions

Expert Solution


import java.util.Scanner;
public class Main
{

     static double salesTax, amountDueWithTax, totalAmount, amountTendered, change;
     static Scanner sc = new Scanner(System.in);
     //get all the information about items ordered
     public static int[] readData(String items[])
     {
           int num[] = new int[5];
           for(int i=0; i<5; i++)
           {
              System.out.print("Enter quantity of " + items[i] + " : ");
              //get all the information about items ordered and the amount of money tendered as mentioned in ques
              num[i] = sc.nextInt();
           }
           return num;
     }
    //Method to calculate and return discount
    public static double getDiscount(int num[], double rate[], double amount[])
    {
         double tempAmount = 0,discount=0;
         //find the amount for all items and totalAmount
         for(int i=0; i<5; i++)
         {
            
            tempAmount = tempAmount + num[i]*rate[i];
         }
        //10% discount on order over $50
       if(tempAmount>50)
       {
          discount=0.1*tempAmount;
          
       }
       //if the order is not eligible for discount,then it becomes zero
      else
       {
         discount=0;
         
       }
       return discount;
    }
    //method to calculate amount with tax
    // discount variable passes as a parameter,So that the totalAmount can be calculate...
    public static void getAmountWithTax(int num[], double rate[], double amount[],double discount)
    {
         double totalAmount = 0;
         //find the amount for all items and totalAmount
         for(int i=0; i<5; i++)
         {
            amount[i] = num[i]*rate[i];
            totalAmount = totalAmount + amount[i];
         }
         if(discount>0)
         {
                totalAmount=totalAmount-discount;
                
         }
         System.out.print("Total Amount"+totalAmount);
         //find salesTax, amountDueWithTax
         salesTax = totalAmount*0.06;
         amountDueWithTax = totalAmount + salesTax;
    }
    //method to print the receipt
    public static void printInfo(int num[], String items[], double rate[], double amount[])
    {
        System.out.println("Thank you for visiting Roronoa Pizza Place!"); //print the title and Address
        System.out.println("109th Avenue, Mount Olympia");
        System.out.println("Your Order Was");
        for(int i=0; i<5; i++)
        System.out.printf("%d %s @ %.4f each: $%.4f\n",num[i], items[i], rate[i] ,amount[i]);
        System.out.printf("Amount due for pizzas and drinks is: $%.4f\n", totalAmount);
        System.out.printf("Sales tax amount is: $%.4f\n", salesTax);
        System.out.printf("Total amount due, including tax is: $%.4f\n", amountDueWithTax);
        System.out.printf("Amount tendered: $%.3f\n", amountTendered);
        System.out.printf("Change: $%.4f\n", change);
    }
    //main method
    public static void main(String[] args)
    {
         double rate[] ={8.99, 1.5, 12.99, 2.5, 1.5};
         double amount[] = new double[5];
         String items[] = {"Small pizzas", "Small pizza toppings", "Large pizzas", "Large pizza toppings", "Soft Drinks" };
         ///get all the information about items ordered
         int num[] = readData(items);
        //calculate amountDueWithTax
        double d=getDiscount(num, rate, amount);
        System.out.print("Your discount is : "+d);
        getAmountWithTax(num, rate, amount,d);
        do{
              System.out.print("Enter Amount tendered : ");
              amountTendered = sc.nextDouble();
              if(amountTendered >= amountDueWithTax)
                break;
              System.out.println ("Money given is not enough!Try again");
          }while(true);
        //calculate the change
        change = amountTendered - amountDueWithTax;
        //print the receipt
        printInfo(num, items, rate, amount);
     }

}

Related Solutions

For this programming assignment, you will use your previous code that implemented a video game class...
For this programming assignment, you will use your previous code that implemented a video game class and objects with constructors. Add error checking to all your constructors, except the default constructor which does not require it. Make sure that the high score and number of times played is zero or greater (no negative values permitted). Also modify your set methods to do the same error checking. Finally add error checking to any input requested from the user. #include <iostream> #include...
THONNY: This project focusses on dealing with strings of text. The starting point for this is...
THONNY: This project focusses on dealing with strings of text. The starting point for this is a variable, ‘text’, that contains a random collection of words. The aim of this assignment is to iterate over the words and find the length of the longest word. text = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus facilisis consequat. " "Nam ultricies quis dolor vitae placerat. Integer in ante sit amet eros egestas porttitor. Phasellus " "semper lectus dapibus volutpat...
You are required to make a copy of the tax return that Celia Brown, the previous...
You are required to make a copy of the tax return that Celia Brown, the previous controller, prepared, and then begin comparing the tax return to the draft of the company's financial statements. You prepare the following schedule for this year: Panache, Inc. Book/Tax Differences 2014 Description Financial Statement Amount Tax Return Amount Depreciation $48,000 $40,000 Officers’ life insurance premiums $15,000 0 Interest revenue on municipal bonds $25,000 0 Product warranty costs $27,000 $20,000 Gross profit on installment sales $91,000...
In this programming project, you will be implementing the data structure min-heap. You should use the...
In this programming project, you will be implementing the data structure min-heap. You should use the C++ programming language, not any other programming language. Also, your program should be based on the g++ compiler on general.asu.edu. All programs will be compiled and graded on general.asu.edu, a Linux based machine. If you program does not work on that machine, you will receive no credit for this assignment. You will need to submit it electronically at the blackboard, in one zip file,...
This week, you will create and implement an object-oriented programming design for your project. You will...
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it. Submit a screen shot from Visual Studio with your explanation into a Word...
Starting out with Python 4th edition Chapter 2 Programming Exercise 12 Stock Transaction Program Not sure...
Starting out with Python 4th edition Chapter 2 Programming Exercise 12 Stock Transaction Program Not sure how to do this
Sally-Anne is considering starting a business and is not sure what type of structure to use....
Sally-Anne is considering starting a business and is not sure what type of structure to use. She estimates that the annual turnover for the 2020 tax year will be $525,000 and the (taxable) net profit will be $183,000. Both Sally-Anne and her husband have private health insurance. Calculate (showing workings) the tax she would have to pay if she sets up the business as: a. A sole trader (no other income) b. A partnership 50/50 with her husband (neither earn...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
Pls leave if you are not sure about the answer, and do not copy from the...
Pls leave if you are not sure about the answer, and do not copy from the chegg, pls explain A and C througly. Happy Feet Inc. manufactures and sells three types of shoes. The income statements prepared under the absorption costing method for the three shoes are as follows: Happy Feet Inc. Product Income Statements -- Absorption Costing For the Year Ended December 31, 2016 1 Cross Training Shoes Golf Shoes Running Shoes 2 Revenues $830,000.00 $720,000.00 $640,000.00 3 Cost...
Use Minitab to answer the questions. Make sure to copy all output from the Minitab: The...
Use Minitab to answer the questions. Make sure to copy all output from the Minitab: The U.S. Bureau of Labor Statistics publishes a variety of unemployment statistics, including the number of individuals who are unemployed and the mean length of time the individuals have been unemployed. For November 1998, the Bureau of Labor Statistics reported that the national mean length of time of unemployment was 14.5 weeks. The mayor of Chicago has requested the study on the status of unemployment...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT