Concept explainers
Give the complete definition of a class called Person that has two instance variables, one for the person’s name and the other for the person’s age. Include accessor methods and mutator methods for each instance variable. Also, include a method that sets both the name and age of a person. There are no other methods.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (7th Edition)
Starting Out With Visual Basic (8th Edition)
C How to Program (8th Edition)
Problem Solving with C++ (10th Edition)
Digital Fundamentals (11th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- Given the following class definition , what is the output of the shown main method?arrow_forwardI need to override the toString() method with my own, however I am not sure how to reference back to the parameters for the constructor of the class. I've included my code below. I even tried giving the class instance variables of the same name, however the error said the code was "unreachable." What am I doing wrong? /** * Superclass for the different types of appointments. * TODO: Appointments have a description & date MM/DD/YYYY * TODO: method: occursOn(int year, int month, int day); * 4 method constructor: year, month, day, description */ public class Appointment { /** * the constructor method for an Appointment. * * @param year - the year of the appointment. * @param month - the month of the appointment. * @param date - the day of the appointment. * @param description - a short description of the appointment. */ publicAppointment(intyear, intmonth, intdate, Stringdescription){ } /** * Method to return a string representation of the appointment. * Will be inherited by the…arrow_forwardis this just for the candidate class or is the election class included?arrow_forward
- Write 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_forwardI need to figure out how to call a method that is located in a different class. For example, I am trying to make a tax calculator that multiplies a payers income by a corporate rate. However, I cannot figure out how to call the income method. Nothing I have tried is working. Is there any chance you can guide me? I am just trying to make this equation work. Is there something else that is stopping this from working?arrow_forwardConsider 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_forward
- Consider 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_forwardElaborate the connection of Class and Interface by inserting actual code in the answerarrow_forwardCan we have two methods in a class with the same name?arrow_forward
- Is this overload constructor? But what is behavior methods? Do I need to add walk, feed and bark into the code? See code below: Overload constructor? public String getName() {return name;}public String getBreed() {return breed;}public int getAge() {return age;} package dog1; public class Dog1 { String name;String breed;int age;public Dog1(String name, String breed, int age) { this.name = name;this.breed = breed;this.age = age;}public String getName() {return name;}public String getBreed() {return breed;}public int getAge() {return age;}@Overridepublic String toString() {return ("My name is " +this.getName()+".\nMy breed and age are: "+this.getBreed()+","+this.getAge());}public static void main(String[] args) {Dog1 chico = new Dog1("Chico", "Pitbull",5);System.out.println(chico.toString());}} How can I add walk, feed and bark?arrow_forwardWhat is method overloading? Is it permissible to define two methods that have the same name but different parameter types? Is it permissible to define two methods in a class that have identical method names and parameter lists, but different return value types or different modifiers?arrow_forward(Java) Identify the true statements, select all that apply: -Setters and getters are not required for public instance variables -Every private instance variable in a class definition must have a mutator method -A getter method has the same return-type as the field it retriees and takes no paramaters -A setter method is a return-type void and takes a parameter of tehe same type as its fieldarrow_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