DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Confused writing a Java Class (http://www.daniweb.com/forums/thread18558.html)

jengels Feb 12th, 2005 10:50 pm
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?

pasaris Feb 13th, 2005 2:53 pm
Re: Confused writing a Java Class
 
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

jwenting Feb 14th, 2005 1:52 am
Re: Confused writing a Java Class
 
please don't do peoples' homework for them. It prevents them from learning and turns them into lazy bastards who cause professionals to have to work overtime while they themselves lounge in front of the television...

server_crash Feb 14th, 2005 7:40 am
Re: Confused writing a Java Class
 
Quote:

Originally Posted by jwenting
turns them into lazy bastards

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.


All times are GMT -4. The time now is 1:54 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC