Question

In: Computer Science

Please complete a program that will be an order entry program for a store or organization....

Please complete a program that will be an order entry program for a store or

organization. The program will accept order entry input from two customers, calculate

the total order amount of each order and display data about each order to the

customer. There will be two orders, one will be a “delivery” order and the other will be a “pickup” order.

The data entered by each customer will be:

Customer name

Item purchased

Quantity purchased

Price of the item

The information displayed for each customer order will be:

Order Date (system generated)

Delivery Location (hardcoded in constructor)

Order Type (program supplied)

Item description

Price

Quantity

Order total (program calculates)

Delivery Charge (constant = $10.00)

You can follow these steps to guide you through the process.

1. Create a public class named Order.

2. The Order class will have instance variables for each object to hold data pertaining to each

object as needed (for the input from the customer, program calculated and system generated

values).

3. The Order class will have two constructors (both considered overloaded) of which will set the

current system date for the order as well as the delivery type (Hint: use the LocalDate class for

the date).

a. One constructor will accept a parameter for the address and will be called when a

delivery order is placed. It will set a delivery type instance variable value as “delivery”.

b. The second overloaded constructor will not require a parameter for the address when a

pickup order is placed. It will set a delivery type instance variable value as “pickup”.

4. Create a second public class named OrderCart.

5. Create a main() method within the OrderCart class that will do the following:

a. Display a greeting.

b. Instantiate two Order class objects one for “pickup” and one for “delivery”.

o The “delivery” class object will pass a delivery address argument to the constructor.

At this time, you should hard code an address into the call to the constructor to

keep it simple. (Decision structures are not needed and therefore not used for this

program).

o The “pickup” class object will not pass any delivery information to the constructor.

c. Prompts and accepts input from the user for the all of the instance variables (customer

name, item description, quantity and price).

d. Calls two overloaded methods named calculateOrderTotal() to calculate the order total of

each order (no sales tax is charged in this example). Each method accepts an “Order”

object as it’s parameter.

o One overloaded method will accept a delivery charge of $10.00 and will be used to

calculate the order total for the “delivery” order. The total should include the

delivery charge (total = price * quantity + delivery charge).

o The second overloaded method will not accept any delivery charges and will used

to calculate the order total for the “pickup” order. The total charge will not include

a delivery charge (total = price * quantity).

o

e. Calls two overloaded methods named displayOrderData() to output the data for each

order. Each method accepts an “Order” object as it’s parameter.

o One overloaded method will accept a delivery charge of $10.00 and will be used to

display the order details including the delivery charge.

o The second overloaded method will not accept any delivery charges and will used

display the order specifics.

Solutions

Expert Solution

Hi,

Hope you are doing fine. I have coded the above question in java keeping all the requirements in mind. Since there is no sample output given, I have written the output according to my convenience. You may change it as per your needs. The code hhas been clearly explained using comments that have been highlighted in bold.

Program:

Order.java

import java.time.LocalDate;

//class order
public class Order {
   //declaring all the attributes of the class as per the question
   String name;
   String item;
   int qty;
   //price is taken in float. You may also declare it as double
   float price;
   //using LocalDate to declare orderDate
   LocalDate orderDate;
   String address;
   String orderType;
   //total stores the total price of items
   float total;
  
   //no parameter constructor that sets orderType to "pickup" and sets orderDate to current date
   public Order() {
       this.orderType = "pickup";
       this.orderDate=LocalDate.now();
   }
  
   //parameterized constructor that sets address along with setting orderType to "delivery" and oderDate to current date
   public Order(String address) {
       this.address=address;
       this.orderType = "delivery";
       this.orderDate=LocalDate.now();
   }   

}

orderCart.java

//class orderCart
import java.util.Scanner;

public class OrderCart {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       //declaring scanner for input
       Scanner sc=new Scanner(System.in);
       //Welcome message
       System.out.println("Welcome to the store");
       //creating an object delivery for order class with the address as parameter
       Order delivery=new Order("Brooklyn street");
       //creating an object pickup for order class with no parameter constructor called
       Order pickup=new Order("Pickup");
       //Taking details of customer1 i.e delivery object
       System.out.println("Customer 1");
       System.out.println("Enter name: ");
       delivery.name=sc.next();
       System.out.println("Enter item purchased: ");
       delivery.item=sc.next();
       System.out.println("Enter the quantity: ");
       delivery.qty=sc.nextInt();
       System.out.println("Enter price of the item: ");
       delivery.price=sc.nextFloat();
       System.out.println();
       //Taking details of customer2 i.e pickup object
       System.out.println("Customer 2");
       System.out.println("Enter name: ");
       pickup.name=sc.next();
       System.out.println("Enter item purchased: ");
       pickup.item=sc.next();
       System.out.println("Enter the quantity: ");
       pickup.qty=sc.nextInt();
       System.out.println("Enter price of the item: ");
       pickup.price=sc.nextFloat();
       System.out.println();
      
       //calculating total using calculateOrderTotal() method
       float total_delivery,total_pickup;
       //calculating order total for delivery object by passing delivery charge as an additional parameter
       total_delivery=calculateOrderTotal(delivery,10.00);
       //calculating order total for pickup object
       total_pickup=calculateOrderTotal(pickup);
       //setting total attribute for each object
       delivery.total=total_delivery;
       pickup.total=total_pickup;
      
