Assign Oop
Assign Oop
ENROLLMENT: 02-132212-010
package com.mycompany.assignment1;
company.display();
}
}
class car{
String carname="L-sedan";
String colour="Grey";
String enginetype="Diesel";
int seatingcapacity=7;
System.out.println("carname:" +carname);
System.out.println("colour:" +colour);
System.out.println("enginetype:" +enginetype);
}
2)In this OOP class, there are 30 students. And each student has its name and
roll Number .You are required to make a class OOPCourse containing two instance
variable(attributes/data members/member variables ).
Ask the user to provide his name and id .And display the entered information to
user.
package com.mycompany.assignment1;
import java.util.Scanner;
c.input();
c.display();
class oopcourse
String studentname;
int rollno;
studentname=input.next();
rollno=input.nextInt();
package com.mycompany.assignment1;
import java.util.Scanner;
public class Task3 {
s.inputinfo();
s.display();
class Student{
String name;
int id;
int rollno;
name=input.next();
rollno=input.nextInt();
(percentage=(obtainMarks/TotalMarks)*100).
Signature of method reflects the example of a method with return value
Take example Student and define a method .Ask user to input data in main
package com.mycompany.assignment1;
import java.util.Scanner;
S.inputinfo();
S.result();
S.display();
}
class student{
String name;
int id;
int rollno;
double ObtainedMarks;
double totalMarks;
double r;
double percentage;
name=input.next();
id=input.nextInt();
rollno=input.nextInt();
ObtainedMarks=input.nextDouble();
totalMarks=input.nextDouble();
r=(ObtainedMarks/totalMarks);
percentage=r*100;
a) Now what would you do if the calculation result needs to print in main
b) Now, make a method to perform multiplication
package com.mycompany.assignment1;
System.out.println("Addition:");
calculator c1=new calculator(2,3);
System.out.println("Multiplication;");
class calculator{
int a;
int b;
this.a=a;
this.b=b;
System.out.println(a+b);
System.out.println(a*b);
}
6:Design the class SalaryCalculator which has basicSalry,grossSalry,netSalry as
member variables of class. Provide method to calculate gross Salary and Net
Salary
grosssalary = b_sal+hra+medicalallowance+conyeanceAllowance);
netsalary = grosssalary-(b_sal*0.05);
package com.mycompany.assignment1;
System.out.println("Enter information:");
s.getinfo();
s.formula();
System.out.println("Displaying information:");
s.display();
class salary{
basicsalary=input.nextDouble();
System.out.println("Enter HRA:");
HRA=input.nextDouble();
medicalallowance=input.nextDouble();
conyeanceallowance=input.nextDouble();
}
public void formula(){
grosssalary=basicsalary+HRA+medicalallowance+conyeanceallowance;
netsalary=grosssalary-(basicsalary*0.05);
package com.mycompany.assignment1;
import java.util.Scanner;
course1.displayMessage();
course.displayMessage();
course2.displayMessage();
}
class GradeBook
String coursename;
String courseinstructor;
this.coursename=coursename;
this.courseinstructor=courseinstructor;
}
8:Design the application for class Circle that inputs from the user the radius of a
circle as an integer and prints the circle’s diameter and area in main() .Also
Provide a user based parameterized constructor.i.e U need to ask the radius value
from user
package com.mycompany.assignment1;
import java.util.Scanner;
class Circle
double circle;
circle=(3.14*radius*radius);
}
}
9: Modify the class Circle which has a default constructor in which a hardcode
value sets as a value of a radius. Now apply if and switch control structures for
choice to choose which constructor user wants to use.
package com.mycompany.assignment1;
import java.util.Scanner;
{
Scanner input = new Scanner(System.in);
System.out.println("Do you want to use hardcoded or usercoded constructor? (1 for hard, 2 for
user)");
int whichCoded=input.nextInt();
if(whichCoded == 2){
System.out.println("Enter Radius");
System.out.println("Area: "+crcle.circle);
} else {
System.out.println("Area: "+crcle.circle);
class Circle
double circle;
circle=(3.142*radius*radius);
public Circle()
circle=(3.142*12*12);
}
10: Define a class Student that has attributes Name, Roll no, (integer),
percentage(double) . Include following constructors:
Create a student with Name and Roll no. Hint: A default constructor that takes
no arguments
Create a student with Name, Roll no,percentage. Hint: A constructor that takes
values of all attributes. Provide a method that shows the information of a
student.
package com.mycompany.assignment1;
public class Task10 {
class Student
String name;
int rollno;
double percentage;
public Student(){
this.rollno = 16;
this.name="Arooba Aqeel";
this.percentage = 98.0;
this.rollno = rollno;
this.name=name;
this.percentage = percentage;