Professional Documents
Culture Documents
Class OOPs
Type Lab
AIM:
1. Write a JAVA program to implement class mechanism. – Create a class, define datamembers, methods
(setData(args) ,getData()) and invoke them inside main method.
2. Write software to prepare the results of the student for school examination. The Roll no ofthe students and their marks
in subjects of Physics, Chemistry and Maths are suppliedthrough the Scanner class. The result of the subject is
prepared and displayed on the outputscreen by finding the students who fail and pass the exam. If the marks are
below 40% insubject, then the student has failed in the subject. If the student passes and the aggregatescore is above
75% then he scores Distinction. If the student passes and aggregate marksare 60%,50%, and 40% then he scores
First, Second, and Third Division. Mention all thecases in output.
import java.util.*;
class Sleep{
static String Sleptat;
static String Wokeupat;
static Scanner input;
Experiment - 4 1
Algorithm:
1. Import all the modules from java util library.
import java.util.*;
class StudentMarks{
static String Name;
static int Rollno;
static String Branch;
static Scanner input;
static int PhysicsPer;
static int ChemistryPer;
static int MathsPer;
static int Aggregate;
Experiment - 4 2
public static void main(String[] args){
System.out.println("Name: Muditt Sharmma,\n Sap ID : 500091725, \n Roll no. : R2142210506");
input = new Scanner(System.in);
setinfo();
getinfo();
sorted();
}
System.out.println("Chemistry Percentage:"+ChemistryPer);
if(ChemistryPer<100 && ChemistryPer<40){
System.out.println("You failed in Chemistry");
}
else if(ChemistryPer<100 && ChemistryPer>75){
System.out.println("You scored a distinction in Chemistry");
}
else if(ChemistryPer<100&& ChemistryPer>=40){
System.out.println("You passed");
}
else{
System.out.println("INVALID");
}
System.out.println("");
System.out.println("Maths Percentage:"+MathsPer);
if(MathsPer<100 && MathsPer<40){
System.out.println("You failed in Maths");
}
else if(MathsPer<100 && MathsPer>75){
System.out.println("You scored a distinction in Chemistry");
}
else if(MathsPer<100&& MathsPer>=40){
System.out.println("You passed");
}
else{
System.out.println("INVALID");
}
System.out.println("");
Aggregate=(PhysicsPer+MathsPer+ChemistryPer)/3;
System.out.println("Aggregate:"+Aggregate);
if(Aggregate<100 && Aggregate<40){
System.out.println("You have failed. You have to repeat a year");
}
else if(Aggregate<100 && Aggregate>75){
System.out.println("You have scored a distinction");
}
else if(Aggregate>=40 && Aggregate<50){
System.out.println("You passed Third Division");
}
else if(Aggregate>=50 && Aggregate<60){
Experiment - 4 3
System.out.println("You passed Second Division");
}
else if(Aggregate>=60 && Aggregate<75){
System.out.println("You passed First Division");
}
else{
System.out.println("INVALID");
}
}
Algorithm:
1. Import every module from java util library
3. create the required variables like Name, Roll no, Branch, and marks.
13. check the conditions for passing, distinction, first division, second division and third division and show the result
accordingly
Experiment - 4 4
{
System.out.println("Sum of the doubles: "+(a+b));
}
sum(1.2, 2.4);
}
}
Algorithm:
1. create a class called Polymorphism
Experiment - 4 5
Algorithm:
1. Create a class TypePromotion
2. Create a sum function with parameters as int num1 and int num2
5. return s
8. result = sum(10,20)
9. show result
class ConstructorOverloading
{
private int Rupee;
ConstructorOverloading()
{
Rupee =49;
}
ConstructorOverloading(int r)
{
this();
Rupee = Rupee+ r;
}
public int getRupee(){
return Rupee;
}
public void setRupee(int Rupee) {
this.Rupee = Rupee;
}
public static void main(String args[])
{
ConstructorOverloading obj = new ConstructorOverloading(12);
System.out.println(obj.getRupee());
}
}
Experiment - 4 6
Algorithm:
1. create a class ConstructorOverloading
5. set Rupee to 49
8. set Rupee=Rupee+r
14. create obj as the new instance for ConstructorOverloading() and pass 12 as the value of r in the parenthesis
Experiment - 4 7