       //displaying info
       System.out.println("Info of customer 1: "+delivery.name);
       //display info of delivery object
       displayOrderData(delivery,10.00);
       System.out.println();
       //display info of pickup object
       System.out.println("Info of customer 2: "+pickup.name);
       displayOrderData(pickup);
   }

   //method to display details of objects of orderType "delivery"
   private static void displayOrderData(Order delivery, double d) {
       // TODO Auto-generated method stub
       System.out.println("Order date: "+delivery.orderDate);
       System.out.println("Delivery Location: "+delivery.address);
       System.out.println("Order type: "+delivery.orderType);
       System.out.println("Item description: "+delivery.item);
       System.out.println("Price: $"+delivery.price);
       System.out.println("Quantity: "+delivery.qty);
       System.out.println("Order total: $"+delivery.total);
       System.out.println("Delivery charge: $"+d);
      
   }

   //method to display details of objects of orderType "pickup"
   private static void displayOrderData(Order pickup) {
       // TODO Auto-generated method stub
       System.out.println("Order date: "+pickup.orderDate);
       System.out.println("Order type: "+pickup.orderType);
       System.out.println("Item description: "+pickup.item);
       System.out.println("Price: $"+pickup.price);
       System.out.println("Quantity: "+pickup.qty);
       System.out.println("Order total: $"+pickup.total);
      
   }

   //method to calculate order total of objects of orderType "pickup"
   private static float calculateOrderTotal(Order pickup) {
       // TODO Auto-generated method stub
       float total=pickup.price*pickup.qty;
       return total;
   }

   //method to calculate order total of objects of orderType "delivery"
   private static float calculateOrderTotal(Order delivery, double d) {
       // TODO Auto-generated method stub
       float total=delivery.price*delivery.qty+(float)d;
       return total;
   }

}

Executable code snippets:

Order.java

orderCart.java

Output:


Related Solutions

please complete the following program in c++: In this homework assignment you will modify the program...
please complete the following program in c++: In this homework assignment you will modify the program you have developed in Homework Assignment 1 by implementing the following: 1- Your program will ask the user to choose to either Compute and Display Surface Areas of Hemispheres and their Average (Choice 1) or to Compute and Display Volumes of Hemispheres and their Average (Choice 2). The program will only perform the chosen operation. (Hint: use a character variable to read the character...
Instructions Complete the program below. The program should be turned in as a .py file. Please...
Instructions Complete the program below. The program should be turned in as a .py file. Please turn in the .py file itself (do not take a picture of it or copy/paste it into another program). Please also turn in the output for your program. The output should be in a different file. You may find the easiest way is to take a screenshot of your output. You can use the snipping tool on Windows or the grab tool on a...
Write a C program that summarizes an order from a fictitious store. You must have these...
Write a C program that summarizes an order from a fictitious store. You must have these four lines in your program: float bike_cost, surfboard_cost; float tax_rate, tax_amount; int num_bikes, num_surfboards; float total_cost_bikes, total_cost_surfboards; float total_cost, total_amount_with_tax;
Write a C program that summarizes an order from a fictitious store. You must have these...
Write a C program that summarizes an order from a fictitious store. You must have these four lines in your program: float bike_cost, surfboard_cost; float tax_rate, tax_amount; int num_bikes, num_surfboards; float total_cost_bikes, total_cost_surfboards; float total_cost, total_amount_with_tax; You will assign your own unique values for each of the variables, except the totals which are computed. No other variables are needed in the program. For example, you will see the numbers I picked in my program in the sample output below. I...
C++ PLEASE IMPORTANT: The use of vectors is not allowed This program will store roster and...
C++ PLEASE IMPORTANT: The use of vectors is not allowed This program will store roster and rating information for a basketball team. Coaches rate players during tryouts to ensure a balanced team. A roster can include at most 10 players. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output...
Complete the program below in order to make run properly by competing validName methods and add...
Complete the program below in order to make run properly by competing validName methods and add trycatch block in the main method. public class ExceptionWithThrow { public static String validName(String name) throws InputMismatchException{ // check here if the name is a valid name // through InputMismatchException if invalid //throw // return the name if it is valid } public static void main(String[] args) { // Ask the user to enter a name and their validity through validName method // Add...
Develop an onboarding program for an organization. This program can be general to the organization, or...
Develop an onboarding program for an organization. This program can be general to the organization, or can be for a specific area, and for brand new employees or those transferring/promoted who are new to an area of the organization Brief explanation, and identify the intended recipients of the program Identify the components of a socialization program that will be ideal for your onboarding program. Be sure to keep in mind the following items: Stage Models of Socialization The Information Newcomers...
Select a system engineering organization, identify the entry level requirements for the organization, and develop a...
Select a system engineering organization, identify the entry level requirements for the organization, and develop a set of descriptions for an individual at each skill level: basic, intermediate, and supervisory.
Please write in C. This program will store roster and rating information for a soccer team....
Please write in C. This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (3 pts) ex Enter player 1's jersey number:...
Please write a java program that has the following methods in it: (preferably in order)   a...
Please write a java program that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled, and the total tuition Design Notes: The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT