OOPS Assignment No 2
OOPS Assignment No 2
SOFTWARE ENGINEERING
MILITARY COLLEGE OF SIGNALS,
NUST, RAWALPINDI
Assignment no: 02
STUDENT DETAILS:
NAME SARA AMIN
DEPARTMENT SE-29 C
CMS ID 464417
INSTRUCTOR Col Khawir
DATE 1 May, 2024
ASSIGNMENT NO: 02
Question n0 :1
CODE:
Package rectangleClass;
class Rectangle
{
double width;
double height;
public Rectangle(){
width=1;
height=1;
}
public Rectangle(double width,double height)
{
this.width=width;
this.height=height;
}
public double getArea ()
{
return width*height;
}
public double getPerimetrer()
{
return 2*(width+height);
}
}
public class RectangleClass {
}
UML DIAGRAM:
Rectangle
+ width : double
+ height : double
+area: double
+perimeter: double
+ Rectangle()
+ Rectangle( double , double )
+ getArea() : double
+ getPerimeter() : double
+display() : void
r : Rectangle R1 : Rectangle
width : 4 width : 3.5
height : 40 height : 35.9
QUESTION NO : 02
CODE:
package stockClass;
class Stock
{
String symbol;
String name;
double previousClosingPrice;
double currentPrice;
Stock(String symbol,String name)
{
this.symbol=symbol;
this.name=name;
}
public double getChangePercent()
{
return (currentPrice-previousClosingPrice)/(previousClosingPrice) *
100;
}
}
Stock
+ symbol : String
+ name : String
+ previousClosingPrice : double
+ currentPrice : double
s1 : Stock
symbol : ORCL
name : Oracle
previousClosingPrice : 34.5
currentPrice : 34.35
QUESTION NO: 03
CODE:
package accountClass;
import java.util.*;
class Account {
private int id;
private double balance;
private double annualInterestRate;
private Date dateCreated = new Date();
Account() {
id = 0;
balance = 0;
annualInterestRate = 0.0;
}
UML DAIGRAM:
Account
-id: int
-balance: double
-AnnualInterestRate: double
-dateCreated: Date
Account()
Account(int,double)
+setId( int) : void
+setBalance(double) : void
+setAnnualRate(double):void
+get id:int
+getBalance: double
+getAnnualRate:double
+getdate: Date
+getMonthlyinterestrate(): double
+montlhyInterest() : double
+withdraw():void
+deposit():void
a1: Account
setannualrate(double) :void
withdraw(int): void
deposit(int):void
QUESTION NO: 04
CODE:
package stopwatchClass;
import java.util.*;
import java.text.SimpleDateFormat;
import java.util.Random;
class StopWatch
{
private Date starttime;
private Date endtime;
StopWatch()
{
starttime= new Date();
}
public String getstarttime()
{
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
UML DIAGRAM:
StopWatch
- startTime : Date
- endTime : Date
+ StopWatch()
+ start() : void
+ stop() : void
+ ElapsedTime() : long
+ getstarttime() :String
+ getendtime() : String
watch : StopWatch
start() : void
stop() : void
getstarttime(): String
getendtime(): String
Elapsedtime(): Long
QUESTION NO: 05
CODE:
package locationClass ;
import java.util.Scanner;
class Location
{
int rows;
int column;
double maxvalue;
}
return l1;
}
}
public class LocationClass {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int rows ;
int column;
System.out.println("Enter rows :");
rows=in.nextInt();
System.out.println("Enter Columns :");
column=in.nextInt();
double[][] arr = new double[rows][column];
System.out.println("Enter array: ");
for (int i=0;i<rows;i++)
{
for (int j=0;j<column;j++)
{
arr[i][j]=in.nextDouble();
}
Location l2=Location.locatelargest(arr);
System.out.println("max value "+l2.maxvalue+" is found at
location["+l2.rows+"]["+l2.column+"]");
UML DAIGRAM:
Location
+row: int
+column: int
+maxvalue: double
Location(int,int)
+locatelargest(double[][]): Location
l1 : Location
Maxvalue
Row
Column
Locatelargest(double [][]):Location