
Concept explainers
(JAVA
Demonstrate the Object Oriented Programming concepts (Inheritance, Polymorphism, and Encapsulation).
create a class called Shape. which has a color field and methods for getting and setting the color for each shape, as well as a method for calculating the area of the shape. The Circle, Square, and Rectangle classes are the shapes to include where they inherit from Shape and implement their own versions of the getArea() and display() methods. The Main class creates instances of all three classes and calls their display() methods, demonstrating polymorphism. The color field in the Shape class is encapsulated, and it is accessed through getter and setter methods.
Here is a sample output for this project:
Shape: Circle
Color: Red
Radius: 5.0
Area: 78.53981633974483
++++++++++++++++++++
Shape: Rectangle
Color: Blue
Width: 3.0
Height: 4.0
Area: 12.0
++++++++++++++++++++
Shape: Square
Color: Yellow
Width: 4.0
Area: 16.0

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 6 images

- Write a simple cash register class. (Use Java) Each cash register should keep track of the number of items checked out and the total cash in the register. We are only concerned with the number of items to check out and their prices. No need to handle item names, SKUs, taxes, etc... It should have the following methods (use static when appropriate): checkout( ) Takes two forms. If there is only one parameter that is the cash received and there is only one item checked out. If it has two parameters, the first parameter should have the number of items checked out and the second parameter is the price per item. cashout( ) Reset the number of items and total cash to zero for a cash register getItems( ) Returns the number of items in the cash register getTotalCash( ) Returns the total cash in the cash register getAveragePricePerItem( ) Returns the average price per item checked out by the cash register getRegisterCount( ) Returns the number of cash registers created getAllItems(…arrow_forward1) Demonstrate the use of overloaded methodseach has three primitive parameters two methods computes and returns the product to the calling method for printing one method computes and prints the product; does not return a result Note:- Please type and execute the above java program and also need an output for this program as soon as possible. (type a java program)arrow_forward(Java) Question 1 Explain the answer step-by-step and include verbal explanation. Thank you! What is the difference between an interface and an abstract class? What advantage does an interface offer over an abstract class?arrow_forward
- Instructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…arrow_forward(Java) Q2 Explain the answer by including verbal explanation. Thank you! 2. Information Hiding a. Fill in the missing parts of the information hiding definition: hiding the ___________ that are most likely to _________ (a.k.a. data hiding) b. Give two reasons that we should always make our class member variables private. Reason 1: Reason 2arrow_forward(Java) Q3 Explain the answer step-by-step . Include verbal explanation. Thank you! The below class pertains to questions 3: public class Address { private int number; private String street;}3. Add the following methods to the Address class: a. a toString method b. two mutator methods - setNumber and setStreet c. two accessor methods - getNumber and getStreetarrow_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





