Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that: 1. Has an object class named L3XXxxRegOct that is a concrete subclass of the Shape class from Chapter 4 (Comparable

image text in transcribedimage text in transcribedimage text in transcribedWrite a Java program that: 1. Has an object class named L3XXxxRegOct that is a concrete subclass of the Shape class from Chapter 4 (Comparable electronic version in the sample code.) that represents an Regular Octagon. 2. The class must include appropriate implementations of the required abstract methods. 3. The class must override toString() in a descriptive fashion, displaying any instance variables and the area, each labeled unambiguously. The string must easily fit on one line of the console. 4. Add constructors/accessors/mutators for all instance variables. 5. Retain the default Comparable logic for Shape and L3XXxxRegOct. 6. Performs the following tasks in the main() of L3XXxxRegOct: a. Declare and instantiate an instance of an L3XXxxRegOct array and insert at least 20 of your octagon instances, each constructed with a random (double) dimension. b. Display the contents of the array after the octagons have been inserted, one instance per line. Precede the output with a descriptive heading. c. Sort the octagons in place in ascending order using a static method you write named lab3Sort that takes a Comparable array as its lone parameter. (More details below.) d. Display the sorted array contents, one instance per line, with a descriptive heading and whitespace separation from the unsorted group. Your sort algorithm can be any standard sort that is neither Bubble Sort nor a Bogosort.

shape.java image text in transcribed
1 public class Shape 2 { 3 public double area ( ) 4 { 5 return -1; 6 } 7 } 6 9 1 public class Circle extends Shape 2 { 3 public Circle( double rad ) 4 { radius rad; } 5 public double area( ) 7 { return Math.PI * radius * radius; } 8 public double perimeter( ) 0 { return 2 * Math.PI * radius; } 1 2 public String toString() 3 { return "Circle: + radius; } 4 5 private double radius; 6 } 7 8 public class Rectangle extends Shape 9 { 0 public Rectangle( double len, double wid ) 1 { length = len; width = wid; } Procedure: Write a Java program that: 1. Has an object class named L3XXxxRegoct that is a concrete subclass of the Shape class from Chapter 4 (Comparable electronic version in the sample code.) that represents an Regular Octagon. 2. The class must include appropriate implementations of the required abstract methods. 3. The class must override toString() in a descriptive fashion, displaying any instance variables and the area, each labeled unambiguously. The string must easily fit on one line of the console. 4. Add constructors/accessors/mutators for all instance variables. 5. Retain the default Comparable logic for Shape and L3XXxxRegOct. 6. Performs the following tasks in the main() of L3XXxxRegOct: a. Declare and instantiate an instance of an L3XXxxRegoct array and insert at least 20 of your octagon instances, each constructed with a random (double) dimension. b. Display the contents of the array after the octagons have been inserted, one instance per line. Precede the output with a descriptive heading. c. Sort the octagons in place in ascending order using a static method you write named lab3Sort that takes a comparable array as its lone parameter. (More details below.) d. Display the sorted array contents, one instance per line, with a descriptive heading and whitespace separation from the unsorted group. Your sort algorithm can be any standard sort that is neither Bubble Sort nor a Bogosort. Make an honest attempt to code a sort you already know rather than just copying it if possible, but it must be coded by you (i.e. calling a library method to do your sort for you is not acceptable.) 2:18 codereview.stackexchange.com appreciated! Shape.java /* nhgrif says: Phrancis ready for inheritance/polymorphism? * Given the following abstract class: public abstract class Shape { public abstract double areal); public abstract double perimeter(); Implement a Circle, Triangle, and Rectangle cl * Ex: public class Circle extends Shape ... etc */ public abstract class Shape { public abstract double area(); public abstract double perimeter(); } Rectangle.java public class Rectangle extends Shape { private final double width, length; //sides public Rectangle() { this(1,1); } public Rectangledouble width, double lengt this.width = width; this. length = length; } @Override public double area() { // A = W return width length; R + 38 1 public class Shape 2 { 3 public double area ( ) 4 { 5 return -1; 6 } 7 } 6 9 1 public class Circle extends Shape 2 { 3 public Circle( double rad ) 4 { radius rad; } 5 public double area( ) 7 { return Math.PI * radius * radius; } 8 public double perimeter( ) 0 { return 2 * Math.PI * radius; } 1 2 public String toString() 3 { return "Circle: + radius; } 4 5 private double radius; 6 } 7 8 public class Rectangle extends Shape 9 { 0 public Rectangle( double len, double wid ) 1 { length = len; width = wid; } Procedure: Write a Java program that: 1. Has an object class named L3XXxxRegoct that is a concrete subclass of the Shape class from Chapter 4 (Comparable electronic version in the sample code.) that represents an Regular Octagon. 2. The class must include appropriate implementations of the required abstract methods. 3. The class must override toString() in a descriptive fashion, displaying any instance variables and the area, each labeled unambiguously. The string must easily fit on one line of the console. 4. Add constructors/accessors/mutators for all instance variables. 5. Retain the default Comparable logic for Shape and L3XXxxRegOct. 6. Performs the following tasks in the main() of L3XXxxRegOct: a. Declare and instantiate an instance of an L3XXxxRegoct array and insert at least 20 of your octagon instances, each constructed with a random (double) dimension. b. Display the contents of the array after the octagons have been inserted, one instance per line. Precede the output with a descriptive heading. c. Sort the octagons in place in ascending order using a static method you write named lab3Sort that takes a comparable array as its lone parameter. (More details below.) d. Display the sorted array contents, one instance per line, with a descriptive heading and whitespace separation from the unsorted group. Your sort algorithm can be any standard sort that is neither Bubble Sort nor a Bogosort. Make an honest attempt to code a sort you already know rather than just copying it if possible, but it must be coded by you (i.e. calling a library method to do your sort for you is not acceptable.) 2:18 codereview.stackexchange.com appreciated! Shape.java /* nhgrif says: Phrancis ready for inheritance/polymorphism? * Given the following abstract class: public abstract class Shape { public abstract double areal); public abstract double perimeter(); Implement a Circle, Triangle, and Rectangle cl * Ex: public class Circle extends Shape ... etc */ public abstract class Shape { public abstract double area(); public abstract double perimeter(); } Rectangle.java public class Rectangle extends Shape { private final double width, length; //sides public Rectangle() { this(1,1); } public Rectangledouble width, double lengt this.width = width; this. length = length; } @Override public double area() { // A = W return width length; R + 38

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions