Introduction To Object Oriented Systems Development
Introduction To Object Oriented Systems Development
Name of Student
Name of Institution
INTRODUCTION TO OBJECT ORIENTED SYSTEMS DEVELOPMENT 2
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
public float getSidelength(){
return sideLength;
}
public float findArea(){
return sideLength*sideLength;
}
public float findPerimeter(){
return 4f*sideLength;
}
public float findSquareSideLength(float perimeter){
return(perimeter/4f);
}
public void summaryPrint(){
System.out.println("shape name: Square");
System.out.println("side length: "+String.valueOf(getSidelength()));
System.out.println("Area: "+String.valueOf(findArea()));
System.out.println("Perimeter: "+ String.valueOf(findPerimeter()));
}
import java.util.Scanner;
public class Circle extends TwoDimensionShape{
private float radius;
public Circle(){
ShapeName("Circle");
setRadius();
summaryPrint();
}
public Circle(float perimeter){
radius = findRadius(perimeter);
summaryPrint();
}
public void setRadius(){
while(true){
try{
Scanner myObj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter radius of Circle: ");
radius = Float.parseFloat(myObj.nextLine());
break;
INTRODUCTION TO OBJECT ORIENTED SYSTEMS DEVELOPMENT 4
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
public float getRadius(){
return radius;
}
public float findArea(){
return pi*radius*radius;
}
public float findPerimeter(){
return 2f*pi*radius;
}
public float findRadius(float perimeter){
return(perimeter/(2f*pi));
}
public void summaryPrint(){
System.out.println("Shape name: Circle");
System.out.println("Radius: "+String.valueOf(getRadius()));
System.out.println("Area: "+String.valueOf(findArea()));
System.out.println("Perimeter: "+ String.valueOf(findPerimeter()));
}
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
public float getSidelength(){
return sideLength;
INTRODUCTION TO OBJECT ORIENTED SYSTEMS DEVELOPMENT 5
}
public float findArea(){
return ((float)Math.sqrt(3)/4f)*sideLength*sideLength;
}
public float findPerimeter(){
return 3f*sideLength;
}
public float findTriangleSideLength(float perimeter){
return(perimeter/3f);
}
public void summaryPrint(){
System.out.println("shape name: Triangle");
System.out.println("side length: "+String.valueOf(getSidelength()));
System.out.println("Area: "+String.valueOf(findArea()));
System.out.println("Perimeter: "+ String.valueOf(findPerimeter()));
}
break;
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
public float getSidelength(){
return sideLength;
}
public float calculateSurfaceArea(){
return 6f*(sideLength*sideLength);
}
public float calculateVolume(){
return sideLength*sideLength*sideLength;
}
public float findCubeSideLength(float surfaceArea){
return((float)Math.sqrt(surfaceArea)/6f);
}
public void summaryPrint(){
System.out.println("shape name: Cube");
System.out.println("side length: "+String.valueOf(getSidelength()));
System.out.println("surfaceAreaArea:
"+String.valueOf(calculateSurfaceArea()));
System.out.println("Volume: "+ String.valueOf(calculateVolume()));
}
}catch(Exception e){
System.out.println("invalid value enter again:");
INTRODUCTION TO OBJECT ORIENTED SYSTEMS DEVELOPMENT 7
}
}
}
public void setRadius(){
while(true){
try{
Scanner myObj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter radius of Cylinder: ");
radius = Float.parseFloat(myObj.nextLine());
break;
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
while(true){
try{
Scanner myObj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter height of Pyramid: ");
height = Float.parseFloat(myObj.nextLine());
break;
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
public void setLength(){
while(true){
try{
Scanner myObj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter Length of Pyramid: ");
length = Float.parseFloat(myObj.nextLine());
break;
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
}catch(Exception e){
System.out.println("invalid value enter again:");
}
}
}
}
case 2:
ThreeDimensionShape threeDShape;
System.out.println("1. Cube \n2. Cylinder\n3. Pyramid\
n4. Exit to main menu\nEnter your choice: ");
int shapeType3d = Integer.parseInt(sc.nextLine());
switch(shapeType3d){
case 1:
System.out.println("1. Find SurfaceArea and
volume \n2. find radius\\side length\nEnter your choice: ");
int finalChoice3d =
Integer.parseInt(sc.nextLine());
if(finalChoice3d ==1){
threeDShape = new Cube();
}else if(finalChoice3d ==2){
System.out.println("Enter the surface
area:");
float SurfaceArea =
Float.parseFloat(sc.nextLine());
threeDShape = new Cube();
}else{
System.out.println("invalid input");
}
break;
case 2:
threeDShape = new Cylinder();
break;
case 3:
threeDShape = new Pyramid();
break;
}
break;
case 3:
exit = true;
break;
default:
System.out.println("invalid input");
}
if(exit){
break;
}
}
}catch(Exception e){
System.out.println("Invalid choice.Enter a correct choice!");
}
}
INTRODUCTION TO OBJECT ORIENTED SYSTEMS DEVELOPMENT 11
Task 5: UML
UML Diagram
INTRODUCTION TO OBJECT ORIENTED SYSTEMS DEVELOPMENT 12
Task 6: Testing
Test case Purpose Expected Result
test fixture Validate the behavior The methods are
of methods expected to behave
correctly.
unit test Run a certain They assert the
proper working of
functionality in the code.
objects.
integration test test the behavior of a The system is
expected to work as
component
intended by the
developer.
Performance tests Ensure the code test Testing does not
runs really fast. affect the efficiency
of the project.
Task 7: Individual
public class Circle {
public Circle() {
radius = 0.0;
}
public Circle(double r) {
radius = r;
}
return radius * 2;
}
// close keyboard
keyboard.close();