Skip to document

ICE107 LAB02 Nazmul ALAM

This is first lab about OOP. It is all about some basic programs.
Course

JAVA basic programming (CSE110)

34 Documents
Students shared 34 documents in this course
Academic year: 2020/2021
Uploaded by:
0followers
0Uploads
0upvotes

Comments

Please sign in or register to post comments.

Preview text

Lab Report: 02

Course Title: Object Oriented Programming

Course Code: ICE

Section: 01

Submitted to:

Muhammad Suhail Najeeb

Lecturer

Department of Electronics and Communications Engineering

Submitted by:

Nazmul Alam

ID: 2017-2- 50 -

Date of Submission: July 19, 2021

Problem:

Code(Class):

package rectanglePackage;

public class Rectangle {

double width, height; Rectangle(){ width =1; height =1; } Rectangle( double width, double height){ this .width= width; this .height= height; } double getArea() { return widthheight; } double getPerimeter() { return 2(width+height);

}

}

Code (Test):

package rectanglePackage;

public class Main { public static void printRect(Rectangle r) { System. out .println("For Rectangle 1: "); System. out .println("Width: "+ r + "\tHeight: " + r); System. out .println("Area: " + r() + "\tPerimeter: "

  • r());

} public static void main(String[]args) { Rectangle rect1 = new Rectangle(4,40);

this .annualInterestRate = 0; this .dateCreated = new Date();

} //constructor Account( int id, double balance){ this .id = id; this .balance = balance; this .dateCreated = new Date();

}

//accessor method for id getID(){ return this .id;

} //modifier method for id void setID( int id){ this .id = id; } //accessor method for balance getBalance(){ return this .balance; } //modifier method for balance void setBalance( double balance){ this .balance = balance; } double getBalance() { return this .balance;

}

// accessor for annual intetest rate getAnualinterestrate(){ return this .annualInterestRate; } //modifier method for annual interest rate void setAnnualinterestrate( double annualInterestRate){ this .annualInterestRate = annualInterestRate; } //accessor method for date created getDatecreated(){ return this .dateCreated;

}

private getMonthlyInterestRate() { return (annualInterestRate / 100) / 12 ; }

private getMonthlyInterest() { return balance * getMonthlyInterestRate(); }

private withdraw( double amount) { this .balance -= amount; }

private deposit( double amount) { this .balance += amount; }

Code (Test):

package accountPackage;

public class Accountoutput { public static void main(String[] args) { Account account = new Account(1122, 20000); account(4); account(2500); account(3000); System. out .println("Balance: $" + account()); System. out .println("Monthly Interest: " + account()); System. out .println("Date Created: " + account());

} }

public RegularPolygon( int numberOfSides, double sideLength, double x, double y) { this (numberOfSides, sideLength); CenterX = x; CenterY = y; } //Accessor

public int getNumberOfSides() { return NumberOfSides; } //Modifier public void setNumberOfSides( int numberOfSides) { NumberOfSides = numberOfSides; } //Accessor public double getSideLength() { return SideLength; } //Modifier public void setSideLength( double sideLength) { SideLength = sideLength; }

public double getCenterY() { return CenterY; }

public void setCenterY( double centerY) { CenterY = centerY; }

public double getCenterX() { return CenterX; }

public void setCenterX( double centerX) { CenterX = centerX; }

public double getPerimeter(){

return NumberOfSides * SideLength; }

public double getArea() {

return (NumberOfSides * SideLength * SideLength) / (4 * Math. tan (Math. PI / NumberOfSides)); }

}

Code(Test):

package Polygon;

public class Main {

public static void main(String[] args) { // Create three RegularPolygon objects RegularPolygon regularPolygon1 = new RegularPolygon(); RegularPolygon regularPolygon2 = new RegularPolygon(4, 3); RegularPolygon regularPolygon3 = new RegularPolygon(8, 4, 6, 5);

// Display perimeter and area of each object System. out .println("Objects Perimeter Area"); System. out .printf( "1 %6 %5\n", regularPolygon1(), regularPolygon1()); System. out .printf( "2 %6 %5\n", regularPolygon2(), regularPolygon2()); System. out .printf( "3 %6 %5\n", regularPolygon3(), regularPolygon3()); } }

Output:

Was this document helpful?

ICE107 LAB02 Nazmul ALAM

Course: JAVA basic programming (CSE110)

34 Documents
Students shared 34 documents in this course
Was this document helpful?
Lab Report: 02
Course Title: Object Oriented Programming
Course Code: ICE107
Section: 01
Submitted to:
Muhammad Suhail Najeeb
Lecturer
Department of Electronics and Communications Engineering
Submitted by:
Nazmul Alam
ID: 2017-2-50-009
Date of Submission: July 19, 2021