Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 3PP
Program Plan Intro
Bill details
Program Plan:
Filename: Billing.java
- • Define the “Billing.java” class.
- • Declare the required variables.
- • Define the default constructor, and constructor for the class.
- • Define the accessor and mutator methods.
- • Define the “writeOutput” method.
- ○ Call the “writeOutput” method with different doctor and patient objects.
- • Define the “equals” method.
- ○ Return Boolean value.
Filename: Doctor.java
- • Define the “Doctor.java” class which extends from the “Person” class.
- • Declare the required variables.
- • Define the constructor for the class.
- • Define the accessor and mutator methods.
- • Define the “writeOutput” method.
- ○ Display the doctor name, specialization, and visit fee on the output screen.
- • Define the “equals” method.
- ○ Return Boolean value.
Filename: Patient.java
- • Define the “Patient.java” class which extends from the “Person” class.
- • Declare the required variables.
- • Define the default constructor, and constructor for the class.
- • Define the accessor and mutator methods.
- • Define the “writeOutput” method.
- ○ Display the patient name, and ID on the output screen.
- • Define the “equals” method.
- ○ Return Boolean value.
Filename: Demo.java
- • Define main function.
- ○ Create the objects for “Doctor”, “Patient”, and “Billing” classes and pass the input value to the respective methods.
- ○ Call the “writeOutput” method with “Billing” object “b1”.
- ○ Call the “writeOutput” method with “Billing” object “b2”.
- ○ Calculate the visit fees for first and second doctors.
- ○ Add the fees and stored it in a “total” variable.
- ○ Display the total amount.
- ○ Compare the “b1” and “b2” values then print Boolean result.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a java program that has:A class University that has:- Three private instance variables named firstName, lastName, and id- A constructor to initialize the three instance variables- A toString method to return: “Welcome,” + firstName +” “ + lastName + “Your ID is ” + id- AccessorsA subclass Employee that has:- Five additional private instance variables named department, rate, bonus, hours, and salary- An appropriate constructor to use constructor of superclass in defining those of the subclass- A method named compteSalary ( ) to return salary- A method named computeBonus ( ) to return bonus- Accessors
A subclass Staff that:- Overrides computeBonus ( ) such that if hours are greater than 40, there will be %10 bonus for each additional houradded to salary- Overrides compteSalary ( ) such that salary = (rate * hours) + bonus- Overrides toString method to add department and salary into the outputA subclass Faculty that:- Overrides computeBonus ( ) such that if hours are greater than…
a) Implement a class Point with three attributes, x, y, and z.b) Implement an init method with an optional parameter type: 1) Set the default value of x, y, and z to 0.c) Implement a display method to print the values of x, y, and z as the example output below.d) Instantiate two objects of type Point, one with arguments,1, 2, and 3, and the other one without any arguments.e) Call display() to print x, y, and z.
Example Output(x, y, z): (1, 2, 3)(x, y, z) : (0, 0, 0)
Consider a class BankAccount that has • Two attributes i.e. accountID and balance and• A function named balanceInquiry() to get information about the current amount in the account Derive two classes from the BankAccount class i.e. CurrentAccount and the SavingsAccount. Both classes (CurrentAccount and SavingsAccount) inherit all attributes/behaviors from the BankAccount class. In addition, followings are required to be the part of both classes• Appropriate constructors to initialize data fields of base class• A function named amountWithdrawn(amount) to withdraw certain amount while taken into account the following conditionso While withdrawing from current account, the minimum balance should not decrease Rs. 5000o While withdrawing from savings account, the minimum balance should not decrease Rs. 10,000• amountDeposit(amount) to deposit amount in the accountIn the main() function, create instances of derived classes (i.e. CurrentAccount and SavingsAccount) and invoke their respective…
Chapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 8.1 - Prob. 1STQCh. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Can a derived class directly access by name a...Ch. 8.1 - Can a derived class directly invoke a private...Ch. 8.1 - Prob. 6STQCh. 8.1 - Suppose s is an object of the class Student. Base...Ch. 8.2 - Give a complete definition of a class called...Ch. 8.2 - Add a constructor to the class Student that sets...Ch. 8.2 - Rewrite the definition of the method writeoutput...
Ch. 8.2 - Rewrite the definition of the method reset for the...Ch. 8.2 - Can an object be referenced by variables of...Ch. 8.2 - What is the type or types of the variable(s) that...Ch. 8.2 - Prob. 14STQCh. 8.2 - Prob. 15STQCh. 8.2 - Consider the code below, which was discussed in...Ch. 8.2 - Prob. 17STQCh. 8.3 - Prob. 18STQCh. 8.3 - Prob. 19STQCh. 8.3 - Is overloading a method name an example of...Ch. 8.3 - In the following code, will the two invocations of...Ch. 8.3 - In the following code, which definition of...Ch. 8.4 - Prob. 23STQCh. 8.4 - Prob. 24STQCh. 8.4 - Prob. 25STQCh. 8.4 - Prob. 26STQCh. 8.4 - Prob. 27STQCh. 8.4 - Prob. 28STQCh. 8.4 - Are the two definitions of the constructors given...Ch. 8.4 - The private method skipSpaces appears in the...Ch. 8.4 - Describe the implementation of the method drawHere...Ch. 8.4 - Is the following valid if ShapeBaSe is defined as...Ch. 8.4 - Prob. 33STQCh. 8.5 - Prob. 34STQCh. 8.5 - What is an advantage of having the main...Ch. 8.5 - What Java construct allows us to define and...Ch. 8 - Consider a program that will keep track of the...Ch. 8 - Implement your base class for the hierarchy from...Ch. 8 - Draw a hierarchy for the components you might find...Ch. 8 - Suppose we want to implement a drawing program...Ch. 8 - Create a class Square derived from DrawableShape,...Ch. 8 - Create a class SchoolKid that is the base class...Ch. 8 - Derive a class ExaggeratingKid from SchoolKid, as...Ch. 8 - Create an abstract class PayCalculator that has an...Ch. 8 - Derive a class RegularPay from PayCalculator, as...Ch. 8 - Create an abstract class DiscountPolicy. It should...Ch. 8 - Derive a class BulkDiscount from DiscountPolicy,...Ch. 8 - Derive a class BuyNItemsGetOneFree from...Ch. 8 - Prob. 13ECh. 8 - Prob. 14ECh. 8 - Create an interface MessageEncoder that has a...Ch. 8 - Create a class SubstitutionCipher that implements...Ch. 8 - Create a class ShuffleCipher that implements the...Ch. 8 - Define a class named Employee whose objects are...Ch. 8 - Define a class named Doctor whose objects are...Ch. 8 - Create a base class called Vehicle that has the...Ch. 8 - Create a new class called Dog that is derived from...Ch. 8 - Define a class called Diamond that is derived from...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PPCh. 8 - Prob. 4PPCh. 8 - Create an interface MessageDecoder that has a...Ch. 8 - For this Programming Project, start with...Ch. 8 - Modify the Student class in Listing 8.2 so that it...Ch. 8 - Create a JavaFX application that uses a TextField...Ch. 8 - Prob. 10PP
Knowledge Booster
Similar questions
- Define a class named Doctor whose objects are records for a clinic’s doctors. Derive this class from the class Person given in Listing 8.1. A Doctor record has the doctor’s name—defined in the class Person—a specialty as a string (for example Pediatrician, Obstetrician, General Practitioner, and so on), and an office-visit fee (use the type double). Give your class a reasonable complement of constructors and accessor methods, and an equals method as well. Write a driver program to test all yourmethods.arrow_forwardConsider the following class Date, which represents a date using three ints for month, day and year: class Date { private: int month; int day; int year; public: Date() { month = day = year = 0; } Date(int m, int d, int y) { month = m; day = d; year = y; } bool operator==(Date); bool operator<(Date); }; Write an implementation for both overloaded operators. == should return true if the Date objects are equivalent and false if not. < should return true if the Date of the calling object (left object) comes before the parameter Date object (right object) and false if not. You may assume that all objects of class Date are valid, i.e. month is between 1 and 12, inclusive; day contains an appropriate day for the given month, and year can be anything. You do not need to demonstrate calling these operators.arrow_forwardWrite a class in Java , named Patient that has fields for the following data: First name, middle name, and last name Address, city, state, and ZIP code Phone number Name and phone number of emergency contact The patient class should have a constructor, accessor, and mutator that accept an argument for each field.arrow_forward
- Consider the case of a shop that sells CDs in cash. The CDs are of three types: Movie CDs, Software CDs and Music CDs. For each of the following CD types, the required attributes are:Movie CD: Movie Title, Year of Release, Lead Actor Name, CD price and CD quantitySoftware CD: Software Name, Edition, Year of Release, CD price and CD quantityMusic CD: Album Title, Year of Release, Number of Songs, Format, CD price and CD quantity All objects of the classes cannot change their state once they are instantiated. How will you implement this?arrow_forwardwrite the following 3 classes for the Java program so that this program produces the sample output shown at the end of Main. ElectricCar: a vehicle with a limited range. So it must be a subclass of Vehicle, and it must implement LimitedRange. Thus it needs an instance variable for its range, and a travel method (required by Vehicle. Please use @Override) that outputs "Zoom!" if it has enough range to go the distance specified (and update its range). It must have a constructor with 3 arguments as called by main. It also needs a getCurrentRange method as required by LimitedRange (use @Override for this too). Motorboat: a vehicle with a limited range. So it is similar to ElectricCar, but it outputs "Wisshhh!" when it goes. Sailboat: a vehicle that doesn't have a limited range. So it is a subclass of Vehicle, but doesn't implement LimitedRange. It can go any distance, and outputs "Weee!" when it travels. Code: class Main { publicstaticvoid main(String[] args) { Vehicle[]…arrow_forwardWrite a class named Person with data attributes for a person’s name, address, and telephonenumber. Next, write a class named Customer that is a subclass of the Person class. TheCustomer class should have a data attribute for a customer number, and a Boolean data attributeindicating whether the customer wishes to be on a mailing list. Demonstrate an instance of theCustomer class in a simple program.arrow_forward
- Given the base class Book, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a print_info() method that overrides the Book class' print_info() method by printing not only the title, author, publisher, and publication date, but also the edition and number of volumes. Ex: If the input is: The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe James W. Guthrie Watson-Guptill 2001 2nd 1 the output is: Book Information: Book Title: The Hobbit Author: J. R. R. Tolkien Publisher: George Allen & Unwin Publication Date: 21 September 1937 Book Information: Book Title: The Illustrated Encyclopedia of the Universe Author: James W. Guthrie Publisher: Watson-Guptill Publication Date: 2001 Edition: 2nd Number of Volumes: 1 python code to be used: class Book: def __init__(self, title, author, publisher, publication_date):…arrow_forwardImplement the following concepts by constructing suitable classes in Java -a. Constructorsb. Constructor Overloadingc. Function Overloadingd. Function Overridinge. InheritanceCreate a class Person - Field - Name, Birthdate, Contact no and Mail idMethods - Constructor, accept and displayClass Employee - Inherits the Person classFields : Emp ID, grade, basic salary, Gross Salary, HRA (House Rent Allowance), TA (TravelingAllowance), DA (Dearness Allowance)Given:Grade Basic TAA 8000 2000B 7000 1500C 6000 1000D 5000 500Calculate Gross Salary :Gross Salary = Basic + HRA (20% of Basic) + DA (50% Basic) + TAe.g if Basic = 8000TA = 2000HRA = 20% of 8000 = 1600DA = 50 % of 8000 = 4000Gross = 8000 + 2000 + 1600 + 4000 = 15600Optional : you can implement increment function in which you can change grade of an employee andrecalculate salary with new gradearrow_forwardneed help understanding this in java. Given main() and a base Book class, define a derived class called Encyclopedia with member methods to get and set private fields of the following types: String to store the edition int to store the number of pages Within the derived Encyclopedia class, define a printInfo() method that overrides the Book class' printInfo() method by printing the title, author, publisher, publication date, edition, and number of pages. Ex. If the input is: The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe Ian Ridpath Watson-Guptill 2001 2nd 384 the output is: Book Information: Book Title: The Hobbit Author: J. R. R. Tolkien Publisher: George Allen & Unwin Publication Date: 21 September 1937 Book Information: Book Title: The Illustrated Encyclopedia of the Universe Author: Ian Ridpath Publisher: Watson-Guptill Publication Date: 2001 Edition: 2nd Number of Pages: 384 Note: Indentations use 3…arrow_forward
- We have a parking office class for an object-oriented parking management system using java Add(implement) a method to the Parking Office class to return the collection of permit ids for a specific customer (getPermitIds(Customer)) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getPermitIds(Customer) method as mentioned above Explain your code in a few words Important- We have a method to return a collection of permit ids (getPermitIds), what we need is a method to return the collection of permit ids for a specific customer (getPermitIds(Customer))arrow_forwardConsider the following Student Class An. EngineeringStudent "is-a" Student whose major is Engineering. In additional to the name, number of credit hours, and GPA, an Engineering electrical, computer, etc. Write the complete defoe the Engineeringstudent class including the implementation of the methods.arrow_forwardWrite a JAVA program to model the kinds of people one finds in a university. The categories are students, teachers and teaching assistant (TAs). All these categories are kinds of Person (Person is abstract class. A teaching assistant (TA) is a student and a teacher as well. A person has a name (string). A student has grade point average GPA (between 0 to 4), the teacher has the number of scholarly papers he/she has published and the teacher assistant has the number of courses he/she assists. All the classes contain constructors with default arguments to fill all data spaces. Provide display method to print all data members of an object on the screen. Classes also contain a function called isSuccessful(). Students with a GPA over 3.5 are considered successful. This function returns true if someone is successful or false if not. In main(), define an array of Person class, which can point to students, teachers and teacher assistants. The program first asks the kind of person and then lets…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning