Expand|Select|Wrap|Line Numbers
- import java.io.*;
- class Studentinfo
- {
- private int rlno,m1,m2,m3;
- private String sname;
- public void getdata(int rlno1,String sname1,int m11,int m22,int m33)
- {
- rlno=rlno1;
- sname=sname1;
- m1=m11;
- m2=m22;
- m3=m33;
- }
- void putdata(Studentinfo []students,int s_rlno,int cnt)
- {
- int f=0;
- int i=0;
- int total=0;
- float per=0;
- for(i=0;i<cnt;i++)
- {
- if(students[i].rlno==s_rlno)
- {
- total=total+students[i].m1+students[i].m2+students[i].m3;
- per=per+total/3;
- System.out.println("\n Student Roll no :"+students[i].rlno);
- System.out.println("\n student Name : "+students[i].sname);
- System.out.println("\n student marks in m1 :"+students[i].m1);
- System.out.println("\n student marks in m2 :"+students[i].m2);
- System.out.println("\n student marks in m3 :"+students[i].m3);
- System.out.println("\n student total marks :"+total);
- System.out.println("\n student percentage :"+per);
- }
- }
- }
- public void putdata(Studentinfo [] students,int cnt)
- {
- int i=0;
- int total=0;
- float per=0;
- for(i=0;i<cnt;i++)
- {
- total=total+(students[i].m1+students[i].m2+students[i].m3/3);
- per=total/3;
- System.out.println("\n The percentage of student :"+per);
- }
- }
- }
- public class Student
- {
- public static void main(String [] args) throws IOException
- {
- int cnt=0;
- int ch,f=0;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- Studentinfo students[] = new Studentinfo[10];
- do
- {
- System.out.println("\n 1.Enter student Information.");
- System.out.println("\n 2.Display Student Information.");
- System.out.println("\n 3.Display all Student percentage.");
- System.out.println("\n 4.Exit ");
- System.out.println("\nEnter Your choice : ");
- ch=Integer.parseInt(br.readLine());
- switch(ch)
- {
- case 1:
- if(cnt==10)
- {
- System.out.println("\n Sorry Data storage Limit Reached ");
- break;
- }
- System.out.println(" Enter Student Roll no:");
- int srlno1=Integer.parseInt(br.readLine());
- System.out.println(" Enter student name :");
- String sname1=br.readLine();
- System.out.println(" Enter student marks 1 :");
- int m11=Integer.parseInt(br.readLine());
- System.out.println(" Enter student marks 2 :");
- int m22=Integer.parseInt(br.readLine());
- System.out.println(" Enter student marks 3 :");
- int m33=Integer.parseInt(br.readLine());
- students[cnt] =new Studentinfo();
- students[cnt++].getdata(srlno1,sname1,m11,m22,m33);
- f=1;
- break;
- case 2:
- System.out.println("\n Enter Roll NO :");
- int s_rlno=Integer.parseInt(br.readLine());
- students[0].putdata(students,s_rlno,cnt);
- break;
- case 3:
- students[0].putdata(students,cnt);
- break;
- case 4:
- System.out.println("\n Thank you ");
- break;
- default:
- System.out.println("\n Invalid option ");
- }
- }while(ch!=4);
- }
- };
when i select choice-2 and if there is no record then it must display msg..