Computing代写 | The Context of Data Linkage

Java基础,学习如何声明使用抽象函类、抽象方法,继承抽象类、重写方法。

Introduction

 As was taught earlier in the semester, Java allows the declaration of both classes and interfaces. Being an object-oriented programming language, it also allows classes/interfaces to extend/implement others through a concept called inheritance.

 

An interface can be thought of as a contract. Any concrete class that implements an interface must provide declarations for methods contained in it. An abstract class is similar to an interface, in that it requires its concrete subclasses to provide declarations for its abstract methods. Abstract classes, though, can also contains fields and constructors.

 

The power of both interfaces and abstract classes is that types can be related, making an assertion that subtypes have certain methods in common. For example, AbstractList is an abstract class held in the java.util package. It contains a get() method that is marked as abstract. This means that its subclasses, such as ArrayList, must provide a declaration for that method.

 

One can declare a field of type AbstractList, and will know for a fact that any reference it holds has a get() implementation. This allows an existing implementation to be swapped out for a potentially better one, and not break existing code.

 

Description

 

Your task for this homework is to create three classes — Polyhedron, Tetrahedron, and Icosahedron. Polyhedron is an abstract class, of which both Tetrahedron and Icosahedron extend. Field, constructor, and method declarations for each are listed below.

Page 1 of 5 – Problem Solving and Object-Oriented Programming (CS18000)

 

Polyhedron

 Fields

Name Type Access Modifier
sideLength double private

Constructor

Parameters Access Modifier
double sideLength public

 Methods

Name Return Type Parameters Access Modifier
getSurfaceArea1 double None public
getVolume1 double None public
getSideLength double None public
setSideLength void double sideLength public
equals boolean Object anObject public
toString void None public

 Constructor

Parameters Access Modifier
double sideLength public

 Methods

Name Return Type Parameters Access Modifier
getSurfaceArea double None public
getVolume double None public
equals boolean Object anObject public
toString void None public

 

Icosahedron

 Supertype

Name
Polyhedron

 Constructor

Parameters Access Modifier
double sideLength public

 Methods

Name Return Type Parameters Access Modifier
getSurfaceArea double None public
getVolume double None public
equals boolean Object anObject public
toString void None public

 

Requirements

You are required to declare the three classes mentioned above – Polyhedron, Tetrahedron, and Icosahedron. In order for your work to be graded correctly, please follow the specifications outlined above, and in the JavaDoc.

Submission Instructions

Submit both Polyhedron.java, Tetrahedron.java , and Icosahedron.java to Vocareum through Blackboard. Keep in mind that only your last submission will be considered. Test cases will be used to grade your work.

Grading Rubric

  • Polyhedron class (40 points)
    • 5 points
      • Making Polyhedron abstract
      • Declaring the sideLength field
    • 5 points for each constructor/method declaration (7 total)
  • 30 points
    • Tetrahedron class
      • 3 points for extending Polyhedron
      • 4 points for each constructor/method declaration (5 total)
    • Icosahedron class
      • 3 points for extending Polyhedron
      • 4 points for each constructor/method declaration (5 total)