for example:
Create a class named Shirt with data fields for collar size and sleeve length. Include a constructor that takes arguments for each field. Also include a String class variable named variable named material and initialize it to “cotton”. Write a program TestShirt to instantiate 3 Shirt objects with different collar sizes and sleeves lengths, and then display all the data, including material, for each shirt.
well, here is what i have done.
class Shirt{
private double collarSize;
private double sleeveLength;
private String material;
Shirt(double c,double s, String m){
collarSize=c;
sleeveLength=s;
material=m;
m="Cotton";
}
void Printf(){
System.out.println("Collarsize = "+collarSize+" "+"SleeveLength = "+sleeveLength+" "+"Material = "+material);
}
}
public class TestShirt {
public static void main(String []args){
Shirt testShirt1= new Shirt(15,30,"cotton");
Shirt testShirt2= new Shirt(13,28,"cotton");
Shirt testShirt3= new Shirt(17,32,"sock");
testShirt1.Printf();
testShirt2.Printf();
testShirt3.Printf();
}
}
UPDATE: i guess am missing a class for Material.
Well do i need to use get and set methods ??? this is my question, could someone give me some pointers on WHEN and how to use the get set methods?
Thanx..

New Topic/Question
Reply



MultiQuote









|