| | |
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 |
911 actionlistener addball addressbook android applet application apps array automation binary bluetooth businessintelligence button card character class client code collision component consumer crashcourse css csv database desktop eclipse ee error fractal free ftp game givemetehcodez graphics gui html image integration j2me japplet java javaarraylist javac javadoc javaee javafx javaprojects jni jpanel julia jvm linked linux loan mac method migrate mobile netbeans objects online oriented phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server service set sms software sort sql swing test textfield textfields threads time tree trolltech ubuntu update utility windows






