This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes newbie simple  java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie simple  java program" Watch "newbie simple  java program" New topic
Author

newbie simple java program

ajay garg
Greenhorn

Joined: Aug 24, 2005
Posts: 2
hi
i m a newbie in programmig and making a simple program
i made a class

class student
{
String name;
int id;
int age ;
}
public static void main()
{
student o1 = new student();
o1.add (???
}

i want my program in this way:
here output must be like this
do u want to add student? say (y/n)
if i write 'y'
than it asked
please write: name, id, age .
ajay , 001 , 18


than it must show the output:
ajay ,001 ,18
now again it must asked
do u want to add student? say (y/n)
here i want to make a list of student

i wan to print list of student uptill user write y
please help me in any way so that
i can go through this problem
[ August 24, 2005: Message edited by: ajay garg ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you're adding students, so you want to separate the student from the register.
create the following classes
class StudentRegister
class Student

You need to have (in the register)
your code for main() - to start the program
a collection class - to hold the student objects

the collection class could be
an array - but you need to know/set a size
an arraylist
a hashmap - where (say) student id is the key

now, if the user answers yes to add student, you get the 3 data items
and use the constructor to add the data to the student object
arraylist.add(new Student("Mary",12345,21));
ajay garg
Greenhorn

Joined: Aug 24, 2005
Posts: 2


import java.util.*;
class student
{

static String name;
static int age;
static int id;

public student(String name , int age , int id)
{


student.name= name;
student.age=age;
student.id = id;
}


}


public class candidate

{

public static void main(String args[])

{

Map map = new HashMap(); // hash table
map.put("a", new student(" ajay" , 25 , 1));
map.put("b", new student(" ram " , 23 , 2));
map.put("c", new student(" shyam" , 20, 3) );
// Iterator it = map.keySet().iterator();
System.out.println(map);
}



}





i have done up till now
now how to iterate and according to myproblem
it must asked do u want to add y/n

pleeeese help anyone
Ashok George
Ranch Hand

Joined: Mar 25, 2005
Posts: 87
that reply!! was gud!!
lot of info in that!!!
thanx..... for the help!!!
really great cheers to the moderators of this grou[p...... really great work guys!!!
 
wood burning stoves
 
subject: newbie simple java program