1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Over [174]
3 years ago
7

This is a program that calculates information about orders of shirts and pants. All orders have a quantity and a color. Write a

Clothing class that matches this UML: The no-argument constructor will set the quantity to zero and the color to the empty string. The calculatePrice() method returns 0.0. The two-argument constructor and the setQuantity() method must ensure that the quantity will be greater than or equal to zero. Hint: use Math.abs()
Computers and Technology
1 answer:
LuckyWell [14K]3 years ago
4 0

Answer:

Check the explanation

Explanation:

// 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;

}

}

_____________________________

// 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;

} else {

tot = 50.0;

}

return tot;

}

}

__________________________

// 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;

}

}

___________________________

//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);

Pants p2=new Pants(4,"Blue",36,34);

clothes.add(s);

clothes.add(p1);

clothes.add(p2);

for(int i=0;i<clothes.size();i++)

{

if(clothes.get(i) instanceof Shirt)

{

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 :8

Total price of Shirts :148.0

Total number of Pants :10

Total price of Pants :100.0

Average waist size is :42.0

Average inseam length is :32.0

You might be interested in
Containers for contaminated sharps must have several characteristics. What’s missing from the list? PuContainers for contaminate
Nadya [2.5K]
All sharps containers must be stored upright,be puncture-resistant, be labeled or color-coded red & leakproof on both the sides & the bottom! The last one is the one missing!
4 0
3 years ago
Read 2 more answers
Technician A says that high pressure in recycled refrigerant is only caused by air contamination. Technician B says that recycle
hjlf

Answer:

a. A only

Explanation:

When air, is in excess of allowable amounts, it  can cause the system to operate at pressures that are higher than normal. This means that the recycled refrigerant is operating at high pressure. Thus Technician A is correct.

However, Technician B is incorrect because unlike reclaimed refrigerants where the process strip the refrigerant of impurities making it to meet the standards of a new refrigerant, the recycled refrigerant is not as pure as it's contaminants are only reduced.

Therefore, only technician A is correct.

6 0
3 years ago
Carlie was asked to review a software project for her company to determine specific deadlines. Which part of project management
Elis [28]

Answer:

Resources

Explanation:

Carlie certainly requires to review the resources. It is important to find out how many software engineers, testers, etc. are available. And only then Carlie can find out the exact deadlines as required here. And hence, she must have look at the resources while determining the specific deadlines. Hence, resources are the correct option.

3 0
3 years ago
Read 2 more answers
Who tryna trade in gta my psn is xMadOrNawx-_-
barxatty [35]
Ok I’ll add you to day
5 0
2 years ago
Read 2 more answers
List and discuss five economic growth indicators
patriot [66]
Strong employment numbers. To see economic growth there needs to be an increase in Gross Domestic Product (GDP). ...
Stable Inflation. ...
Interest rates are rising. ...
Wage Growth. ...
High Retail Sales. ...
Higher New Home Sales. ...
Higher Industrial Production.
5 0
1 year ago
Other questions:
  • Which type of loop only runs while a condition is true?
    11·2 answers
  • What does in-private or incognito browsing do?
    5·1 answer
  • What will be the output of the following Python code? class A: def test1(self): print(" test of A called ") class B(A): def test
    15·1 answer
  • g Define memory hierarchy. A. The rate at which information can be transferred from one place to another. B. Ordering storage sy
    8·1 answer
  • The data in a database management system that identifies the names of​ tables, fields in each​ table, and the properties of each
    13·2 answers
  • Which of the following statements opens the file info.txt for both input and output? a) dataFile.open("info.txt", ios::in &amp;&
    11·2 answers
  • State the difference between = and ==
    9·1 answer
  • Is the most important characteristic of a hard drive.​
    7·2 answers
  • Please answer me <br> in Assignment - Algorithms
    10·1 answer
  • CLS
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!