This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thanks anyway  RSS feed

 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I am really new to Java and not very good or able to follow the online tutorials well enough to provide solutions, its been a major problem for me so far.
Thanks to all those who did provide help in any form it was much appreciated.
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dude, it sounds like you are giving up! Dont do it man, Microsoft is your only alternative and thats the dark side
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian
Its not that I am giving up, but it has to be in on Tuesday and I am no where near it. In the end you jut have to bite the bullet

I really needed to have this completed to give me some idea how it goes etc.

However I wont go to the darkside
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some unsolicited help using a couple of simpler classes.





Caveat: I'm at work so this code is untested.
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Garrett
I will have a go....TY
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garrett
What does the override do?
It shows up as an error!
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, that only works on Java 1.5 or higher. What version are you using? Anyway, it won't hurt to just delete it.
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garrett
How do I use this code to solve my problem?
thanks a lot
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wayne Styles:
Hi Garrett
How do I use this code to solve my problem?
thanks a lot

Well.. You don't exactly. However If you study the code and understand how it works, it will help you in solving your problem. If you look at class PersonTester its a lot like what you want to do in your Main class. In the main() method, it creates a new Person instance by invoking the constructor, and then it invokes some methods on that Person instance. Think about how that applies to your requirements.
[ August 21, 2006: Message edited by: Garrett Rowe ]
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garrett
I think I follow whats going on, but I am struggling to find where to put the classes in the code?

Can you help!
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garrett
Here is the code I have now for the Admin Class, I have the nurse class that I need to use.

package Admin;

import javax.swing.*;

public class Admin{

static int numberOfStaff;
static String[]staffNames;

public Admin(){
}
public static void main(String[]args){
Admin.setThingsUp();
System.out.println("All Data Entered Goodbye");
System.exit(0);
}

private static void setThingsUp(){
while(numberOfStaff < 1 || numberOfStaff > 3)//loop to ensure only 1-3 staff can be entered
{
String userln=JOptionPane.showInputDialog("Enter the number of Nurses presently employed. 3 Maximum");
numberOfStaff=Integer.parseInt(userln);
}
{
staffNames = new String[numberOfStaff];//this added to initialize the array
for (int count = 0 ; count < numberOfStaff; count=count + 1){
staffNames[count]=JOptionPane.showInputDialog("Enter the name of the next Nurse.");
continue;

}
}
}
}

So do I need to add your code into here or into its own class (using JBuilder!)
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wayne,

Take a look at Garrett's code.

Notice how the Person class works. It has a constructor that allows a Person class to be built -- and the constructor takes parameters which it saves. It also has getter methods that returns values from the Person class. You need to do something similar for your Nurse (and other) classes.

Notice how the PersonTester class works. It uses the new keyword to create a person class -- and notice how the parameters match the constructor of the person class. Also see how it is used, it calls the getter to get the information about the Person. You need to something similar (in your main class) to construct your Nurse class -- and to use your Nurse class.

Henry
[ August 21, 2006: Message edited by: Henry Wong ]
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry
My problem is in JBuilder I have been asked to create a new class, this provides me with a black page, great.

But I dont know how to link my Admin class and the new nurse class together.

I cant get the new nurse class to allow me to enter any information as only the admin class actually runs. (Does this make any sense to you!)

I need to transfer data from the nurse class to the admin class, but I cant add anything into the nurse class........god this seems really complicated, but I bet its easy really. It all part of the learning curve.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, notice how the PersonTester class works. It uses the new keyword to create a person class -- and notice how the parameters match the constructor of the person class. Also see how it is used, it calls the getter to get the information about the Person.

This is what your Admin class needs to do. You need to construct a Nurse class in your admin class. And then your admin class needs to communicate (get data) with that Nurse class. This is exactly what was done with the PersonTester class -- it constructed a Person class, and then it called the get methods to get data from it.


As for JBuilder... Hopefully someone else can help here. As I have never used that Development Tool before.

Henry
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think its nearly completed. Thanks everyone.
But its not working yet

Here is my admin code
package Admin;

import javax.swing.*;

public class Admin{
public class Nurse{

static int numberOfStaff;
static String[]staffNames;

public Admin(){
}
public static void main(String[]args){
Admin.setThingsUp();
System.out.println("All Data Entered Goodbye");
System.exit(0);
}

private static void setThingsUp(){
while(numberOfStaff < 1 || numberOfStaff > 3)//loop to ensure only 1-3 staff can be entered

{
String userln=JOptionPane.showInputDialog("Enter the number of Nurses presently employed. 3 Maximum");
System.out.println("Sorry YOU can only enter numbers 1 - 3, please re-enter");//Informs the user that they must enter numbers 1-3
numberOfStaff=Integer.parseInt(userln);
}
{
staffNames = new String[numberOfStaff];//this added to initialize the array

for (int count = 0 ; count < numberOfStaff; count=count + 1){

staffNames[count]=JOptionPane.showInputDialog("Enter the name of the next Nurse.");
continue;

public static void main(String[] args){
Nurse me = new Nurse("Bob", "Lockhart");
System.out.println("My National Insurance No is " + me.getnatIns());
System.out.println("My Works No is " + me.getworkNo());
System.out.println("My Details are " + me.getallInfo());
System.out.println("me.toString = " + me.toString());
}
}
}
}
}
}
Last bit added.

