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
Which file format produces a lock-down version of an access database? accdb accdb-be accde accdb-e
jek_recluse [69]

The file format that produces a lock-down version of an access database is called; ACCDE

<h3>How to Identify Access Database?</h3>

ACCDB files are the default Microsoft Access database format in Access 2007 and later versions while the ACCDE format is a read-only, compressed version.

Now, the file format that produces a lock down version of an access database is called ACCDE file which is a Microsoft Access Execute Only Database file used to protect an ACCDB file.

Read more about Access Database at; brainly.com/question/9745438

#SPJ1

8 0
1 year ago
How does this happen on brainly????
Trava [24]

what do you mean????

4 0
2 years ago
Read 2 more answers
Look at the slide.
svetlana [45]

Answer:

c

Explanation:

5 0
2 years ago
Read 2 more answers
What is the space complexity of the algorithm?ArithmeticSeries(list, listSize) { i = 0 arithmeticSum = 0 while (i &lt; listSize)
blondinia [14]

Answer:

O(n) which is a linear space complexity

Explanation:

Space complexity is the amount of memory space needed for a program code to be executed and return results. Space complexity depends on the input space and the auxiliary space used by the algorithm.

The list or array is an integer array of 'n' items, with the memory size 4*n, which is the memory size of an integer multiplied by the number of items in the list. The listSize,  i, and arithmeticSum are all integers, the memory space is 4(3) = 12. The return statement passes the content of the arithmetic variable to another variable of space 4.

The total space complexity of the algorithm is "4n + 16" which is a linear space complexity.

7 0
2 years ago
What purpose would tracking changes be most useful for?
olya-2409 [2.1K]
So, you can be able to make a prediction and understand the cycle.
6 0
3 years ago
Other questions:
  • Write a program that accepts three decimal numbers as input and outputs their sums?​
    5·1 answer
  • Convert the decimal integer, 353.87510 to each of these forms:
    9·1 answer
  • Which cable standard is a standard for newer digital cable, satellite, and cable modem connections?
    11·1 answer
  • What is the different between information and data
    9·1 answer
  • Write a list comprehension statement to generate a list of all pairs of odd posi
    7·1 answer
  • Is spin to win paying or is a scam app​
    6·2 answers
  • State five differences between Dos and Windows.​
    14·1 answer
  • What is the difference between a LAN and WAN? how do these two networks interact?​
    14·1 answer
  • To break a text string into several lines, which means that the text string continues on the next line, the _____ character shou
    8·1 answer
  • What are the different types of computer operating systems?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!