Define a class called Diamond that is derived from either the class ShapeBasics (Listing 8.12) or the abstract class ShapeBase (Listing 8.19) A diamond has the same sort of top half as a Triangle object, and its bottom half is an inverted version of its top half. Define a utility class having public static methods, such as the method skipSpace and other methods that draw horizontal lines, big V’s, and inverted big V’s Recall that Self-Test
Question 31 asked you to describe one method m this class.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Python (4th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Using MIS (10th Edition)
Database Concepts (8th Edition)
- Write a java program Write a class named Employee with name and salary as private data fields. Add a constructor with both parameters. Write a class named Manager which unherits the Employee class. Add an instance variable, named department, of type String and 15 private. Add a constructor in the subclass class and a toString () method that prints the manager's name, department, and salary [Hint: Add a tastanel) method in the super class as well]. Create objects of Manager and Employee dassarrow_forwardJAVA Write the class Rectangle. A Rectangle is a Shape and should have a width and a height. Refers to this : Write an abstract class for Shape. The intended subclasses are Polygon, Circle, Triangle, and Rectangle. All of these will have a name, an area, and a perimeter. (Consider which methods might be abstract.) Add a toString method that will return the information about the Shape, for example: Triangle, Area: 7.5, Perimeter: 12.0arrow_forwardTask: Implement a class ChessPiece with properties: color, isAlive, moveCount, and position (x, y coordinates). Define an abstract move method. Create a Tower subclass that overrides move for specific behavior. Instructions: ChessPiece Class: Properties: String color, boolean isAlive, int moveCount, Position position. Abstract Method: move(int x, int y). Position Class: Contains int x, int y. Tower Subclass: Extends ChessPiece. Overrides move for straight line movement. Deliverable: Source code for ChessPiece, Position, and Tower. Document class functionalities briefly.arrow_forward
- Implement the following using JAVA: a.Design a class named Person and its two subclasses named Student andEmployee. b.Make Faculty and Staff subclasses of Employee. Please note that,● A person has a name, address, phone number, and email address. A student has aclass status (freshman,sophomore, junior, or senior). You can define the status as aconstant.● An employee has office & salary.● A faculty member has office hours and a rank.● A staff member has a title. c. Draw a UML diagram of the system.arrow_forwarda:) Define a Polygon interface that has methods area() and perimeter(). b:) Then implement classes for Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon, which implement this interface, with the obvious meanings for the area() and perimeter() methods. c:) Implement classes, IsoscelesTriangle, Equilateral-Triangle, Rectangle, and Square, which have the appropriate inheritance relationships. d:) Write a simple user interface, which allows users to create polygons of the various types, input their geometric dimensions, and then output their area and perimeter. e:) For extra effort, allow users to input polygons by specifying their vertex coordinates and be able to test if two such polygons are similar. using all a to e parts develop a programarrow_forward-Interface IResearch Scholar has two methods public void teaches (String str) and public void studies (String str). - Define classes JuniorRS and SeniorRs such that JuniorRS implements IResearchScholar and SeniorRS extends JuniorRS. - Class InterAbstrTest extends SeniorRS, and has the main method. An object of JuniorRs invokes the method studies, and an object of SeniorRS invokes methods studies and teaches.arrow_forward
- (B) Add a class named Square.java Give it private attributes double side and String color Make a constructor with two attributes for assigning a value to side and color when the Square is instantiated. • Add getter and setter methods for all of the attributes. Add a method that returns the area of the shape.arrow_forwardJava program * Interfaces 1. Modify the class Rectangle to implement the Comparable interface, as shown in the following UML class diagrams. Apply the required changes in the class’s header.2. Then, in the Rectangle class override the method compareTo(), so if this object’s area is greater than the specified (given through the parameter) object’s area return 1, if it is less than return -1, and 0 otherwise. 3. Create a test class named Test2. Then complete the following tasks: a. Create an ArrayList and add to it 4 Rectangle objects with different width and height values. b. Print out the elements of the ArrayList. c. Sort the elements of the ArrayList using the static method sort of the class java.long.Collections. This would be possible only, if you implemented the method compareTo() correctly in the Rectangle class. d. After sorting the elements of the ArrayList, print the elements again. 4. Run the Test class. Here is the rectangle's class program public class Rectangle extends…arrow_forwardUsing JAVA write a code to: Implement a class Person with a name and a year of birth. Add a class Student that inherits from Person and has a major. Add a class Instructor that inherits from Person and has a salary. For each class, write the needed constructors, getters, setters, and a toString method that stringifies the instance variables in a readable format. Supply a test program that instantiates an instance of each class and exercises each method defined for the class.arrow_forward
- Create a project to play a bunch of games. Add a class that has main() in it. Create an abstract class called Game. Define one instance variable for the name of the game. Define a constructor that takes the name of the game as a parameter and sets it. Define an abstract method called playGame. It takes no arguments and returns void. Create a child class of Game called BoardGame. Rather than implementing playGame, declare BoardGame abstract. Create a child class of BoardGame called Chess or Battleship or Monopoly or whatever board game you want. Implement the playGame with only a message that says the name of the game and that it is being played. Create a child class of Game called CardGame. Rather than implementing playGame, declare CardGame abstract. Create a child class of CardGame for War. Implement the playGame method by with a message that says the game of war is being played. Create a child class of Game called VideoGame. Rather than implementing playGame,…arrow_forwardWrite a program in java Write a class Car that contains the followings attributes: The name of Car The direction of Car (E, W, N, and S) The position of Car (from imaginary zero point) The class has the following members A constructor to initialize the instance variables Turn function to change the direction of Car to one step right side (e.g. if the direction is to E, it should be changed to S and so on. Overload the Turn function to change the direction to any side directly. It should accept the direction as parameter. Move function to change the position of Car away from zero point. It should accept the distance as parameter.arrow_forwardInstructions: Write your answer on a piece of paper with your name on top. Take a picture and submit within the allocated time limit. «interface Payable «abstract Person idno, name, age Student course, tuition, balance public double pay(double amount); Employee department, salary Given the class hierarchy: 1. Define the interface Payable. 2. Define the class Person that implements Payable and encapsulate. Override toString and equals. 3. Define Student and encapsulate. Override toString and equals. Implement pay(). pay() - deducts amount from balance and returns the new balance. 4. Define class Test. Declare an array of 10 Persons. Assume that Employee had already been implemented. Ask the user whether to create a student or an employee object.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education