| | |
Confused writing a Java Class
![]() |
•
•
Join Date: Jan 2005
Posts: 22
Reputation:
Solved Threads: 0
I have an assignment to write a java class.
What I need to do is write a class and a driver. I need to write a class that stores instance data as members names.
Golfmember(name : String)
then in the driver I would have something like:
golfer1 = new Golfmember();
For instance, the program would display,
Program Displays: Please enter a name for golfer one:
User enters: Joe Blow
Then it should print out something like:
Joe Blow is golfer number one.
I am really confused with writing the class for Golfmember.
Can anyone help?
What I need to do is write a class and a driver. I need to write a class that stores instance data as members names.
Golfmember(name : String)
then in the driver I would have something like:
golfer1 = new Golfmember();
For instance, the program would display,
Program Displays: Please enter a name for golfer one:
User enters: Joe Blow
Then it should print out something like:
Joe Blow is golfer number one.
I am really confused with writing the class for Golfmember.
Can anyone help?
•
•
Join Date: Nov 2004
Posts: 3
Reputation:
Solved Threads: 0
heres your classs with driver.
import java.io.*;
class Golfmember {
static int x = 0;
Golfmember () {
String [] array = new String[5];
array[0] = "one" ;
array[1] = "two";
array[2] = "three";
array[3] = "four";
array[4] = "five";
System.out.println("Please enter name for golfer " + array[x]);
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader (isr);
String s = stdin.readLine();
System.out.println(s +" is golfer "+ array[x]);
}
catch (Exception e) { }
x++ ;
} // end constructor
} // end Golfmemeber class
class driver {
public static void main(String args[] ) {
Golfmember g1 = new Golfmember();
Golfmember g2 = new Golfmember();
Golfmember g3 = new Golfmember();
}
} // end driver
import java.io.*;
class Golfmember {
static int x = 0;
Golfmember () {
String [] array = new String[5];
array[0] = "one" ;
array[1] = "two";
array[2] = "three";
array[3] = "four";
array[4] = "five";
System.out.println("Please enter name for golfer " + array[x]);
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader (isr);
String s = stdin.readLine();
System.out.println(s +" is golfer "+ array[x]);
}
catch (Exception e) { }
x++ ;
} // end constructor
} // end Golfmemeber class
class driver {
public static void main(String args[] ) {
Golfmember g1 = new Golfmember();
Golfmember g2 = new Golfmember();
Golfmember g3 = new Golfmember();
}
} // end driver
![]() |
Similar Threads
- How to? Java GUI interacting with another Java class (Java)
- reading and writing java text files (Java)
- Need help understanding how to use Java for a class. (Java)
- call the constructor of java class from script (Shell Scripting)
- lost on writing a Java class (Java)
Other Threads in the Java Forum
- Previous Thread: applet , Runnable interface and problems
- Next Thread: Undo
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list mac main map method methods mobile myregfun netbeans notdisplaying number online printf problem program project qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






