Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2007, 05:20 PM
Member
 
Join Date: Nov 2007
Posts: 15
kizilbas1 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-29-2007, 07:16 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
I think this might be what you are looking for.

Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-29-2007, 08:10 PM
Member
 
Join Date: Nov 2007
Posts: 15
kizilbas1 is on a distinguished road
Quote:
Originally Posted by ShoeNinja View Post
I think this might be what you are looking for.

Code:
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-29-2007, 08:49 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to 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:
Code:
public int getCost(){ return this.cost; }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-29-2007, 08:54 PM
Member
 
Join Date: Nov 2007
Posts: 15
kizilbas1 is on a distinguished road
Quote:
Originally Posted by ShoeNinja View Post
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:
Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-29-2007, 09:18 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
That should be what it's doing.

Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-29-2007, 09:22 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Is that all of your code up top? I assume you have something like this before that.

Code:
public class Job{ int reference, pageno, copyno, cost; String name; boolean doubleSides;
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-29-2007, 09:25 PM
Member
 
Join Date: Nov 2007
Posts: 15
kizilbas1 is on a distinguished road
Quote:
Originally Posted by ShoeNinja View Post
That should be what it's doing.

Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-29-2007, 09:32 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Did you make the changes to the calCost method that I posted?

Code:
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?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-29-2007, 09:35 PM
Member
 
Join Date: Nov 2007
Posts: 15
kizilbas1 is on a distinguished road
Quote:
Originally Posted by ShoeNinja View Post
Did you make the changes to the calCost method that I posted?

Code:
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
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-29-2007, 09:36 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Sweet man. What was wrong?
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 11-29-2007, 09:42 PM
Member
 
Join Date: Nov 2007
Posts: 15
kizilbas1 is on a distinguished road
Quote:
Originally Posted by ShoeNinja View Post
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the Priority for execution of Interface class and a Abstract class Santoshbk Advanced Java 0 04-02-2008 09:04 AM
Accessing inner class from outer class (an example) Java Tip Java Tips 0 02-17-2008 11:03 AM
An example of accessing outer class from inner class Java Tip Java Tips 0 02-17-2008 11:01 AM
Inner class accessing outer class Java Tip Java Tips 0 02-17-2008 10:59 AM
Accessing one class from another class through swing kbyrne AWT / Swing 5 01-03-2008 09:54 AM


All times are GMT +3. The time now is 03:53 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org