Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Lab Task 3

Uploaded by

thirdparty546
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lab Task 3

Uploaded by

thirdparty546
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

LAB TASK 3

Name: Sayyam Tahir


Reg. no.: SP23-BSE-014

Exercise 1

public class Book {


int BookId;
int pages;
double Price;

public void set(int BookId,int pages,double Price){


this.BookId = BookId;
this.pages = pages;
this.Price = Price;
}

public double getPRICE(){


return Price;
}
public void sHOW(){
System.out.println("Book Id is " + BookId);
System.out.println("Number of pages are " + pages);
System.out.println("Price of the book is " + getPRICE());
}
}
import java.util.Scanner;
public class Book1 {
public static void main(String[] args) {
int Id;
int pg;
double pr;

Scanner input = new Scanner(System.in);


Book Book1 = new Book();
System.out.print("Enter Book Id: ");
Id = input.nextInt();
System.out.print("Enter number of pages of the book: ");
pg = input.nextInt();
System.out.print("Enter price of the book: ");
pr = input.nextDouble();

Book1.set(Id,pg,pr);
Book1.sHOW();
}

}
Exercise 2

public class Building1 {

public int floors;


public double area;
public int occupants;

Building1(int floors, double area, int occ){


this.floors = floors;
this.area = area;
this.occupants = occ;

public double areaperperson(){


double areaperperson = area/occupants;
return areaperperson;
}

public void dISPLAY(){


System.out.println("Area per person is " + areaperperson());
}
}
public class Building {
public static void main(String[] args) {
Building1 house = new Building1(1,400.50,30);
Building1 office = new Building1(2,300.50,10);
System.out.println("Area of house....");
house.dISPLAY();
System.out.println("Area of Office....");
office.dISPLAY();

Homework
public class Result {

int roll_no;
String name;
int[] marks = new int[3];

public void iNPUT(String name, int roll_no, int marks[]){


this.name = name;
this.roll_no = roll_no;
this.marks = marks;
}

public void dISPLAY(){


System.out.println("Name of the Student is " + this.name);
System.out.println("Roll number of the student is " + this.roll_no);
System.out.print("Marks of three subjects of the student are ");
for(int i = 0; i<3; i++){
System.out.print(marks[i] + " ");
}
System.out.println();
System.out.println("Total marks of the student is " + total());
System.out.println("Avarage marks are " + avg());
}

public int total(){


int total = marks[0] + marks[1] + marks[2];
return total;
}

public double avg(){


double avg = (marks[0] + marks[1] + marks[2])/3;
return avg;
}
}

import java.util.Scanner;
public class ResultMain {
public static void main(String[] args) {

String n;
int r;
int[] m = new int[3];

Scanner input = new Scanner(System.in);


Result Result = new Result();
System.out.print("Enter name of the Student: ");
n = input.nextLine();
System.out.print("Enter roll number of the student: ");
r = input.nextInt();
System.out.print("Enter marks of three subjects: ");
for(int i = 0; i<3; i++){
m[i] = input.nextInt();
}
Result.iNPUT(n,r,m);
Result.dISPLAY();
}

}
Example 1

class circle {
public double radius;

public circle (double r) {


radius = r;
}
public double getRadias() {
return radius;
}
public double getArea() {
return (radius * radius) * Math.PI;
}

public double getCircumference() {


return 2 * Math. PI * radius;
}
public double getDiameter() {
return radius * 2;
}

}
public class cricleMain {

public static void main(String[] args) {

circle c1 = new circle(10);


circle c2 = new circle(12);
System.out.println ("cl Area is " + c1.getArea());
System.out.println ("c2 Area is " + c2.getArea());
System.out.println("c1 Diameter is " + c1.getDiameter());
System.out.println("c2 Diameter is " + c2.getDiameter());
c1.radius = 15;
System.out.println("c1 Area is now " + c1.getArea());
}

}
Example 2

public class A {

private int value = 10;


public int getValue() { return value; }
public void setValue (int newValue) { value = newValue; }
}

public static void main(String[] args) {


A a = new A();
a.setValue (33);
System.out.println(a.getValue ());
}
Example 3

public class StaticTest {

private static int a;


private int b;
public StaticTest () {
a = 0; b = 0;
}
public static int getA () { return a; }
public int getB () { return b; }
public static void setA (int newA) { a = newA; }
public void setB (int newB) { b = newB; }
}
public class StatictestMain {
public static void main(String[] args) {

StaticTest s1 = new StaticTest () ;


StaticTest s2 = new StaticTest () ;
System.out.println ("sl values:");
System.out.println ("a =" + s1.getA() + ", b =" + s1. getB ()) ;
System.out.println ("s2 values:");
System.out.println ("a =" + s2.getA() + ", b =" + s2. getB ());
s1. setA (5);
s1. setB (3);
System.out.println("\ns1 values:");
System.out.println ("a =" + s1.getA() + ", b =" + s1. getB ()) ;
System.out.println ("22 values:");
System.out.println ("a =" + s2.getA() + ", b =" + s2. getB ()) ;
}

Example 4

public class Addition {

public static void main(String[] args) {


int x = 5;
int y = 7;
sum(x,y);
}

static void sum(int a, int b){


int c = a + b;
System.out.println(c);
}

Example 5

public class Addition {

public static void main(String[] args) {


int x = 5;
int y = 7;
int z = sum(x,y);
System.out.println(z);
}

static int sum(int a, int b){


int c = a + b;
return c;
}

Example 6
import java.io.*;
public class ReadingSimplifier {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String name = readString("Enter your name: ");
int age = readInt("Enter your age:");
System.out.println("Welcome " + name);
System.out.println("Your birth year is " +(2024-age));
}

static String readString(String message) {


System.out.println(message);
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
try{
String input = in.readLine();
return input;
}catch (Exception e){}
return "";
}
static int readInt(String message){
String input = readString(message);
return Integer.parseInt(input);
}

You might also like