Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called Shirt. There should be 3 instance variables, the color (a

ID: 3650263 • Letter: C

Question

Create a class called Shirt. There should be 3 instance variables, the color (a String), the size (an int), and the unit price (a double).

Write a set method for each instance variable. Write a method showInfo that prints all three instance variables, labeled.

Write a test application, called ShirtTest. It should create a Shirt, have the Shirt call all three get methods, then call showInfo to make sure all is working. A sample output at this point might be:

color: ocean blue
size: 14
unit price: $27.99
(The $ is part of the format string. To get 2 digits to the right of the decimal point use %.2f. See section 3.7 of the textbook.)
Part B.

Once part A is working, proceed. Write a get method for the unit price.

Modify ShirtTest to have a dialogue, as below:

What color shirt would you like? orange
What size? 16
What is the price of a shirt? 31.01
How many would you like? 3

Here is your order:
3 shirts
color: orange
size: 16
unit price: $31.01
Total: $93.03
Thank you for your order.
(In this example, the bold is input, entered by the user.)
main of ShirtTest should ask for and read in the input. main will need some local variables to hold the answers to the questions.
A Shirt object should then be created. Its attributes should be set using the input information.
The summary information should be printed using showInfo.
The total should be computed using the input value for quantity and the get value for unit price. (Yes you could use the variable that holds the input value, but please don't. Use the get method instead.)

Explanation / Answer

Please rate...

Save both the files in the same directory. Compile both the files and run the file "ShirtTest.java"

Programs:

Shirt.java

===========================================================

class Shirt
{
    String color;
    int size;
    double unitPrice;

    public void setColor(String c)
    {
        color=c;
    }
    public void setSize(int s)
    {
        size=s;
    }
    public void setUnitPrice(double us)
    {
        unitPrice=us;
    }
    public void showInfo()
    {
        System.out.print(" Color: "+color);
        System.out.print(" Size: "+size);
        System.out.printf(" Unit Price: $%.2f",unitPrice);
    }

    public double getUnitPrice()
    {
        return unitPrice;
    }
}

=================================================================

ShirtTest.java

=================================================================

import java.util.Scanner;

class ShirtTest
{
    public static void main(String args[])
    {
        Scanner scan=new Scanner(System.in);
        System.out.print("What color shirt would you like? ");
        String c=scan.next();
        System.out.print("What size? ");
        int size=scan.nextInt();
        System.out.print("What is the price of a shirt? ");
        double up=scan.nextDouble();
        System.out.print("How many would you like? ");
        int n=scan.nextInt();

        Shirt s=new Shirt();
        s.setColor(c);
        s.setSize(size);
        s.setUnitPrice(up);
        System.out.println(" Here is your order:");
        System.out.print(n+" shirts");
        s.showInfo();
        System.out.printf(" Total: $%.2f",(n*s.getUnitPrice()));
        System.out.println(" Thank you for your order");
    }
}

==================================================================

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote