import java.util.Scanner;
public class Student {
// lets take some non static data members
int roll;
String name;
int physics;
int maths;
int chemistry;
// lets define main method [since we know every java application starts from main method]
public static void main(String[] args) {
// lets create object of student class [object name is 's']
Student s=new Student();
// lets create object of scanner class to take input from keyboard
Scanner sc=new Scanner(System.in);
System.out.println("please provide student info->");
// read data from keyboard and store that data inside non-static data members
// [note: non-static data members must be used using objectname
System.out.print("enter roll: ");
s.roll=sc.nextInt();
System.out.print("enter name: ");
s.name=sc.next();
System.out.print("enter marks in physics: ");
s.physics=sc.nextInt();
System.out.print("enter marks in chemistry: ");
s.chemistry=sc.nextInt();
System.out.print("enter marks in maths: ");
s.maths=sc.nextInt();
// calculate total obtained marks and store that inside a local variable 'total'
int total=s.physics+s.chemistry+s.maths;
// calculate average and store it inside a local variable 'avg'
double avg=total/3;
// lets take two local variables to store grade and remarks
// currently both variable have an empty string as a value
String grade="";
String remark="";
// decide the grade and remarks on the basis of average
if(avg<33.0) {
grade="fail";
remark="you need to word hard";
}
else if(avg>=34.0 && avg<45.0) {
grade="3rd division";
remark="you need to word hard to get 2nd division";
}
else if(avg>=45.0 && avg<60.0) {
grade="2nd division";
remark="you need to word hard to get 1st division";
}
else if(avg>=60.0 && avg<75.0) {
grade="1st division";
remark="you need to word hard to get distinction";
}
else if(avg>=75.0) {
grade="distinction";
remark="you are awesome, just keep it up";
}
// lets print the report card
System.out.println("####Report-Card####");
System.out.println("roll: "+s.roll); // roll is non static variable
System.out.println("name: "+s.name); // name is non static variable
System.out.println("physics: "+s.physics); // physics is non static variable
System.out.println("chemistry: "+s.chemistry); // chemistry is non static variable
System.out.println("maths: "+s.maths); // maths is non static variable
System.out.println("total marks: "+total+"/300"); // total is local variable
System.out.println("percent: "+avg+"%"); // avg is local variable
System.out.println("grade: "+grade); // grade is local variable
System.out.println("remarks: "+remark); // remark is local variable
System.out.println("####End of report####");
}
}
public class Student {
// lets take some non static data members
int roll;
String name;
int physics;
int maths;
int chemistry;
// lets define main method [since we know every java application starts from main method]
public static void main(String[] args) {
// lets create object of student class [object name is 's']
Student s=new Student();
// lets create object of scanner class to take input from keyboard
Scanner sc=new Scanner(System.in);
System.out.println("please provide student info->");
// read data from keyboard and store that data inside non-static data members
// [note: non-static data members must be used using objectname
System.out.print("enter roll: ");
s.roll=sc.nextInt();
System.out.print("enter name: ");
s.name=sc.next();
System.out.print("enter marks in physics: ");
s.physics=sc.nextInt();
System.out.print("enter marks in chemistry: ");
s.chemistry=sc.nextInt();
System.out.print("enter marks in maths: ");
s.maths=sc.nextInt();
// calculate total obtained marks and store that inside a local variable 'total'
int total=s.physics+s.chemistry+s.maths;
// calculate average and store it inside a local variable 'avg'
double avg=total/3;
// lets take two local variables to store grade and remarks
// currently both variable have an empty string as a value
String grade="";
String remark="";
// decide the grade and remarks on the basis of average
if(avg<33.0) {
grade="fail";
remark="you need to word hard";
}
else if(avg>=34.0 && avg<45.0) {
grade="3rd division";
remark="you need to word hard to get 2nd division";
}
else if(avg>=45.0 && avg<60.0) {
grade="2nd division";
remark="you need to word hard to get 1st division";
}
else if(avg>=60.0 && avg<75.0) {
grade="1st division";
remark="you need to word hard to get distinction";
}
else if(avg>=75.0) {
grade="distinction";
remark="you are awesome, just keep it up";
}
// lets print the report card
System.out.println("####Report-Card####");
System.out.println("roll: "+s.roll); // roll is non static variable
System.out.println("name: "+s.name); // name is non static variable
System.out.println("physics: "+s.physics); // physics is non static variable
System.out.println("chemistry: "+s.chemistry); // chemistry is non static variable
System.out.println("maths: "+s.maths); // maths is non static variable
System.out.println("total marks: "+total+"/300"); // total is local variable
System.out.println("percent: "+avg+"%"); // avg is local variable
System.out.println("grade: "+grade); // grade is local variable
System.out.println("remarks: "+remark); // remark is local variable
System.out.println("####End of report####");
}
}
oye teriii ekdum tagda code :D
ReplyDeleteCode tagda toh tab mana jaata hai jab aap log isko apni applications mai use karen
Deletesure :)
Delete