Simple Program
Excersise : 1
Create a Simple program with your own detail.
Program
import java.io.*;
class Stud
{
int reg,m1,m2,m3,m4,tot;
float avg;
String name;
Stud(String n, int rno)
{
name=n;
reg=rno;
}
Stud(int mark1,int mark2,int mark3,int mark4)
{
m1=mark1;
m2=mark2;
m3=mark3;
m4=mark4;
}
public void display()
{
System.out.println("name="+name);
System.out.println("regno="+reg);
}
public void display2()
{
System.out.println("Mark1="+m1);
System.out.println("Mark2="+m2);
System.out.println("Mark3="+m3);
System.out.println("Mark4="+m4);
}
public void calculation()
{
if((m1>=35)&&(m2>=35)&&(m3>=35)&&(m4>=35))
{
tot=m1+m2+m3+m4;
System.out.println("Total="+tot);
avg=tot/4;
System.out.println("Average="+avg);
if(avg>=75)
System.out.println("DISTINCTION");
else if((avg>=60)&&(avg<75))
System.out.println("FIRST CLASS");
else if((avg>=50)&&(avg<60))
System.out.println("SECOND CLASS");
else
System.out.println("THIRD CLASS");
}
else
System.out.println("FAIL");
}
}
class Student1
{
public static void main(String args[])
{
Stud s1,s2;
DataInputStream din=new DataInputStream(System.in);
try
{
System.out.println("Enter the Name:");
String s=din.readLine();
System.out.println("Enter the Register Number:");
int r=Integer.parseInt(din.readLine());
System.out.println("Mark 1:");
int ma1=Integer.parseInt(din.readLine());
System.out.println("Mark 2:");
int ma2=Integer.parseInt(din.readLine());
System.out.println("Mark 3:");
int ma3=Integer.parseInt(din.readLine());
System.out.println("Mark 4:");
int ma4=Integer.parseInt(din.readLine());
s1=new Stud(s,r);
s2=new Stud(ma1,ma2,ma3,ma4);
s1.display();
s2.display2();
s2.calculation();
}
catch(Exception e)
{
System.out.println("INPUT ERROR!!!");
}
}
}
Output
Post a Comment
Thanks for your comments. Please be visit and given positive review on our site.