Create a class named Shirt with data fields for collar size and sleeve length. I
ID: 3647367 • Letter: C
Question
Create a class named Shirt with data fields for collar size and sleeve length. Include a constructor that takes parameters for each field. Also include a final, static String named MATERIAL and initialize it to cotton. add an additional data field that stores the number of pockets on the shirt. Update the constructor so that it takes parameters for each field.Then write and application named TestShirt to instantiate three Shirt objects with different collar sizes and sleeve lengths , and then display all the data, including material, for each shirt. instantiate three Shirt objects with different collar sizes, sleeve lengths, and numbers of pockets, and then display all the data, including material, for each shirt.
Explanation / Answer
public class Shirt { private int collar, sleeve; private String material; Shirt(int c, int s) { collar = c; sleeve = s; material = "cotton"; } public void display() { System.out.println(collar + " size" + sleeve + " long" + material + " material"); } } TestShirt class public class testShirt { public static void main(String[] args) { Shirt S1 = new Shirt(17,36); Shirt S2 = new Shirt(18,40); Shirt S3 = new Shirt(19, 42); S1.display(); S2.display(); S3.display(); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.