Created
May 20, 2020 03:59
-
-
Save minor/4396628c873623a808fa26995b2c1ec2 to your computer and use it in GitHub Desktop.
Orders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Saurish Srivastava: May 19 2020: Purpose of the program: calculates information about orders of shirts and pants. All orders have a quantity and a color.*/ | |
package com.finalexam; | |
import java.util.ArrayList; | |
public class Orders { | |
public static void main(String[] args) { | |
/* Define variables and ArrayList */ | |
int numberOfShirts = 0; | |
int numberOfPants = 0; | |
int waistTotal = 0; | |
int inseamTotal = 0; | |
double priceShirt = 0; | |
double pricePants = 0; | |
ArrayList<Clothing> list = new ArrayList<>(); | |
/* Add the objects */ | |
list.add(new Shirt(8, "Green", "XXL")); | |
list.add(new Pants(6, "Brown", 48, 30)); | |
list.add(new Shirt(2, "White", "M")); | |
list.add(new Pants(4, "Blue", 36, 34)); | |
/* For loop to go through the ArrayList */ | |
for (int i = 0; i < list.size(); i++) { | |
if(list.get(i) instanceof Shirt) { | |
Shirt newshirt = (Shirt) list.get(i); | |
numberOfShirts += newshirt.getQuantity(); | |
priceShirt += (newshirt.getQuantity() * newshirt.calculatePrice()); | |
} | |
else if (list.get(i) instanceof Pants) { | |
Pants newpants = (Pants) list.get(i); | |
numberOfPants += newpants.getQuantity(); | |
waistTotal += newpants.getQuantity() * newpants.getWaist(); | |
inseamTotal += newpants.getQuantity() * newpants.getInseam(); | |
pricePants += newpants.getQuantity() * newpants.calculatePrice(); | |
} | |
} | |
/* Calculate averageWaist and averageInseam and total price of ALL products */ | |
double averageWaist = waistTotal / numberOfPants; | |
double averageInseam = inseamTotal / numberOfPants; | |
double totalPrice = priceShirt + pricePants; | |
/* Final Print */ | |
System.out.println("The total number of shirts ordered are: " + numberOfShirts + " and came out to be $" + String.format("%.2f", priceShirt) + "."); | |
System.out.println("The total number of pants ordered are: " + numberOfPants + " and came out to be $" + String.format("%.2f", pricePants) + "."); | |
System.out.println("Total Price: $" + String.format("%.2f", totalPrice)); | |
System.out.println("The average waist size is: " + numberOfShirts + "."); | |
System.out.println("The average inseam size is: " + numberOfShirts + "."); | |
} | |
} | |
/** Thank you Professor for teaching this course. Could you also please regrade the assignment? It is still showing up as a 12/15 for me. | |
* I made no changes to the program and the screenshot is exactly what I got. THANKS!**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment