Avik Sarkar
2013-01-04 07:36:10 UTC
Data Members-name,age,m1,m2,m3(marks in 3 sub),maximum,average
Member Methods-
1)A parametrized constructor to initialize the data members
2)To accept the details of a student
3)To compute average and maximum out of 3 marks
4)To display name,age,marks in 3 sub,max,avg
Write a main method create an object and CALL THE ABOVE METHODS
import java.io.*;
class student
{
String name;
int age,m1,m2,m3,maxi;
float avg;
student(String n,int a,int m4,int m5,int m6)
{
age=a;
m1=m4;
m2=m5;
m3=m6;
name=n;
maxi=0;
avg=0;
}
void accept(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter name");
String a=in.readLine();
System.out.println("Enter age");
int ae=Integer.parseInt(in.readLine());
System.out.println("Enter marks1");
int m7=Integer.parseInt(in.readLine());
System.out.println("Enter marks 2");
int m8=Integer.parseInt(in.readLine());
System.out.println("Enter marhks 3");
int m9=Integer.parseInt(in.readLine());
student obj=new student(a,ae,m7,m8,m9);
}
void compute()
{
int t=m1+m2+m3;
avg=(float)(t/3f);
if(m1>m2&&m1>m3)
maxi=m1;
else if(m2>m1&&m2>m3)
maxi=m2;
else
maxi=m3;
}
void display()
{
System.out.println("Name= "+name);
System.out.println("marks 1 = "+m1);
System.out.println("marks 2 = "+m2);
System.out.println("marks 3= "+m3);
System.out.println("avg= "+avg);
System.out.println("max= "+maxi);
}
public static void main(String args[])throws IOException
{
student obj1=new student();
obj1.accept();
obj1.compute();
obj1.display();
}
}
The above returns a syntax error: cannot find symbol-constructor student
How to correct this error?
And is it possible to create two objects in JAVA?
I don't want to do the program using 2 classes..And even if the program is correct,the question says to call the member methods from main function,but I have called the constructor earlier in the accept() function.So does my answer goes according to the question?
Can anyone suggest a better way to do the program?
REMEMBER I AM IN CLASS 10 ONLY.SO ANSWER IN THAT WAY ONLY.
The best help will be highly appreciated.