0% found this document useful (0 votes)
26 views24 pages

Assign Oop

The document describes 9 programming tasks involving object-oriented concepts like classes, objects, methods and constructors. The tasks involve creating classes for vehicles, students, calculators and more. Users are prompted to input data and the program outputs information based on the class definitions and method implementations.

Uploaded by

raonetflix1999
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
26 views24 pages

Assign Oop

The document describes 9 programming tasks involving object-oriented concepts like classes, objects, methods and constructors. The tasks involve creating classes for vehicles, students, calculators and more. Users are prompted to input data and the program outputs information based on the class definitions and method implementations.

Uploaded by

raonetflix1999
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 24

NAME: Rao Humza

ENROLLMENT: 02-132212-010

COURSE TITLE: Object Oriented Programming

COURSE CODE: CSC-210

CLO#: 1 [C2: Comprehension] PLO#:2[Engineering Problem Analysis]

Class BCE-3 Shift: Morning

Course Instructor: Engr. Usra Sami Time Allowed: 1 Week

Max. Marks: 5 Marks

1) A vehicle company manufactures cars. In recent years company produced a


car called ‘L-Sedan’ which has blue color ,it’s engine type is gas, seating
capacity is 5.Identify the object, form the class and make a test application.

package com.mycompany.assignment1;

public class Task1 {

public static void main(String[] args) {

car company=new car();

System.out.println("car information :");

company.display();

}
}

class car{

String carname="L-sedan";

String colour="Grey";

String enginetype="Diesel";

int seatingcapacity=7;

public void display()

System.out.println("carname:" +carname);

System.out.println("colour:" +colour);

System.out.println("enginetype:" +enginetype);

System.out.println("seating capacity:" +seatingcapacity);

}
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;