Here is my nurse code
package Admin;
public class Nurse{

private final String natIns;
private final String workNo;
public Nurse(String natIns, String workNo){
natIns = newnatIns;
workNo = newworkNo;
}
public String getnatIns(){
return natIns;
}
public String getworkNo(){
return workNo;
}
public String getallInfo(){
return workNo + ", " + natIns;
}
public String toString(){
return getClass().getName() + "["
+ "natIns = " + natIns + ", "
+ "workNo = " + workNo + "]";
}
}
but its not working now. I want to be able to enter data into the nurse class and transfer it to the admin class. I know get data is the method, thanks Henry
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
Can anyone help with this not working. I cant see the error, but then again I probably would not at this learning stage
thanks (Just in case)
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wayne Styles:
Hi All
Can anyone help with this not working. I cant see the error, but then again I probably would not at this learning stage
thanks (Just in case)


Is the problem related to compiling, or running it? I am guessing compiling at this point...

If it is compiling, take a look at the first few errors. Tons of errors may be generated from simple mistakes -- it is easier to just tackle one or two of them, and then compile it again.


So... show us the first couple of errors that the compiler is complaining about, and we'll try to walk you through it.

Henry
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Admin.java": Error #: 215 : invalid method declaration; return type required at line 11, column 14
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wayne Styles:
"Admin.java": Error #: 215 : invalid method declaration; return type required at line 11, column 14


Doh!! I totally forgot that you are using an IDE. The java compiler is much more verbose than that. JBuilder doesn't have to be because it probably points you to where the error is. And probably have internal tooltips that explain what error #215 is.

Keep in mind, we don't have any idea where "line 11, column 14" is. You are going to have to provide the code, with an exact pointer of where line 11 is!! You probably also have to explain error 215 too.

Henry
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wayne Styles:

Here is my admin code
package Admin;

import javax.swing.*;

public class Admin{
public class Nurse{ <<--- This line shouldn't be here.

 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry
I think I will have to submit as it is, just two things to do really.
1) Write code to create a Nurse object in the main method and to store a reference to that Nurse object.
I am assuming this is the get statement!
2) Write code to send a message to the Nurse object.

I am having problems understanding these never mind doing them, any help would be REALLY GREAT
Thanks in advanced.
PS I will leave the error bits from before.
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joanne
Ok, but where should it go then? I need to reference the nurse class within the admin code???

TA
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I am taking a guess where line 11 is... looks right though.



Anyway, if you look at line 6, you have a declaration a Nurse class. Since this Nurse class is defined inside the Admin class, you are defining an inner class (ie. a class within a class). This is probably not what you want -- but I could be wrong.

At line 11, the Admin() constructor is causing the problem. Because you are still defining the inner Nurse class, it is not expecting a contructor for the admin class. Instead it is assuming that it is a method for the inner nurse class. A method that doesn't have a return type -- hence, the error.

Henry
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wayne Styles:
Hi Joanne
Ok, but where should it go then? I need to reference the nurse class within the admin code???

TA



You are already referencing the Nurse class in your admin class -- take a look at the main method of the admin class.



The first line of the method is instantiating a Nurse object -- with a NatIns of "Bob" and a WorkNo of "Lockhart".

Henry
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've taken your Admin class and cleaned it up. There is no need to declare the Nurse class in the Admin class the way you did: public class Nurse. The fact that it is a seperate class is good enough. Also note that your braces are totally off. You don't close some and close others way too many times. It would also appear that you have defined your main method twice. Probably confusion with the Nurse class. Here is the Admin class: Note I used UBB code blocks to format this in this forum.

 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Greg
This is great.
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK
Last bit I hope, it has been a learning curve to say the least.

Write code to create a Nurse object in the main method and to store a reference to that Nurse object.

and

Write code to send a message to the Nurse object.

Any ideas?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I am full of ideas.

Write code to create a Nurse object in the main method...

You already did this.

and to store a reference to that Nurse object.

That's a bit vague but I am assuming it means an instance variable. So, you need an instance variable to store your Nurse object.

Write code to send a message to the Nurse object.

nurse.setMessage("Hello there. Why don't you undo that bow and let me get to know you better.")
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg
The message was funny....
I know you are full of ideas,you have helped me out no end.

Big thanks to you all
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Gregg
As you say "thats a bit vauge", the whole thing has been like this and its been very difficult.

But now I think I am hooked on programming, I just need the time to learn it properly. Its a bit like a Rubik cube, one more turn and I might get it.

But its still not working and thats a real pain.
Thanks again
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
Let me try an put into words whats driving me mad.

I have 2 classes, one called admin and one called nurse. Admin created first.

Now nurse code does not "do anything" like ask for any input, so why bother having this at all?

Is the nurse class a store for information from the admin class?
If so how does the info get into the class nurse?
If not how on earth does it get info into the admin class if its not asking for anything.

Does this make sense to you.......
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the purposes of Object Oriented Programming is to encapsulate related data into objects. So in my previous Person example, each person has a first name, and a last name. In a more robust design each person might also have a Date object that represents their date of birth, or an Address which represents where they live. The point is, each Person is responsible for keeping track of its own data. If you have 1000 Person objects, you should be able to run down the line and ask each one what its name is.

Or using your design, say you were to write a class called Hospital, the Hospital class may be responsible for maintaining a List of Nurses that work there. If the Hospital wanted to find a Nurse with a particular work number it should be able to run down the List of Nurses that it maintains, and ask each Nurse instance what its workNumber is. The method signiture might look like this



and it might be called like this


Edit: I may have gone off on a tangent here, but I hope you get the concept I was going for. Each Nurse instance is reponsible for maintaining info about one particular Nurse.
[ August 22, 2006: Message edited by: Garrett Rowe ]
 
Wayne Styles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
I get the idea I think.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!