Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (TCO A) Consider the class Octagon given below: public class Octagon { privat

ID: 3541070 • Letter: 1

Question

1. (TCO A) Consider the class Octagon given below:

public class Octagon
{
    private double side;

    public Octagon()
    {
        side = 1;
    }

    public Octagon(double s)
    {
        side = s;
     }

    public double getSide()
    {
        return side;
     }

    public void setSide(double  d)
    {
        side = d;
     }

    public String toString()
    {
        return "<" + side + ">" ;
    }
}

Write Java code that makes a shallow copy of octagon oct1 in the place indicated in the class Main given below.

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Octagon oct1 =  new Octagon(2.5);

        Octagon oct2 = /* write here Java code that produces a shallow copy */
        System.out.println(oct1 + " " + oct2);
     }
}

Explanation / Answer

import java.util.*;

public class Main
{
public static void main(String[] args)
{
Octagon oct1 = new Octagon(2.5);

Octagon oct2 = oct1
System.out.println(oct1 + " " + oct2);
}
}