public class Task2 {


public static void main(String[] args) {

oopcourse c=new oopcourse();

for(int i=1 ;i<=30 ;i++)

c.input();

c.display();

class oopcourse

String studentname;

int rollno;

Scanner input=new Scanner(System.in);

public void input()

System.out.println("enter the student name:");

studentname=input.next();

System.out.println("enter the roll no:");

rollno=input.nextInt();

public void display()


{

System.out.println("student name:" +studentname);

System.out.println("roll no:" +rollno);

3) Redesign example 2(Student).Declare a method as

InputInfo(): to take input data(Id and Roll Number) from user.

Also declare another method

Display():which show the user his information.

package com.mycompany.assignment1;

import java.util.Scanner;
public class Task3 {

public static void main(String[] args) {

Student s=new Student();

System.out.println("Enter Student Information");

s.inputinfo();

System.out.println("Displaying Student Information");

s.display();

class Student{

String name;

int id;

int rollno;

Scanner input=new Scanner(System.in);

public void inputinfo()

System.out.println("Enter Student name: ");

name=input.next();

System.out.println("Enter Student ID: ");


id=input.nextInt();

System.out.println("Enter Student Roll Number: ");

rollno=input.nextInt();

public void display()

System.out.println("Student Name: "+name);

System.out.println("Student Id: "+id);

System.out.println("Student Roll Number: "+rollno);

4) Declare another method in above example which computes result of a student


by using formula.

(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

Display():which show the user his information.

package com.mycompany.assignment1;

import java.util.Scanner;

public class Task4 {

public static void main(String[] args) {

student S =new student();

System.out.println("Enter Student Information:");

S.inputinfo();

S.result();

System.out.println("Displaying Student Information and Percentage");

S.display();

}
class student{

String name;

int id;

int rollno;

double ObtainedMarks;

double totalMarks;

double r;

double percentage;

Scanner input= new Scanner(System.in);

public void inputinfo()

System.out.println("Enter Student Name: ");

name=input.next();

System.out.println("Enter Student ID: ");

id=input.nextInt();

System.out.println("Enter Student Roll Number: ");

rollno=input.nextInt();

System.out.println("Enter Obtained Marks Of Student: ");

ObtainedMarks=input.nextDouble();

System.out.println("Enter Total Marks: ");

totalMarks=input.nextDouble();

public void result()

r=(ObtainedMarks/totalMarks);
percentage=r*100;

public void display()

System.out.println("Student Name: "+name);

System.out.println("Student Id: "+id);

System.out.println("Student Roll Number: "+rollno);

System.out.println("Student Percentage: " +percentage);

5:Design a class calculator to perform basic calculation which include

Three Numbers as attributes/data member(Num1,Num2, Result)

Method which performs the addition of numbers provided by the user

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;

public class Task5 {

public static void main(String[] args) {

System.out.println("Addition:");
calculator c1=new calculator(2,3);

System.out.println("Multiplication;");

calculator c2=new calculator(6.6,2.7);

class calculator{

int a;

int b;

public calculator(int a, int b){

this.a=a;

this.b=b;

System.out.println(a+b);

public calculator(double a, double 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);

Ask user to provide his basic salary and all allowances

package com.mycompany.assignment1;

public class Task6 {

public static void main(String[] args) {


salary s=new salary();

System.out.println("Enter information:");

s.getinfo();

s.formula();

System.out.println("Displaying information:");

s.display();

class salary{

double basicsalary, grosssalary, netsalary, HRA, medicalallowance, conyeanceallowance;

Scanner input= new Scanner(System.in);

public void getinfo(){

System.out.println("Enter basic salary:");

basicsalary=input.nextDouble();

System.out.println("Enter HRA:");

HRA=input.nextDouble();

System.out.println("Enter medical allowance:");

medicalallowance=input.nextDouble();

System.out.println("Enter conyeance allowance:");

conyeanceallowance=input.nextDouble();

}
public void formula(){

grosssalary=basicsalary+HRA+medicalallowance+conyeanceallowance;

netsalary=grosssalary-(basicsalary*0.05);

public void display(){

System.out.println("Gross salary: "+grosssalary);

System.out.println("Net salary:" +netsalary);

7: Create a class GradeBook


a)Include a courseName ,courseInstructor as member variable of type string

b)Provide a constructor to specify two parameters-one for the courseName and


one for the instructor’Name

c)Declare a method displayMessage to output the welcome message and


coursename , followed by “This course is presented by:” and the instructor’s
name.

package com.mycompany.assignment1;

import java.util.Scanner;

public class Assignment1 {

public static void main(String[] args)

GradeBook course=new GradeBook("Complex Variable", "Engr Ahmed Faraz");

GradeBook course1= new GradeBook("Object Orianted Programming" , "Engr Usra Sami");

GradeBook course2= new GradeBook("Object Orianted Programming Lab","Engr Sidra");

course1.displayMessage();

course.displayMessage();

course2.displayMessage();

}
class GradeBook

String coursename;

String courseinstructor;

Scanner inout= new Scanner (System.in);

public GradeBook( String coursename, String courseinstructor)

this.coursename=coursename;

this.courseinstructor=courseinstructor;

public void displayMessage()

System.out.println("Course Name: " + coursename);

System.out.println("Course Instructor: " + 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;

public class Task8 {

public static void main(String[] args)


{

Scanner input = new Scanner(System.in);

System.out.println("Enter the value of Radius");

double radius = input.nextDouble();

Circle c = new Circle(radius);

System.out.println("Area of Circle: "+c.circle);

class Circle

double circle;

public Circle(double radius)

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;

public class Task9 {

public static void main(String[] args)

{
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");

double radius = input.nextDouble();

Circle crcle = new Circle(radius);

System.out.println("Area: "+crcle.circle);

} else {

Circle crcle = new Circle();

System.out.println("Area: "+crcle.circle);

class Circle

double circle;

public Circle(double radius)


{

circle=(3.142*radius*radius);

public Circle()

System.out.println("The value of radius is hardcoded to 12");

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 {

public static void main(String[] args)

Student std1 = new Student("Rao Humza",15,100.0);

System.out.println("Name of std1: " + std1.name);

System.out.println("rollno of std1: " + std1.rollno);

System.out.println("percentage of std1: " + std1.percentage+"%");

Student std2 = new Student();

System.out.println("Name of std2: " + std2.name);

System.out.println("rollno of std2: " + std2.rollno);

System.out.println("percentage of std2: " + std2.percentage+"%");

class Student

String name;

int rollno;

double percentage;
public Student(){

this.rollno = 16;

this.name="Arooba Aqeel";

this.percentage = 98.0;

public Student(String name, int rollno, double percentage){

this.rollno = rollno;

this.name=name;

this.percentage = percentage;

You might also like