Concept explainers
How would you change the definition of the class DayOfYear in Display 10.4 so that it has two versions of an (overloaded) constructor? One version should have two int formal parameters (one for the month and one for the day) and should set the private member variables to represent that month and day. The other should have no formal parameters and should set the date represented to January 1. Do this without using a constructor initialization section in either constructor.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Java How To Program (Early Objects)
Database Concepts (8th Edition)
Starting Out with Python (4th Edition)
- In this exercise, you are going to build on your Circleclass from the previous exercise. You are going to add 2 method, areaDifference and perimeterDifference. Both methods take a doubleradius of a second circle and return the difference from the current circle. For example, if you create a Circle object with a radius of 4 and call areaDifference(3), you will return the diffence between the area of a circle with radius 4 and the area of a circle with a radius of 3. perimeterDifferencewould be the same. Make sure you create at least one Circle and test and print the results of your methods. given: public class Circle{private double radius;public Circle(double theRadius){radius = theRadius;}// Add a method called area that returns the area of a circle// using Math.PIpublic double area(){return Math.PI*radius*radius;}// Add a method called perimeter that returns the perimeter of a// circle using Math.PIpublic double perimeter(){return Math.PI*2*radius;}}arrow_forwardgood afternoon could you help me by modifying a code with a nicer interface and showing me lines of fields but please modify it yourself.arrow_forwardCan you call a constructor from another constructor? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. Problem Statement# A class can have multiple parameterized constructors which can call each other. You are given a partially completed code of a Car class in the editor. Modify the parametrized constructor which assigns parameters to the required fields. Input# carName, carModel, carCapacity Output# carName, carModel, carCapacity Sample Input# "Ferrari", "F8", "100" Sample Output# "Ferrari", "F8", "100" Part of solution // Car class class Car { // Private Fields private String carName; private String carModel; private String carCapacity; // Default Constructor public Car() { this.carName = ""; this.carModel = ""; this.carCapacity = ""; } // Parameterized Constructor 1 public Car(String name, String model) { this.carName = name; this.carModel = model; } // Parameterized Constructor 2 public…arrow_forward
- Would you mind help me write racer class, sensor class, and timestamp class? (Note: The sensor class can have functions to determine if two sensors are adjacent and calculate the speed between them, while the time stamp class can have functions to calculate the time elapsed between two time stamps.) The class of racer should include : 1. Private data: racer number (int), an unknown number of sensor data. Sensor data includes sensor number (int that starts at 0 for start time; the last sensor is finish line), mile marker for the sensor double) and time stamp for each sensor (when racer passes the sensor) with hour, minute, second and millisecond. (You may want instance variables that holds racer's total race time, total race distance, total race speed.) 2. Default constructor 3. Copy constructor: make sure the code copies any vectors contained in the class 4. Set and get functions for private dat. 5. "get" function that computes and returns the racer's total time to complete…arrow_forwardFor the 'The Chicken class' on the app intelliJ in java. The Chicken class must:• Define three fields called exactly name, pricePerKilo and inStock. The name field must be of type String, the pricePerKilo must be of type int (representing the cost per kilo in pence) and the inStock field must be of type boolean.• Initialise the three fields via a constructor that takes exactly two parameters. The first parameter must be of type String and the second parameter must be of type int. The first parameter must initialise the name field and the second must initialise the pricePerKilo field. The constructor must set the inStock field to true for all Chicken objects. There must be no parameter to the constructor for the inStock field.• Define getters for all three fields using the standard getter naming convention. In particular, note that the getter for the inStock field must be called getInStock rather than isInStock.• Define setters for the pricePerKilo and inStock fields using the standard…arrow_forwardBuild a class called BankAccount that manages checking and savings accounts. Attributes: customer name, the customer's savings account balance, and the customer's checking account balance.Constructor with parameters (self, new_name, checking_balance, savings_balance) deposit_checking(self, amount) - add parameter amount to the checking account balance (only if positive)deposit_savings(self, amount) - add parameter amount to the savings account balance (only if positive)withdraw_checking(self, amount) - subtract parameter amount from the checking account balance (only if positive)withdraw_savings(self, amount) - subtract parameter amount from the savings account balance (only if positive)transfer_to_savings(self, amount) - subtract parameter amount from the checking account balance and add to the savings account balance (only if positive)arrow_forward
- Hi, I am making a elevator simulation and I need help in making the passenger classes using polymorphism, I am not sure what to implement in the comment that says logic. Any help is appreciated. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. This is what i have so far public abstract class Passenger { protected String type; protected int…arrow_forwardI have no idea what to do. Modify the FitnessTracker class, created in Chapter 4 Programming Exercise 3AB, so that the default constructor calls the three-parameter constructor. Use TestFitnessTracker2 to test the new version of the class. import java.time.*;public class FitnessTracker2 {String activity;int minutes;LocalDate date;public FitnessTracker2() {}public FitnessTracker2(String activityParam, int minutesParam, LocalDate dateParam) {}public String getActivity() {}public int getMinutes() {}public LocalDate getDate() {}} import java.time.*;public class TestFitnessTracker2{public static void main(String[] args){ FitnessTracker2 exercise = new FitnessTracker2(); System.out.println(exercise.getActivity() + " " + exercise.getMinutes() +" minutes on " + exercise.getDate()); // code to test constructor added for exercise 3bLocalDate date = LocalDate.of(2020, 8, 20);FitnessTracker2 exercise2 = new FitnessTracker2("bicycling", 35, date); System.out.println(exercise2.getActivity() + " " +…arrow_forwardFor this exercise, you are given a Team superclass with a BaseballTeam and FootballTeam subclass. Take a moment to examine these classes and the instance variables and methods in each. In the TeamTester class, you will see three objects declared and instantiated using the Team, FootballTeam, or BaseballTeam classes. For each object, use a print statement to print out any public method that returns information that is available for that particular object, including the toString. For example, the dolphin object is a FootballTeam object. One of the pieces of information that can be printed is the getTies() method, so you will call that method in your TeamTester file: System.out.println(dolphins.getTies()); Do this for all the methods that each of the objects can call. Hint: Remember, for the program to compile and run, Java looks for methods to exist in certain classes. ================================= public class Team { private String name;private String location;private int…arrow_forward
- Write a class called Circle that contains:a. Three private instance variables: radius (of the type double), color (of thetype String), and area (of type double).b. Two constructors - a default constructor with no argument (default value of radiusis 2.0, and color is Green) and a parameterized constructor, which initializes onlythe radius and the color variables.c. Getter and setter for the radius and color variables.d. Two public methods: calculateArea(), and getPerimeter, which return the areaand perimeter of a circle instance, respectively. Both methods have return.Then write a driver class that tests the Circle class. In the driver class, create two objectsof Circle class, one that tests the default constructor of the Circle class (here no user inputis required) and then get the color, radius, area, and perimeter of that object and displaythem. The second object should test the parameterized constructor (here you need to ask userto give you input to initialize the class variables).…arrow_forwardWrite a complete program for the description given below. Consider a Billing class that implements an interface Payable having a method getTotalPayment Amount(). Besides this, you have a Doctor class with private instance variables (docID, docName, and docFee) and a public getDoc() method, Patient class with private instance variables (pName, pID. pDisease), Medicine class with private instance variables (medID, medName, medQty, medPrice), and Medical Test class with private instance variables (testID, testName, testPrice). Each of these classes has the toString() method to display the information of its object. The Billing class is having "Has A" relationship with the other four classes (Doctor, Patient, Medicine, and MedicalTest) mentioned above. The getPayment Amount() method of Billing class returns the total billing amount that includes doc fee, medicine cost, and medical test fee that a patient has to pay. After implementing these classes, you are required to do the following in…arrow_forwardFor this lab task, you will work with classes and objects. Create a class named text that works similar to the built-in string class. You will need to define a constructor that can be used to initialize objects of this new class with some literal text. Next, define three methods: to_upper() that will convert all characters to uppercase, reverse() that will reverse the text and length() that will return the length of the text. After you have completed this part, copy the following mainfunction to your code and check if the implementation is correct. int main() { text sample = "This is a sample text"; cout << sample.to_upper(); // This should display "THIS IS A SAMPLE TEXT" cout << endl;cout << sample.reverse(); // This should display "txet elpmas a si sihT"cout << endl; cout << sample.length(); // This should display 21 }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