Question

In: Computer Science

Problem 5: (10 pts) Modify the patient class with two overloaded methods to display a bill...

Problem 5: (10 pts) Modify the patient class with two overloaded methods to display a bill for astandard visit based on age. In the first method do not use any parameters to pass in data. If the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard doctors office visit is $125. Build a second method where you pass in a discount rate. If the patient is over 65, then apply the discount rate to a standard rate of $125. Create a main method that calls both of these methods and displays the results

Solutions

Expert Solution

Hi,

Hope you are doing fine. I have coded the above question in java keeping all the conditions and requirements in mind. The line by line explanation is provided using comments that have been highlighted in bold. Before you look at the code, here are a few thing for you to take a special note of:

  • As per the question, the conditions are based on the variable "age" but there is no pinpoint description of age. It is nowhere given if age is a global variable or is an input variable giiven by user or a class instance variable or a static class variable. So, in order to solve the question, I have assumed age to be an instance variable of class patient.
  • The else condition for displayBill() with discount as parameter is not given. I have taken iit the same as the other overloaded method, you may change/remove it as per your requirement.
  • The logic for discount is not clearly given. It is just mentioned that "apply the discount rate to a standard rate of $125". Apply could mean either subtraction or percentage. Since they have mentioned discount rate annd not % i have subtracted it directly from 125. In case, if you want to consider discount as percentage then replace:

System.out.println("Standard vist after discount is $"+(125-discount)); with System.out.println("Standard vist after discount is $"+(125-(125*discount/100)));

Program:

//class patient
public class patient {
   //declaring class attribute age of type int
   int age;
  
   //non parameterized constructor that is initialized when an object for patient is created
   public patient(int age) {
       this.age = age;
   }

   //displayBill() is method to display bill for a standard visit without any input parameters
   public void displayBill()
   {
       //if age is greater than 65
       if (age>65)
       {
           System.out.println("Standard visit is $75");
       }
       else
           System.out.println("Standard visit is $125");
   }
  
   //Overloading the displayBill() method by changing its signature i.e passing a parameter discount of type int
   public void displayBill(int discount)
   {
       //if age is greater than 65
       if(age>65)
           //Here we are subtracting the discount rate from 125
           System.out.println("Standard vist after discount is $"+(125-discount));
       else
           System.out.println("Standard visit is $125");
   }
  
   //main method
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       //creating object p for class patient with age 75
       patient p=new patient(75);
       //calling displayBill() method without parameter
       p.displayBill();
       //calling displayBill() method with parameter
       p.displayBill(100);
   }
}

Executable code snippet:

Output:


Related Solutions

Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and...
Problem 3: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and printing “toString” of every object in the linkedList. Every student object to be printed in a separate line.  deleteStudentByID(long id): delete student object from the list whose ID is matching with the passed parameter.  sortListByID(): sort the linkedlist according to students IDs.  findMarksAverage(): find the average of all marks for all students in the list.  findMinMark(int markIndex): find the student...
For this C++ program, Write and modify the code to compute and display the class average...
For this C++ program, Write and modify the code to compute and display the class average as well as the standard deviation. Your code changes are as follows: 1. The variable “double grade” should be replaced by a two-dimensional array variable “double grade[NUMSTUDENTS][NUMGRADES].” Also replace the variable “double average” by “double average[NUMSTUDENTS].” This is necessary since you need to save the entered grades specially to compute the standard deviations. 2. After completing the display of the average grade of all...
Write a class that has three overloaded static methods for calculating the areas of the following...
Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: - circles - rectangles - cylinders Here are the formulas for calculating the area of the shapes. Area of a circle: Area = π r2, where p is Math.PI and r is the circle's radius Area of a rectangle: Area = Width x Length Area of a cylinder: Area = π r2 h, where p is Math.PI, r is the radius of...
Write a class that has three overloaded static methods for calculating the areas of the following...
Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: - circles - rectangles - cylinders Here are the formulas for calculating the area of the shapes. Area of a circle: Area = π r2, where p is Math.PI and r is the circle's radius Area of a rectangle: Area = Width x Length Area of a cylinder: Area = π r2 h, where p is Math.PI, r is the radius of...
Modify the program 7-5 (pr7-5.cpp) on page 425 by performing the following: 1. Add an overloaded...
Modify the program 7-5 (pr7-5.cpp) on page 425 by performing the following: 1. Add an overloaded constructor that has a parameter for radius. Negative values should result in radius set to 1.0. (see example 7-6 page 427) 2. Add a member function calcCircumference() to compute and return the circle circumference (2 * 3.14 * radius). 3. In main() "circle1" should be instantiated with a value for radius. // This program uses a constructor to initialize a member variable. #include <iostream>...
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store....
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store. • When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8% tax, and return the total due. • When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 8% tax, and return the total due. • When computeBill() receives three parameters, they represent the price...
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store....
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store. • When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8% tax, and return the total due. • When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 8% tax, and return the total due. • When computeBill() receives three parameters, they represent the price...
Java Create a class named Billing that includes three overloaded computeBill() methods for a photo book...
Java Create a class named Billing that includes three overloaded computeBill() methods for a photo book store. main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main()....
What is the output of the following program? Slightly modify the program so that: [Pts. 10]...
What is the output of the following program? Slightly modify the program so that: [Pts. 10] The Parent process calculates the val such a way that its value is 20 and it prints “This is parent process and val = 20”. Also, slightly modify The child process calculates the val such a way that its value is 25 and it prints “This is child process and val = 25”. int main() { int val = 15; int pid; if (pid...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give...
Write in Java Modify the parent class (Plant) by adding the following abstract methods:(The class give in the end of question) a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the vegetable can be used in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT