By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

Please help

P: n/a

Please help, I am learning java and have been stuck with this problem. I
have been trying to
figure it out on my own, but I am getting nowhere. The problem is this; I
need to create a class
named shirt with three data fields. I need a constructor that will take
arguments for the sleeve and
collar fields.I need to be able to use this to create three shirt objects. I
am stuck and I dont want
anyone to do my work for me, just a push in the right direction. Thank you
for your time. Mike

class shirt
{
int sleeve;
int collar;
double min = 200.00;

public static getsleeve()
{
return sleeve;
}

public static getcollar()
{
return collar
}

{

public class newshirt
{
public static void main(String[] args)
{
shirt myshirt = newshirt(12, 20);

//This is were I need help how can i use access the values (12, 20)
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Mike,

A few tips:
1) Don't try to stuff everything into one class.
Create a class Shirt and use that one from your main.

2) Do not use the static-keyword unless you know what is does.
I guess you introduced static in your methods to keep your compiler happy.

So what you should do is first create a nice Shirt class.
To pass the attributes of a shirt to the shirtclass you have a few options:
a) pass them to the constructor, (from main:)
Shirt myFirstShirt = new Shirt(10,20,30);
Shirt mySecondShirt = new Shirt(2,2,1);

or b) Create an empty Shirt-object and create a few methods to set the
attributes of your shirt, like this:
Shirt myFirstShirt = new Shirt();
myFirstShirt.setCollarSize(20);
myFirstShirt.setSize("Large");

This is just fantasycode of course, but I hope it helps you a bit.

Good luck,
Erwin

Jul 17 '05 #2

P: n/a
Also,
If you use the constructor version shown in (a) below, your Shirt Class
will need a Shirt Constructor method....
eg
public Shirt(int pSleeve, int pCollar) {
sleeve = pSleeve;
collar = pCollar;
}
Then to access the values for sleeve and collar you would use the
MyShirt.getsleeve(), and MyShirt.getcollar() methids.

Hope this helps :)
erwin moller wrote:
Hi Mike,

A few tips:
1) Don't try to stuff everything into one class.
Create a class Shirt and use that one from your main.

2) Do not use the static-keyword unless you know what is does.
I guess you introduced static in your methods to keep your compiler happy.

So what you should do is first create a nice Shirt class.
To pass the attributes of a shirt to the shirtclass you have a few options:
a) pass them to the constructor, (from main:)
Shirt myFirstShirt = new Shirt(10,20,30);
Shirt mySecondShirt = new Shirt(2,2,1);

or b) Create an empty Shirt-object and create a few methods to set the
attributes of your shirt, like this:
Shirt myFirstShirt = new Shirt();
myFirstShirt.setCollarSize(20);
myFirstShirt.setSize("Large");

This is just fantasycode of course, but I hope it helps you a bit.

Good luck,
Erwin


Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.