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
What is the best anime of all time?​
Blizzard [7]

(My opinion)  Naruto! (then Boruto is on it's way to becoming good)

but other people might say my hero academia or any of the dragon ball saga

4 0
3 years ago
In what service does the customer order,pickup, and pay at the desk
Crank

Answer:

monye

Explanation:

cash or credit becuse with what else are they gonna pay with

8 0
3 years ago
What is the correct sequence of the phases in the systems development life cycle?
HACTEHA [7]
1. Requirements gathering/analysis.
2. Design.
3. Development.
4. Testing.
5. Maintenance.
7 0
3 years ago
Select the correct answer.
DochEvi [55]

Answer:

ask customers to use strong passwords to protect their accounts

6 0
3 years ago
Read 2 more answers
What is a many-to many types of correspondence?
Ann [662]

Answer:

We have many types of correspondences. There are internal correspondences, external correspondences, sales correspondences, and personalized correspondences. By many to many correspondences we mean, a lot of people correspond with a lot many people from another department, company or market, or any set of people in fact. An internal correspondences, sales correspondences, personalized correspondences or external correspondences can be of many to many types, and as well as of others like one to one, many to one and so on.

Explanation:

Please check the answer.

5 0
3 years ago
Other questions:
  • 4
    10·1 answer
  • ) How many switching functions of two variables (x and y) are there?
    11·1 answer
  • The term "Cloud" refers to what option(s) below? (Select all that apply)
    13·1 answer
  • For your biology class, you have taken a number of measurements for a plant growth experiment. You wish to create a chart that s
    10·1 answer
  • Which of the following is most likely to be considered plagiarism? Using materials from a source without proper citation. Adding
    5·1 answer
  • An exclusion contract A. gives a firm the right to be the exclusive provider of a good in a particular market. B. is a form of e
    13·1 answer
  • Define a function called 'findWordFreq, which takes two parameters. The first parameter, 'text" is an nltk.text.Text object and
    8·1 answer
  • 15 points: Which type of system is used to capture and leverage the decision-making abilities of human experts?
    5·1 answer
  • For this activity, you will practice being both proactive and reactive to bugs. Both are necessary to get rid of errors in code.
    5·1 answer
  • The pci express version 4.0 can provide up to what amount of throughput with 16 lanes for data?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!