Sample output:
Total number of shirts ordered: 10
Total price of all
shirts: $173.00
Total number of pants ordered: 10
Total price of all pants: $500.00
Average waist size: 42.0
Average inseam size: 32.0
please don't copy and paste an already posted solution
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Clothing.java
public class Clothing {
//Declaring instance variables
private int quantity;
private String color;
//Zero argumented constructor
public Clothing() {
this.quantity = 0;
this.color = "";
}
//Parameterized constructor
public Clothing(int quantity, String color) {
this.quantity = quantity;
this.color = color;
}
// getters and setters
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double calculatePrice()
{
return 0.0;
}
}
___________________________
// Shirt.java
public class Shirt extends Clothing {
//Declaring instance variables
private String size;
//Zero argumented constructor
public Shirt() {
this.size = "";
}
//Parameterized constructor
public Shirt(int quantity, String color, String size)
{
super(quantity, color);
this.size = size;
}
// getters and setters
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public double calculatePrice() {
double tot = 0;
if (size.equalsIgnoreCase("S"))
{
tot =
getQuantity() * 11.00;
} else if
(size.equalsIgnoreCase("M")) {
tot =
getQuantity() * 12.50;
} else if
(size.equalsIgnoreCase("L")) {
tot =
getQuantity() * 15.00;
} else if
(size.equalsIgnoreCase("XL")) {
tot =
getQuantity() * 16.50;
} else if
(size.equalsIgnoreCase("XXL")) {
tot =
getQuantity() * 18.50;
}
return tot;
}
}
____________________________
// Pants.java
public class Pants extends Clothing {
//Declaring instance variables
private int waist;
private int inseam;
//Zero argumented constructor
public Pants() {
this.waist = 0;
this.inseam = 0;
}
//Parameterized constructor
public Pants(int quantity, String color, int waist,
int inseam) {
super(quantity, color);
setWaist(waist);
setInseam(inseam);
}
// getters and setters
public int getWaist() {
return waist;
}
public void setWaist(int waist) {
if (waist > 0)
this.waist =
waist;
}
public int getInseam() {
return inseam;
}
public void setInseam(int inseam) {
if (inseam > 0)
this.inseam =
inseam;
}
public double calculatePrice() {
double tot = 0;
if (waist > 48 || inseam >
36) {
tot = 65.50 *
getQuantity();
} else {
tot = 50.0 *
getQuantity();
}
return tot;
}
}
___________________________
// Test.java
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
int totShirts=0,totPants=0;
double
sprice=0,pprice=0,totWaist=0,totinseam=0,avgWaist=0,avginseam=0;
int cnt=0;
ArrayList<Clothing>
clothes=new ArrayList<Clothing>();
Shirt s=new
Shirt(8,"Green","XXL");
Pants p1=new
Pants(6,"Brown",48,30);
Shirt s1=new
Shirt(2,"White","M");
Pants p2=new
Pants(4,"Blue",36,34);
clothes.add(s);
clothes.add(s1);
clothes.add(p1);
clothes.add(p2);
for(int
i=0;i<clothes.size();i++)
{
if(clothes.get(i) instanceof Shirt)
{
s1=(Shirt)clothes.get(i);
totShirts+=s1.getQuantity();
sprice+=s1.calculatePrice();
}
else
if(clothes.get(i) instanceof Pants)
{
Pants pa=(Pants)clothes.get(i);
totPants+=pa.getQuantity();
pprice+=pa.calculatePrice();
totinseam+=pa.getInseam();
totWaist+=pa.getWaist();
cnt++;
}
}
System.out.println("Total number of
shirts :"+totShirts);
System.out.println("Total price of
Shirts :"+sprice);
System.out.println("Total number of
Pants :"+totPants);
System.out.println("Total price of
Pants :"+pprice);
System.out.printf("Average waist size is
:%.1f\n",totWaist/cnt);
System.out.printf("Average inseam length is
:%.1f\n",totinseam/cnt);
}
}
______________________________
Output:
Total number of shirts :10
Total price of Shirts :173.0
Total number of Pants :10
Total price of Pants :500.0
Average waist size is :42.0
Average inseam length is :32.0
_______________Could you plz rate me well.Thank
You
Sample output: Total number of shirts ordered: 10 Total price of all shirts: $173.00 Total number of pants ordered: 10...
Write an equals method for the Shirt class provided below. Two shirts are logically equivalent if they have the same size, color, and price. public class Shirt { private Size size; private String color; private double price; enum Size { SMALL, MEDIUM, LARGE } public Shirt(Size size, String color, double price) { this.size = size; this.color = color; this.price = price; } public Size getSize() { return size; } public String getColor() { return color; } public double getPrice() {...
Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...
in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "RetailItem" class which simulates the sale of a retail item. It should have a constructor that accepts a "RetailItem" object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. Your class should have these methods: getSubtotal: returns the subtotal of the sale, which is quantity times price....
DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress, Cart and Main. ITEM CLASS Your Item class should contain: Attributes (protected) String name - name of the Item double price - price of the item Methods (public) void setName(String n) - sets the name of Item void setPrice(double p) - sets the price of Item String getName() - retrieves name double getPrice() - retrieves price String formattedOutput() returns a string containing detail of...
Order up:: Write a program that will be used to keep track of orders placed at a donut shop. There are two types of items that can be ordered: coffee or donuts. Your program will have a class for each order type, and an abstract superclass. Coffee orders are constructed with the following information: quantity (int) - how many coffees are being ordered size (String) - the size of the coffees (all coffees in the order have the same size)...
I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...
You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot be blank) double size (from 5 to 12) int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows 1. red 2. green 3. blue 4. black 5. grey One constructor, one get method per instance variable, one set method per instance variable. You will need a...
Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I cannot compile it. Could you please point out the error.The question is that This programming project extends Q1. Create a PizzaOrder class that allows up to three pizzas to be saved in an order. Each pizza saved should be a Pizza object as described in Q1. In addition to appropriate instance variables and constructors, add the following methods: public void setNumPizzas(int numPizzas)—sets the number...
Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.Given files: main.cpp - contains the main function for testing the program.Course.cpp - represents a course, which contains a vector of Student objects as a course roster. (Type your code in here)Course.h - header file for the Course class.Student.cpp - represents a classroom student, which has three data members: first name, last name, and...
Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...