954,173 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Confused writing a Java Class

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?

jengels
Newbie Poster
22 posts since Jan 2005
Reputation Points: 10
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

pasaris
Newbie Poster
3 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

please don't do peoples' homework for them. It prevents them from learning and turns them into lazy ######## who cause professionals to have to work overtime while they themselves lounge in front of the television...

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
turns them into lazy ########

lol
:cheesy:

I agree though, you should of at least let him show a little effort..I mean even if it was a bunch of method and class stubs, at least it would have been some effort.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

i have a simular problem with a photocopying machine task i need to right class called photocopier and add the code to create the instance variables

powerStatus, an integer instance variable ( -1= standby, 0=Off and 1 =On)
letter, a string instance variable for (none, general, form,menu and paper)
copying a boolean instant variable
copytime a double variable representing the time of the current printing job

Any Help would be fantastic

markhowe56
Newbie Poster
5 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This thread is more than 5 years old, the OP had probably finished his PhD by now. Please open a new thread and leave old threads to die in peace.

apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You