jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie simple  java program" Watch "newbie simple  java program" New topic

newbie simple java program

ajay garg

Joined: Aug 24, 2005
Posts: 2
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

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.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();


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!!!
I agree. Here's the link: http://aspose.com/file-tools
subject: newbie simple java program
It's not a secret anymore!