Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Experiment No.

2
Problem No.1
class Product {

int ID;

String name;

float price;

void insertRecord(int id, String n, float p) {

ID = id;

name = n;

price = p;

void display() {

System.out.println("Id of Product is " + ID);

System.out.println("Name of Product is " + name);

System.out.println("Price of Product is " + price);

class Records {

public static void main(String args[]) {

Product p1 = new Product();

Product p2 = new Product();

p1.insertRecord(10, "Laptop", 70000);

p2.insertRecord(11, "Red Flair", 6000);

p1.display();

p2.display();

Output:
Id of Product is 10

Name of Product is Laptop


Price of Product is 70000.0

Id of Product is 11

Name of Product is Red Flair

Price of Product is 6000.0

Problem No.2
class Mobile {

String Company_name;

int Screen_size;

void insertRecord(String n, int ss) {

Company_name = n;

Screen_size = ss;

void display() {

System.out.println("Name of Company is " +

Company_name);

System.out.println("Size of Screen is " + Screen_size + " inch");

class Records {

public static void main(String args[]) {

Mobile m = new Mobile();

m.insertRecord("Iphone", 11);

m.display();

Output:
Name of Company is Iphone

Size of Screen is 11 inch


Problem No.3
import java.util.*;

class Rectangle {

int length;

int width;

double area;

void input() {

Scanner l = new Scanner(System.in);

System.out.println("Enter the length ");

length = l.nextInt();

Scanner w = new Scanner(System.in);

System.out.println("Enter the width ");

width =w.nextInt();

void output() {

double Area = length * width;

System.out.println("Area of Rectangle is " + Area);

class rectangle {

public static void main(String args[]) {

Rectangle r = new Rectangle();

r.input();

r.output();

Output:
Enter the length

Enter the width


4

Area of Rectangle is 16.0

Problem No.4
import java.util.*;

class Employee {

int emp_id;

String name;

int Basic_salary;

double DA, HRA, Total_salary;

void input() {

Scanner empid = new Scanner(System.in);

System.out.println("Enter Employe id ");

emp_id = empid.nextInt();

Scanner n = new Scanner(System.in);

System.out.println("Enter Name of employee ");

name = n.nextLine();

Scanner BS = new Scanner(System.in);

System.out.println("Enter the Basic Salary ");

Basic_salary = BS.nextInt();

void output() {

double DA = 0.1 * Basic_salary;

double HRA = 0.2 * Basic_salary;

double Total_salary = DA + HRA + Basic_salary;

System.out.println("Total Salary is " + Total_salary);

class Total_salary {

public static void main(String args[]) {


Employee E1 = new Employee();

Employee E2 = new Employee();

E1.input();

E1.output();

E2.input();

E2.output();

Output:
Enter Employe id 101

Enter Name of employee

Ayush Patil

Enter the Basic Salary 40000

Total Salary is 52000.0

Enter Employe id

102

Enter Name of employee Parth Patil

Enter the Basic Salary

50000

Total Salary is 65000.0

Problem No.5
import java.util.*;

class Student {

int Roll_no;

String name;

int Physics, Chemistry;

double Percantage;

void input() {

Scanner rn = new Scanner(System.in);


System.out.println("Enter Roll no. ");

Roll_no = rn.nextInt();

Scanner n = new Scanner(System.in);

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

name = n.nextLine();

System.out.println("Enter your marks out of 100");

Scanner p = new Scanner(System.in);

System.out.println("Enter the Marks of Physics ");

Physics = p.nextInt();

Scanner c = new Scanner(System.in);

System.out.println("Enter the Marks of Chemistry");

Chemistry = p.nextInt();

void output() {

Percantage = (Physics + Chemistry) / 2;

System.out.println("Your Percantage " + Percantage);

class Percantage {

public static void main(String args[]) {

Student s = new Student();

s.input();

s.output();

Output:
Enter Roll no. 33

Enter Name of Student Parth Patil


Enter your marks out of 100

Enter the Marks of Physics

85

Enter the Marks of Chemistry

80

Your Percantage 82.0

You might also like