Reply
Old 03-20-2008, 07:04 AM Java
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
Is there anyone who can help me with some java ?
__________________
Www.ebookcabi.net
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
When You Register, These Ads Go Away!
Old 03-20-2008, 08:36 AM Re: Java
mork29's Avatar
Extreme Talker

Posts: 243
Name: Keith Yelnick
Java or Javascript?
mork29 is offline
Reply With Quote
View Public Profile
 
Old 03-20-2008, 01:31 PM Re: Java
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
java ...
__________________
Www.ebookcabi.net
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 03-20-2008, 01:38 PM Re: Java
joder's Avatar
Flipotron

Posts: 6,443
Name: James
Location: In the ocean.
Then you might want to ask a mod to place this thread in the Coding Forum. Javascript is way different than Java.
joder is offline
Reply With Quote
View Public Profile
 
Old 03-20-2008, 03:32 PM Re: Java
NullPointer's Avatar
Will Code for Food

Posts: 498
Name: Matt
Location: Irvine, CA
Post java questions in the coding forum, I can most likely help you out. Java happens to be the language I code in most often.
__________________
http://tinsology.com/ - Under construction
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 03-20-2008, 03:32 PM Re: Java
JacobBranch's Avatar
Skilled Talker

Posts: 65
Name: My Username
Location: Somwhere
Its so fun how no one knows where to post something
__________________
(Will Design/Will Program/Will Code)
(For Small Price)
JacobBranch is offline
Reply With Quote
View Public Profile
 
Old 03-20-2008, 04:58 PM Re: Java
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
If you can help me null that be good thanks
__________________
Www.ebookcabi.net
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 03-20-2008, 05:15 PM Re: Java
NullPointer's Avatar
Will Code for Food

Posts: 498
Name: Matt
Location: Irvine, CA
What exactly do you need help with?
__________________
http://tinsology.com/ - Under construction
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 03-20-2008, 05:56 PM Re: Java
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
Ok well I just started learning java using the blue j enviroment not sure you heard of this or used it. I have got assignment to build a vending machine. What is only gonna be used in blue j, so it dont have visual appearence.

and so far I have created the three classes it will use.
Vending machine
Dispenser
Coinbox

in the vending machine i have been told to use a javamap is it? so far I have got this

public void createDispenser(String sProductName, float fPrice, int iInitialStock)
{
Dispenser objX;

objX = new Dispenser();

// Initialise the dispensers
createDispenser("Coke", 90, 5);
createDispenser("Dr_Pepper", 65, 5);
createDispenser("Pepsi", 75, 5);
createDispenser("Sprite", 80, 5);
createDispenser("Water", 70, 5);
createDispenser("Fanta", 85, 5);
createDispenser("Lilt", 65, 5);
createDispenser("7up", 70, 5);
createDispenser("Oasis", 90, 5);
createDispenser("Ice Tea", 95, 5);
createDispenser("apple Juice", 90, 5);


Then what I need to do in the dispenser class. I need to tell the dispenser class, what item to dispense so I have this so far.

public class Dispenser
{
// instance variables also know as fields


// Constructor for objects of class Dispenser
public Dispenser()
{
// initialise instance variables
}
//returns the item name
public String getName()
{
return sProductName;
}

What I want know is how can I call sProductName from the vending class to display in the getName method ?

so when it returns sProductName it say coke so on......

Hope that clean any problem let me know thanks again
__________________
Www.ebookcabi.net
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 03-21-2008, 12:34 AM Re: Java
NullPointer's Avatar
Will Code for Food

Posts: 498
Name: Matt
Location: Irvine, CA
I have used BlueJ before, but I've found that Eclipse is much better. Just a few recommendations before I address your questions. First please use the CODE tags when posting code as it makes it easier to read and second, in java you should format your code like this:
Code:
public class MyClass
{
     //constants and instance variables
     int x;
     int CONSTANT = 5;
   
     public MyClass(int x)
     {
         this.x = x;
     }

     public void method()
     {
      
     }

}
it makes it much easier to debug and whoever is grading your assignment will appreciate it (and hopefully mark you down if you fail to do so).

Ok now on to your question. It looks to me like you forgot to put a closing braket somewhere but I gather this is what you intended:

Code:
public void createDispenser(String sProductName, float fPrice, int iInitialStock)
{
     Dispenser objX;
     objX = new Dispenser();
     //this line can be reduced to Dispenser objX = new Dispenser();
}

     // Initialise the dispensers
     createDispenser("Coke", 90, 5);
     createDispenser("Dr_Pepper", 65, 5);
     createDispenser("Pepsi", 75, 5);
     createDispenser("Sprite", 80, 5);
     createDispenser("Water", 70, 5);
     createDispenser("Fanta", 85, 5);
     createDispenser("Lilt", 65, 5);
     createDispenser("7up", 70, 5);
     createDispenser("Oasis", 90, 5);
     createDispenser("Ice Tea", 95, 5);
     createDispenser("apple Juice", 90, 5);
I'm assuming create dispenser is a method within the vending machine class. If so then I think what you are trying to do is build a map of dispensers. Java should have a built in map so I'm sure you can find some documentation on using it. I don't have any experience with that particular class because usually my professors make us code our data structures from scratch. What you need to do is create your map and then the create disperser class should create a new dispenser and then add it to that map.

If each dispenser needs to have access to the sProductName variable cooresponding to it, then it should be passed to it via the constructor. Modify your dispenser constructor to take a String called sProductName as input like this:

Code:
public class Dispenser
{
     String sProductName;

     public Dispenser(String sProductName)
     {
           this.sProductName = sProductName;
     }
     
     //this method should now work as is
     public String getName()
    {
          return sProductName;
    }

}
hope that helps, let me know if you need any more help.
__________________
http://tinsology.com/ - Under construction

Last edited by NullPointer : 03-21-2008 at 05:42 AM.
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 03-21-2008, 12:00 PM Re: Java
willcode4beer's Avatar
Webmaster Talker

Posts: 695
Name: Paul Davis
Location: San Francisco
java.util.Map is just an interface.
For something like this, a HashMap is probably the best implementation.

But, if you look at the javadoc for the Map interface, you see a list of the various implementations.

BTW, if you are planning to work with Java after finishing school, you are going to want to learn the collections API inside and out.
__________________
Paul Davis
willCode4Beer.com (coding for all the right reasons)
willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 03-21-2008, 01:27 PM Re: Java
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
Hi thanks I will have look about see how I get on as I say just started learning it so a lot stuff just trying get used to.
__________________
Www.ebookcabi.net
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Reply     « Reply to Java
 

Thread Tools

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 Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16310 seconds with 12 queries