Right now I just need the Pseudocode for this This is using
Right now I just need the Pseudocode for this
This is using Java
Objectives: Create base classes and derive new classes using inheritance. Utilize multiple classes in the same
program.
Problem: Disneyland has begun a service that allows guests at the park to pre-order drinks and pick them up at a designated time so as to avoid long concession lines. Guests that spend more than $150 (cumulatively) become preferred customers and are awarded discounts on future orders. A program is needed to track the amount spent by each customer and promote them to preferred customer when they have accumulated $150 in purchases.
Classes:
Customer (base class)
o Members
First name
Last name
Guest ID
Amount spent
o Methods
Overloaded Constructor
Accessors
Mutators
Preferred Customer (derived class)
o Member
Discount Percentage
o Methods
Overloaded Constructor (chained w/ base class constructors)
Accessor
Mutator
Details:
The price of the drink is determined by the type of drink and the amount of ounces ordered o The number of ounces ordered and the price per ounce will be given for each order
Each drink will come in a cylindrical container
The container can be personalized with different Disney graphics
The total price of the personalization is determined by the price per square inch of the container
o The radius, height and price per square inch will be given for each input
Preferred customer information and regular customer information will be stored in files and will be read
into memory before the program processes orders.
o Note that the files may be empty or may not exist.
o In both cases, the respective customer array should not be created until a customer reaches
preferred status.
Regular customers and preferred customers will be held in 2 separate arrays.
The arrays are to be no larger than the actual number of members in each category.
Orders will be read from a file.
After processing an order, if a customer has accumulated $150 or more, promote the customer to
preferred status.
o The preferred customer array will be resized to add one more element.
o Add the new preferred customer into the open element at the end of the preferred customer
array.
o Resize the regular customer array and remove the customer data that was promoted to preferred
status.
Preferred customers get a discount based on how much they have spent overall
o $150 = 5% discount o $200 = 7% discount o $350 = 10% discount
Input: Input data will be stored in three files: preferred.dat, customers.dat and orders.dat. The total number of lines in each file will be unknown.
Preferred.dat will hold the data for known preferred customers and customers.dat will hold the data for known regular customers. Both files should be read at the beginning of the program to establish the preferred customer and regular customer arrays respectively. The files may be empty or may not exist. In such cases, there should not be a respective customer array created before reading the orders.
Each line of preferred.dat will be formatted as follows (except for the last line of the file which will not have a newline character). The data will be listed in the following order on each line with a space between each field. There will be no invalid data on any line.
customer ID
first name
last name
amount spent
discount newline
Each line of customer.dat will be formatted as follows (except for the last line of the file which will not have a newline character). The data will be listed in the following order on each line with a space between each field. There will be no invalid data on any line.
customer ID
first name
last name
amount spent
newline
Orders.dat will hold all orders to process. Each line of the file will be formatted as follows (except for the last line of the file which will not have a newline character). The data will be listed in the following order on each line with a space between each field. There will be no invalid data on any line.
customer ID
container radius
container height
ounces
ounce price
square inch price
quantity
newline
Foreachorder,themainthingtonoteisthetotalcostanditsconnectiontotheappropriatecustomer. Thetotal cost will be added to the amount spent for each customer. If the customer has preferred status, the discounted price will be added to the amount spent. After the amount spent has been updated, check to see if the customer has gained preferred status or if the preferred customer qualifies for a larger discount.
When moving a regular customer to the preferred customer array, always add the data to the end of the array. When removing the customer from the regular customer array, shift the elements toward the front of the array. Do not rearrange the order of the data in either array. Remember that each array should be no bigger than the number if elements it needs to hold.
Output: At the end of the program, write the regular customer data and preferred customer data to the respective files. Use the proper format as listed above in the Input section. There will be no output to the screen.
Solution
public class Customer {
protected String firstName;
protected String lastName;
protected String guestId;
protected double amountSpent;
public Customer() {
firstName = null;
lastName = null;
guestId = null;
amountSpent = 0;
}
public Customer(String firstName, String lastName, String guestId,
double amountSpent) {
this.firstName = firstName;
this.lastName = lastName;
this.guestId = guestId;
this.amountSpent = amountSpent;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getGuestId() {
return guestId;
}
public void setGuestId(String guestId) {
this.guestId = guestId;
}
public double getAmountSpent() {
return amountSpent;
}
public void setAmountSpent(double amountSpent) {
this.amountSpent = amountSpent;
}
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(amountSpent);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result
+ ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result + ((guestId == null) ? 0 : guestId.hashCode());
result = prime * result
+ ((lastName == null) ? 0 : lastName.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Customer other = (Customer) obj;
if (Double.doubleToLongBits(amountSpent) != Double
.doubleToLongBits(other.amountSpent))
return false;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (guestId == null) {
if (other.guestId != null)
return false;
} else if (!guestId.equals(other.guestId))
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
return true;
}
public String toString() {
return \"Members [firstName=\" + firstName + \", lastName=\" + lastName
+ \", guestId=\" + guestId + \", amountSpent=\" + amountSpent + \"]\";
}
}
public class PreferredCustomer extends Customer {
protected double discountPercentage;
public PreferredCustomer(String firstName, String lastName, String guestId,
double amountSpent, double discountPercentage) {
super(firstName, lastName, guestId, amountSpent);
this.discountPercentage = discountPercentage;
}
public double getDiscountPercentage() {
return discountPercentage;
}
public void setDiscountPercentage(double discountPercentage) {
this.discountPercentage = discountPercentage;
}
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
long temp;
temp = Double.doubleToLongBits(discountPercentage);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
PreferredCustomer other = (PreferredCustomer) obj;
if (Double.doubleToLongBits(discountPercentage) != Double
.doubleToLongBits(other.discountPercentage))
return false;
return true;
}
public String toString() {
return \"PreferredCustomer [discountPercentage=\" + discountPercentage
+ \", firstName=\" + firstName + \", lastName=\" + lastName
+ \", guestId=\" + guestId + \", amountSpent=\" + amountSpent + \"]\";
}
}
public class Container {
protected double radius;
protected double height;
protected double pricePerSquare;
public Container(double radius, double height, double pricePerSquare) {
this.radius = radius;
this.height = height;
this.pricePerSquare = pricePerSquare;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getPricePerSquare() {
return pricePerSquare;
}
public void setPricePerSquare(double pricePerSquare) {
this.pricePerSquare = pricePerSquare;
}
}
public class Drink {
protected String name;
public Drink(String name) {
this.name = name;
}
}
import java.util.Scanner;
public class Order {
protected int noOfOunces;
protected Drink drink;
protected Container container;
protected double totalAmount;
public Order() {
noOfOunces = 0;
totalAmount = 0;
}
public Order(Drink drink, Container container) {
this.drink = drink;
this.container = container;
}
public int getNoOfOunces() {
return noOfOunces;
}
public void setNoOfOunces(int noOfOunces) {
this.noOfOunces = noOfOunces;
}
public Drink getDrink() {
return drink;
}
public void setDrink(Drink drink) {
this.drink = drink;
}
public Container getContainer() {
return container;
}
public void setContainer(Container container) {
this.container = container;
}
public double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(double totalAmount) {
this.totalAmount = totalAmount;
}
public double totalOrder() {
Scanner scanner = new Scanner(System.in);
System.out.println(\"enter the what type of drink you want\");
String drinkName = scanner.next();
System.out.println(\"how many ounces you want\");
int ounces = scanner.nextInt();
System.out.println(\"enter the cost of the ounce\");
double ounceprice = scanner.nextDouble();
double price = ounces * ounceprice;
// totalOrder=totalOrder+price;
System.out.println(\"do you want container or not type yes/no\");
String choice = scanner.next();
if (choice.trim().equals(\"yes\")) {
System.out.println(\"enter the radius of the container\");
double radius = scanner.nextDouble();
System.out.println(\"enter the height of the container\");
double height = scanner.nextDouble();
System.out
.println(\" enter no of square per inches of the container\");
int noOfSquareInches = scanner.nextInt();
System.out.println(\"enter the price of the each square\");
double pricePerSquare = scanner.nextDouble();
Container container = new Container(radius, height, pricePerSquare);
totalAmount = price + (pricePerSquare * noOfSquareInches);
setTotalAmount(totalAmount);
return totalAmount;
} else {
totalAmount = price;
setTotalAmount(totalAmount);
return totalAmount;
}
}
}
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
private static Scanner scanner = null;
private static List<Customer> customerList = new ArrayList<Customer>();
private static List<Customer> preferredCustomerList = new ArrayList<Customer>();
public static void main(String[] args) throws FileNotFoundException {
scanner = new Scanner(System.in);
System.out.println(\"enter the first name\");
String fname = scanner.next();
System.out.println(\"enter the last name\");
String lname = scanner.next();
System.out.println(\"enter the guest id\");
String guestId = scanner.next();
System.out.println();
Order order = new Order();
double totalAmount = order.totalOrder();
if (totalAmount >= 150)
{
System.out.println(\"enter the discount percentage\");
double discountPercentage = scanner.nextDouble();
Customer preCustomer = new PreferredCustomer(fname, lname, guestId,
order.getTotalAmount(), discountPercentage);
preferredCustomerList.add(preCustomer);
} else {
Customer customer = new Customer(fname, lname, guestId,
order.totalAmount);
customerList.add(customer);
}
displayCustomers();
}
private static void displayCustomers() {
for (Customer c : customerList) {
System.out.println(c);
}
for (Customer c : preferredCustomerList) {
System.out.println(c);
}
}
}
output
enter the first name
mark
enter the last name
smith
enter the guest id
256
enter the what type of drink you want
soda
how many ounces you want
5
enter the cost of the ounce
23
do you want container or not type yes/no
yes
enter the radius of the container
25
enter the height of the container
25
enter no of square per inches of the container
25
enter the price of the each square
25
enter the discount percentage
2
PreferredCustomer [discountPercentage=2.0, firstName=fg, lastName=gd, guestId=256, amountSpent=740.0]








