Question

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

Now write a class called Orders, which will contain your mainO method. The mainO method will assign orders of clothing to an

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

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 Clothing + quantity: int color: String + Clothingo +Cothing(quantity: int, color: string) +getQuantity0: int +setQuantity(quantiy: int): void +getColorO: String +setColor(color: string): vaid + calculatePrice0: double Now write a Shirt class that extends Clothing: Shirts have a size, which can be "S", "M", "L, XL-, or "XXL" (small, medium, large, extra large, and double extra large). The no-argument constructor sets the size to the empty string. The Shirt size: String +Shirt0 + Shint(quantity: int, colar: string, size: string) calculatePrice() method calculates the price +getSize0: String +setSize(size:String: void +calculatePrice0: double of a shirt as $11.00 for small, $12.50 for medium, S15.00 for large, $16.50 for extra large, and $18.50 for double extra large. Then, write a Pants class that extends Clothing: The no-argument constructor sets waist and inseam to zero. The four-argument constructor must ensure that waist and inseam are greater tharn zero. (Hint: absolute value.) The mutators leave the value unchanged if given a number less than or equal to zero. Pants + waist: int +inseam: int + Pants0 + Pants(quantity: int, color. string, waist int, inseam: int) The calculatePrice() method retums $50.00 unless the waist is greater than 48 or the inseam is greater than 36, in which case the price is $65.50 + getWaistO: int +setWaist(waist: int): void + getinseam0: int +setinseam(inseam: int): void +calculatePrice0: double
Now write a class called Orders, which will contain your mainO method. The mainO method will assign orders of clothing to an ArrayList. Each of these orders consists of the quantity, color, and size (S, M, L, XL, and XXL for shirts) or waist/inseam for pants. Here are the orders you must put in the Arraylist: .8 Green double extra-large (XXL) shirts 6 Brown pants with 48 waist and 30 inseam 2 White medium (M) shirts .4 Blue pants with 36 waist and 34 inseanm Your program will then go through the array list to calculate and print, properly labeled: The total number of shirts ordered and the total price .The total number of pants ordered and their total price. The average waist size (to one decimal place) The average inseam length (to one decimal place) (Yes, I am aware that the program doesn't do any calculations based on the color. Sometimes you need to deal with only part of the data available to you; this is one such instance.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Sample output: Total number of shirts ordered: 10 Total price of all shirts: $173.00 Total number of pants ordered: 10...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an equals method for the Shirt class provided below. Two shirts are logically equivalent if...

    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....

    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 "Ret...

    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,...

    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...

    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...

    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...

    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...

    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.

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT