You are on page 1of 2

//Case 1:

public class Tesst {

static void run() ///static method


{
System.out.println("I am runnig");
}

public void eat()


{
System.out.println("I am eating");
}

/////////////////////////////////////////////////////

public static void main(String[] args) {

System.out.println("Content available in main\n");

Tesst.run(); // here directly call method with the class name.


//calling run method with the class name.
// No need to create an object for static method.

Tesst object= new Tesst();//// Object is created


object.eat(); /// calling eat method with an object.

//Case2:

import java.util.Scanner;

public class Student {

int stud_id;
String stud_name;
int marks_phy,marks_chem,marks_math;

public void studentData()


{
Scanner s = new Scanner(System.in);

System.out.print("Enter Student Id : ");


stud_id = s.nextInt();

System.out.print("\nEnter Student Name : ");


stud_name = s.next();

System.out.print("\nMarks obtained in Physics : ");


marks_phy = s.nextInt();
System.out.print("\nMarks obtained in Chemistry : ");
marks_chem = s.nextInt();
System.out.print("\nMarks obtained in Mathematics : ");
marks_math = s.nextInt();

}
public void displayStudentData()
{
System.out.println("\nStudent Id: "+ stud_id);
System.out.println("\nStudent Name: "+ stud_name);
System.out.println("\nMarks obtained in Physics out of 100: "+
marks_phy);
System.out.println("\nMarks obtained in Chemistry out of 100: "+
marks_chem);
System.out.println("\nMarks obtained in Maths out of 100: "+ marks_math);
}

public void calculateResult()


{
int marks = marks_phy + marks_chem+ marks_math;
System.out.println("\nMarks obtained by" + " "+ stud_name + " in PCM
is: " +marks);

float per = (marks * 100) / 300;


System.out.println ("Percentage in PCM = "+per+"%");

if(marks>120) {
System.out.println("Result: Pass");
}
else {
System.out.println("Result : Fail");
}
}

public static void main(String[] args)


{

Student e = new Student(); //creating object for 1st student


e.studentData();
e.displayStudentData();
e.calculateResult();
System.out.println("================================");
Student e1 = new Student(); //creating object for 2nd student
e1.studentData();
e1.displayStudentData();
e1.calculateResult();

}
}

Case 3:

You might also like