Starting from:

$25

IT2650-Assignment 12 Solved

Step 01 - Compile the following code (you can get the file from Blackboard) 
 

 
 

// Class Shape import java.awt.*; 

 

abstract class Shape {    double area;    public abstract void getArea () ; 



 

// Class Circle 

class Circle extends Shape {  

 

   public Circle (double r) {       area = 3.14 * r * r; 

    

   } 

    

   public void getArea () { 

    

      System.out.println("Circle's area = " + area); 

    

   }; 



 

// Class Square class Square extends Shape {  

 

   public Square (double s) {       area = s * s; 

    

   } 

    

   public void getArea () { 

    

      System.out.println("Square's area = " + area); 

    

   }; 



 

public class Assignment11 { 

 

   public static void main(String[] args) { 

    
      System.out.println ("Assignment 12 Written by Matt Weisfeld"); 

       

      Circle circle1 = new Circle(3);  

      Circle circle2 = new Circle(4); 

       

      Square square1 = new Square(2);  

      Square square2 = new Square(5); 

       

      Circle[] circleArray = new Circle[2];  

      Square[] squareArray = new Square[2]; 

       

      circleArray[0] = circle1;        circleArray[1] = circle2; 

       

      squareArray[0] = square1;        squareArray[1] = square2; 

       

      for (int i = 0; i < circleArray.length; i++) { 

       

         circleArray[i].getArea(); squareArray[i].getArea(); 

       

      } 

    

   } 


 

 

Step 02 – Run the code (the output should look something like this) 
 

  

 

Step 03 – Add the code 
 

The code above iterates through the two separate arrays - circleArray and squareArray.  

Your task is to create an array called shapeArray (that holds 4 shapes) and insert the 4 shapes created by the code below, circle1, circle2, square1, square2.  

 

Now, I want you to create code that iterates through the shapeArray and processes any shape. In essence, the code doesn't care which shape it is processing.  

 

All that you need to turn in is your final version of A12. So upload that single file to Blackboard. 

 

Step 04 – When you run the code you will get something like the following output 
 

  

More products