Explanation of Solution
Flawed method implementation:
Let us make the assumption that, in the code fragment 1.5 in the textbook the following instance variable “balance” is changed to private visibility.
//Create a main class
public class CreditCard
{
//Declare the instance variable
private double balance;
}
Program:
The following code is the subclass PredatoryCreditcard extended from CreditCard class. While changing the instance variable “balance” to private visibility in main class CreditCard, the following method leads to an error:
//Create a sub class PredatoryCreditCard
public class PredatoryCreditCard extends CreditCard
{
// Override the charge()method from superclass
public boolean charge(double price)
{
//Call inherited method
boolean isSuccess = super...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Data Structures and Algorithms in Java
- I hope you are fine, I want the code for this class .. Even if it is a small part of it, please, I want it for necessity, thanksarrow_forwardConsider the Account class in the below. In the class, the withdraw() method audits whenmoney is withdrawn. In order to test the withdraw() method, a stub should be provided for theaudit object. Implement the stub structure shown in the class diagram and test withdraw()method using the StubAudit class.arrow_forwardAbstract in Java Employee Override the display method in the Person class override the toString() and equals() methods Define method earnings as abstract with a return type of double. Hourly Employee provide the setters and getters of your data members provide call to parent contructors earnings is computed by having the product of the total number of hours worked and the rate. but if the number of hours worked exceeds 40, the rate increases to 150% of the current rate. (ex. rate=200; 150% = 300) override the toString() and equals() methods Note:Class Person is already loaded in this activity. No need to add the class in your code.arrow_forward
- Given a Student class, and UndergradCourse is a true subtype of Course, there is one method called recommend in the Student class: public class Student { public Course recommend(Course pCourseID); } Please evaluate if EACH of the method in UndergradStudent class violates the Liskov Substitution Principle. public class UndergradStudent extends Student { 1. public Course recommend(UndergradCourse pCourseID); 2. public UndergradCourse recommend(Course pCourseID); 3. public UndergradCourse recommend(Object pCourseID); 4. public Course recommend(Course pCourseID) throw SomeCheckedException;arrow_forwardCreate an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle with abstract methods getColor () and getBrand (). Now, create a concrete class Taxi with additional method setDriver (String name) that inherits both Wheel and Vehicle. (Note: Concrete classes don’t have any abstract method)arrow_forwardJAVAarrow_forward
- this is for a python class 9.12 LAB: Product class In main.py define the Product class that will manage product inventory. Product class has three attributes: a product code, the product's price, and the number count of product in inventory. Implement the following methods: A constructor with 3 parameters that sets all 3 attributes to the value in the 3 parameters set_code(self, code) - set the product code (i.e. SKU234) to parameter code get_code(self) - return the product code set_price(self, price) - set the price to parameter price get_price(self) - return the price set_count(self, count) - set the number of items in inventory to parameter count get_count(self) - return the count add_inventory(self, amt) - increase inventory by parameter amt sell_inventory(self, amt) - decrease inventory by parameter amt Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is: Name: Apple Price: 0.40 Count: 3 Ex. If 10…arrow_forwardjava Write a simple class to represent a Student. Each student object should have the following data items: A first natne, a lasl name, a student ID, and a GPA. Think carefully about how you should model this data and write getter (query) and setter (command) methods for each. Override public boolean equals(Object o) so that two student objects that have the same student ID are seen as equalarrow_forwardSolve it in Java Codearrow_forward
- Oops in JAVA code.. Write code of employees and another code too..arrow_forwardCreate a class Animal Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal (String name) //constructor public void makes Sound () with the implementation printing out a generic animal sound. Next, override (add) the makes Sound() method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don't make sounds!) Note, you'll also need a constructor in each of your subclasses which calls super(name) to initialize the common 'name' member of Animal. Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. (you should observe the makeSound method called will be: cat -> from Cat class, dog-> from Dog class, bearded Dragon -> from Animal class ) EC:…arrow_forward4arrow_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