|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

11-29-2007, 05:20 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 15
|
|
|
Job Class
I have been trying to run the following code and it compiles but somehow it does not show the cost as stored. So here is the code below;
public Job(int ref, String nam, int pago, int copo, int hour, int minute, boolean doubleSide)
{
reference = ref;
name = nam;
pageno = pago;
copyno = copo;
doubleSides = doubleSide;
setTime = new Time(hour, minute);
Date = null;
}
/**
*
*/
public void calCost(boolean doubleSide, int pago, int copo)
{
if (doubleSides == true)
{
int c = pago * copo * 2;
}
else
{
int c = pago * copo * 3;
}
}
and this is what i have been requiring to do;
The Job class must store the following information about a job: the job's reference number as an int, the name of the member of staff submitting the job as a String, the number of pages and the number of copies to be made as int, whether the copies are to be double sided or not.
&
Write an accessor getCost which returns the cost of the job as specified above
|
|

11-29-2007, 07:16 PM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
I think this might be what you are looking for.
public Job(int ref, String nam, int pago, int copo, int hour, int minute, boolean doubleSide)
{
reference = ref;
name = nam;
pageno = pago;
copyno = copo;
doubleSides = doubleSide;
setTime = new Time(hour, minute);
Date = null;
//add cost field. May need to be something besides an int.
int cost = this.calCost(doubleSides, pageno, copyno);
}
/**
*
*/
//change this to return cost.
public int calCost(boolean doubleSide, int pago, int copo)
{
if (doubleSide == true)
{
int c = pago * copo * 2;
}
else
{
int c = pago * copo * 3;
}
return c;
}
Disclaimer: I didn't compile it. There is a chance I mistyped something.
Last edited by ShoeNinja : 11-29-2007 at 09:36 PM.
|
|

11-29-2007, 08:10 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 15
|
|
Originally Posted by ShoeNinja
I think this might be what you are looking for.
public Job(int ref, String nam, int pago, int copo, int hour, int minute, boolean doubleSide)
{
reference = ref;
name = nam;
pageno = pago;
copyno = copo;
doubleSides = doubleSide;
setTime = new Time(hour, minute);
Date = null;
//add cost field. May need to be something besides an int.
int cost = this.calCost(doubleSides, pageno, copyno);
}
/**
*
*/
//change this to return cost.
public int calCost(boolean doubleSide, int pago, int copo)
{
if (doubleSides == true)
{
int c = pago * copo * 2;
}
else
{
int c = pago * copo * 3;
}
return c;
}
Disclaimer: I didn't compile it. There is a chance I mistyped something.
I have corrected the mistypes, but still it does not store the cost
|
|

11-29-2007, 08:49 PM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
I don't know what you mean by store the cost? In the above code, there is a field in the job class where the cost is stored.
Write an accessor getCost which returns the cost of the job as specified above.
Is this what you need?
If so:
public int getCost(){
return this.cost;
}
|
|

11-29-2007, 08:54 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 15
|
|
Originally Posted by ShoeNinja
I don't know what you mean by store the cost? In the above code, there is a field in the job class where the cost is stored.
Write an accessor getCost which returns the cost of the job as specified above.
Is this what you need?
If so:
public int getCost(){
return this.cost;
}
ye later on i will return the cost, but before that it should calculate the cost. As a result, when i return the cost, it must show me the cost which i have entred not as 0.
|
|

11-29-2007, 09:18 PM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
That should be what it's doing.
this.cost = this.calCost(doubleSides, pageno, copyno);
Here the calCost method uses the data passed to the constructor to calculate and return the cost. Therefore, the cost is stored in cost (imagine that?).
Again I didn't run this, but I am confident that the concept is correct. A little troubleshooting on your part and you should be there.
Last edited by ShoeNinja : 11-29-2007 at 09:23 PM.
|
|

11-29-2007, 09:22 PM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
Is that all of your code up top? I assume you have something like this before that.
public class Job{
int reference, pageno, copyno, cost;
String name;
boolean doubleSides;
|
|

11-29-2007, 09:25 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 15
|
|
Originally Posted by ShoeNinja
That should be what it's doing.
this.cost = this.calCost(doubleSides, pageno, copyno);
Here the calCost method uses the data passed to the constructor to calculate and return the cost. Therefore, the cost is stored in cost (imagine that?).
Again I didn't run this, but I am confident that the concept is correct. A little troubleshooting on your part and you should be there.
it compiles, but still shows the cost as 0.
|
|

11-29-2007, 09:32 PM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
Did you make the changes to the calCost method that I posted?
public int calCost(boolean doubleSide, int pago, int copo)
{
if (doubleSide == true)
{
int c = pago * copo * 2;
}
else
{
int c = pago * copo * 3;
}
return c;
}
How are you instantiating your Job object?
|
|

11-29-2007, 09:35 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 15
|
|
Originally Posted by ShoeNinja
Did you make the changes to the calCost method that I posted?
public int calCost(boolean doubleSide, int pago, int copo)
{
if (doubleSide == true)
{
int c = pago * copo * 2;
}
else
{
int c = pago * copo * 3;
}
return c;
}
How are you instantiating your Job object?
Finally. i have just got it worked. thanks a lot buddy
|
|

11-29-2007, 09:36 PM
|
 |
Senior Member
|
|
Join Date: Oct 2007
Posts: 123
|
|
|
Sweet man. What was wrong?
|
|

11-29-2007, 09:42 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 15
|
|
Originally Posted by ShoeNinja
Sweet man. What was wrong?
I should have put the if statement into constructor not making it as a method
Last edited by kizilbas1 : 12-12-2007 at 06:22 PM.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|