In this BlueJ program, number of objects of an user defined class will be created and values on all the objects will be given. After that the objects will be stored in an array of the same class and using the array, the values will be displayed.
import java.io.*;
class Sata
{
String name, address;
int age;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void inTake()throws Exception
{
System.out.print("Enter Name:");
name=br.readLine();
System.out.print("Enter Address:");
address=br.readLine();
System.out.print("Enter Age:");
age=Integer.parseInt(br.readLine());
}
void show(Sata ob[], int n)
{
for(int i=0;i< n;i++)
System.out.println("\nRecord of candidate number:"+(i+1));
System.out.println("Name="+ob[i].name);
System.out.println("Address="+ob[i].address);
System.out.println("Age="+ob[i].age);
}
}
public static void main(String args[]) throws Exception
{
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
int n;
System.out.println("How many students:");
n=Integer.parseInt(r.readLine());
for(int i=0;i
obj=new
obj.inTake();
ob[i]=obj;
}
System.out.println("\nRecords are as follows\n");
obj.show(ob,n);
}
}
No comments:
Post a Comment