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
Concept explainers
Textbook Question
Chapter 5.2, Problem 16STQ
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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
can you help me how to test this
Part 1: Test Program
Write a program to test all test cases outlined in the test plan. For each method (unit) being tested, ensure your client program provides output clearly describing the method being tested along with the expected and actual result.
When testing constructors, verify the results by calling an accessor method of the class.
When testing mutators, use the accessor method to verify the state change.
When a test fails (actual does not match the expected), correct the method code, then re-test. Keep in mind that a poorly written test can produce inaccurate test results. If a test fails, ensure you have written the test correctly before modifying your unit code.
Output Requirement
For each method (unit), output the method signature.
For each test, output the following:
Test number
Outcome description
Expected result
Actual result
Leave one blank line between each test.
Sample
StudentGrades(int) Test #1 - Initialize grades array…
Change the classes "Line" and "Matrix" as follows:
a. all static properties of classes should be changed only inside class
methods;
b. select one or more sub methods (if it has not been done before) and
arrange them as static methods.
THE BELOW IS IMPORTANT
Rewrite the above code so that
It has all of the correct access modifiers for good encapsulation.
Your code obeys the principle of encapsulation that obliges you to put each method in the proper class.
Your code uses NO getters and NO additional classes or methods. You are welcome to modify any existing methods (including signatures and bodies) and/or move them between the existing classes.
Your code DOES NOT modify any of the constructors.
Important notes:
You DO NOT have to write a main method.
You DO NOT have to write tests.
You DO NOT have to write Javadocs.
You DO NOT have to write interfaces to encapsulate data structures.
There should be no incorrect syntax or other compile-time errors.
Chapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 5.1 - Consider the program in Listing 5.4 . Suppose you...Ch. 5.1 - Prob. 2STQCh. 5.1 - Prob. 3STQCh. 5.1 - Suppose every species in the world has a peculiar...Ch. 5.1 - Revise the definition of the method writeOutput in...Ch. 5.1 - Revise the definition of the method readInput in...Ch. 5.1 - Revise the definition of the method...Ch. 5.1 - What is the meaning of (int) that appears in the...Ch. 5.1 - Prob. 9STQCh. 5.1 - Define a method called getDensity that could be...
Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.2 - In Listing 5.12, we set the data for the object...Ch. 5.2 - Give preconditions and postconditions for the...Ch. 5.2 - What is an accessor method? What is a mutator...Ch. 5.2 - Give the complete definition of a class called...Ch. 5.2 - Prob. 17STQCh. 5.2 - In the definition of the method in Listing 5.15,...Ch. 5.2 - What is a well-encapsulated class definition?Ch. 5.2 - When should an instance variable in a class...Ch. 5.2 - Prob. 21STQCh. 5.2 - In a class definition, is anything private ever...Ch. 5.2 - In a class definition, is the body of any method...Ch. 5.3 - What is a reference type? Are class types...Ch. 5.3 - When comparing two quantities of a class type to...Ch. 5.3 - Prob. 26STQCh. 5.3 - Write a method definition for a method called...Ch. 5.3 - Given the class Species as defined in Listing...Ch. 5.3 - After correcting the program in the previous...Ch. 5.3 - What is the biggest difference between a parameter...Ch. 5.3 - Prob. 31STQCh. 5.3 - Write an equals method for the class Person...Ch. 5.4 - Rewrite the method drawFaceSansMouth in Listing...Ch. 5 - Design a class to represent a credit card. Think...Ch. 5 - Repeat Exercise 1 for a credit card account...Ch. 5 - Repeat Exercise 1 for a coin instead of a credit...Ch. 5 - Repeat Exercise 1 for a collection of coins...Ch. 5 - Consider a Java class that you could use to get an...Ch. 5 - Consider a class that keeps track of the sales of...Ch. 5 - Consider a class MotorBoat that represents...Ch. 5 - Prob. 8ECh. 5 - Prob. 9ECh. 5 - Prob. 10ECh. 5 - Write a program to answer questions like the...Ch. 5 - Define a class called Counter. An object of this...Ch. 5 - Prob. 3PCh. 5 - Define a Trivia class that contains information...Ch. 5 - Define a Beer class that contains the following...Ch. 5 - Write a grading program for an instructor whose...Ch. 5 - Add methods to the Person class from Self-Test...Ch. 5 - Create a class that represents a grade...Ch. 5 - Write a program that uses the Purchase class in...Ch. 5 - Write a program to answer questions like the...Ch. 5 - Consider a class that could be used to play a game...Ch. 5 - Consider a class BasketballGame that represents...Ch. 5 - Consider a class ConcertPromoter that records the...Ch. 5 - Prob. 9PPCh. 5 - Consider a class Movie that contains information...Ch. 5 - Repeat Programming Project 18 from Chapter 4, but...Ch. 5 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is an object? What is a control?
Starting Out With Visual Basic (7th Edition)
Create a flowchart that shows the necessary steps for making the cookies in the following recipe: Ingredients: ...
Starting Out With Visual Basic (8th Edition)
(Tabular Output) Write a program that utilizes looping to produce the following table of values:
C How to Program (8th Edition)
This program numbers the lines found in a text file. Write a program that reads text from a file and outputs ea...
Problem Solving with C++ (10th Edition)
What is the total serial transfer time for the eight bits in Figure 1-62? What is the total parallel transfer t...
Digital Fundamentals (11th Edition)
Population Data If you have downloaded this books source code (the companion Web site is available at www.pears...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Note: Write a Java program given below Question # 1: Define a class for Students with field name, age, marks. Define getter and setter for all the fields. In the setter method, if age is less than 0, print that Age is less than zero. Similarly, if marks is less than zero or greater than 100, print in correct marks and don’t assign marks to member variable. In the Test class, create student’s object and assign the marks and age to appropriate values. Try assigning incorrect values to check if getter and setter methods work as expected.arrow_forwardGive source code and output alsoarrow_forwardCreate a Right Triangle class that has two sides. Name your class rightTraingle. Code getter and setters for the base and the height. (Remember class variables are private.) The class should include a two-argument constructor that allows the program to set the base and height. The constructor should verify that all the dimensions are greater than 0. before assigning the values to the private data members. If a side is not greater than zero, set the value to -1. The class also should include two value-returning methods. One value-returning method should calculate the area of a triangle, and the other should calculate the perimeter of a triangle. If either side is -1, these functions return a -1. The formula for calculating the area of a triangle is 1/2 * b*h, where b is the base and h is the height. The formula for calculating the perimeter of a triangle is b+h+sqrt (b*b+h*h). Be sure to include a default constructor that initializes the variables of the base, height to -1. To test…arrow_forward
- Need help asap:arrow_forwardDesign a class that holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator methods. Also, write a program that creates three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information. my information: name= doe address= 51 any street age= 19 number= 732 810 9995 friends info: name= ella address= 174 any street age= 22 number= 732 895 3586 friends info: name= meg address= 34 any street age= 20 number= 732 337 5580arrow_forwardPrompt We have learned how to use accessor and mutator methods to access private class member data. It is possible to instead make the class members public, which would allow other programs to directly retrieve and modify the class member data without needing to write the accessor and mutator methods. This is usually considered bad practice. Why do you think that is? What do you think the benefits are to writing accessor and mutator methods instead of just leaving the variables public? Below is the definition for a class called Counter. Define a new method for this class called "findDifference". This method should take another Counter object as an argument and return the difference in the counts between the counter being called and the one passed as an argument. The difference should be given as an absolute value (not returned as a negative). See below the class definition for examples of this method being used. public class Counter {private int count;public Counter() {count =…arrow_forward
- please solve it with java and put screenshots of the codearrow_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_forwardPlease see attached picture. Please send a screenshot of the code (Java programming language only)arrow_forward
- Part (1) Define a class as follow: a. create a class called Student that has four instance variables - a (String) name, a (long) StudentID, a (String) College, and a (double) GPA. b. A constructor that takes student name, StudentID, College and GPA. The constructor sets the class variables to these values . c. Make the instance variable GPA private and provide a mutator method (set) and an accessor method (get) to access this variable. In set method if the GPA negative or grater than 4.00 print an invalid message and do not change the instance variable GPA. d. A method Student_Status () that check the GPA if it is less than 2, display the warning message, otherwise display Normal student. e. A method Print() that displays the name, StudentiD, College and GPA of the student as shown below: Sample output: Enter the Student name: ALİ Ahmed Enter the Student ID: 20180011 Enter the College: Information Technology Enter the GPA: 3.2 Normal student Name: Ali Ahmed Student ID: 2018ee11…arrow_forwardPythonarrow_forward1. Making a class called Day. Two of its variables are month and year. The best type for the year would be? it will be Int. Can you explained it! 2. While unit testing, what is the last step before running the test? The Answer is Implement your class or methods. Please explain! 3. With respect to unit testing, what would it mean for your code to have 100% coverage? This means All class constructors and class methods have tests. Please explainarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY