Explanation of Solution
a.
Method heading for each method:
- • Method heading for access method of each attribute:
- ○ Access method for person first name is “public String getPersonFirstName()”.
- ○ Access method for person last name is “public String getPersonLastName()”.
- ○ Access method for person email address name is “public String getPersonEmailAddress()”...
Explanation of Solution
b.
Preconditions and postconditions of each method:
- • Precondition and postcondition of access method for each attribute.
- ○ For method “getPersonFirstName()”:
- ■ Precondition: None
- ■ Postcondition: Returns the first name of given person.
- ○ For method “getPersonLastName()”:
- ■ Precondition: None
- ■ Postcondition: Returns the last name of given person.
- ○ For method “getPersonEmailAddress()”:
- ■ Precondition: None
- ■ Postcondition: Returns the email address of given person.
- ○ For method “getPersonTelephoneNumber()”:
- ■ Precondition: None
- ■ Postcondition: Returns the telephone number of given person.
- ○ For method “getPersonFirstName()”:
- • Precondition and postcondition of “changeEmailAddress(String nEmail)” method...
Explanation of Solution
c.
Test class for some Java statement:
//Create object "p1" for "PersonAddress" class
PersonAddress p1 = new PersonAddress();
//Create object "p2" for "PersonAddress" class
PersonAddress p2 = new PersonAddress();
//Create object "p3" for "PersonAddress" class
PersonAddress p3 = new PersonAddress();
//Set values for "p1" by calling method "setPersonAddress"
p1.setPersonAddress("John", "Merry", "john123@aaa.com", "123-4567");
//Set values for "p2" by calling method "setPersonAddress"
p2.setPersonAddress("John", "Merry", "jr@ccc.com", "123-7654");
//Set values for "p3" by calling method "setPersonAddress"
p3.setPersonAddress("Jansi", "Rose", "htr@aaa.com", "333-4444");
//Display the statement
System.out.println("Values of attributes for person 1.");
//Display person "p1" first name by calling method "getPersonFirstName"
System.out.println("First Name: " + p1.getPersonFirstName());
//Display person "p1" last name by calling method "getPersonLastName"
System.out.println("Last Name: " + p1.getPersonLastName());
//Display person "p1" email address by calling method "getPersonEmailAddress"
System.out.println("Email Address: " + p1.getPersonEmailAddress());
//Display person "p1" telephone number by calling method "getPersonTelephoneNumber"
System.out.println("Telephone Number: " + p1.getPersonTelephoneNumber());
System.out.println();
//Display the given statement
System...
Explanation of Solution
d.
Implementation of class:
PersonAddress.java:
//Import package
import java.util.Scanner;
//Define class "PersonAddress"
public class PersonAddress
{
//Declare required variables in "private" access specifier
private String first_Name;
private String last_Name;
private String email_addr;
private String telephone_number;
//Set value for "PersonAddress" class
public void setPersonAddress(String f, String l, String e, String p)
{
//Assign value to given instance variables
first_Name = f;
last_Name = l;
email_addr = e;
telephone_number = p;
}
//Access method for person first name
public String getPersonFirstName()
{
//Returns person first name
return first_Name;
}
//Access method for person last name
public String getPersonLastName()
{
//Returns person last name
return last_Name;
}
//Access method for person email address
public String getPersonEmailAddress()
{
//Returns person email address
return email_addr;
}
//Access method for person telephone number
public String getPersonTelephoneNumber()
{
//Returns person telephone number
return telephone_number;
}
//Method for change person Email Address
public void changeEmailAddress(String nEmail)
{
//Assign "email_addr" to "nEmail"
email_addr = nEmail;
}
//Method for change person PhoneNumber
public void changePhoneNumber(String nPhone)
{
//Assign "telephone_number" to "nPhone"
telephone_number = nPhone;
}
//Method for check two persons are equal
public boolean equalMethod(PersonAddress otherPerson)
{
//Returns true if persons are equal
return last_Name.equals(otherPerson.last_Name) && first_Name.equals(otherPerson.first_Name);
}
//Define main function
public static void main(String[] args)
{
//Create object "p1" for "PersonAddress" class
PersonAddress p1 = new PersonAddress();
//Create object "p2" for "PersonAddress" class
PersonAddress p2 = new PersonAddress();
//Create object "p3" for "PersonAddress" class
PersonAddress p3 = new PersonAddress();
//Set values for "p1" by calling method "setPersonAddress"
p1.setPersonAddress("John", "Merry", "john123@aaa.com", "123-4567");
//Set values for "p2" by calling method "setPersonAddress"
p2.setPersonAddress("John", "Merry", "jr@ccc.com", "123-7654");
//Set values for "p3" by calling method "setPersonAddress"
p3.setPersonAddress("Jansi", "Rose", "htr@aaa.com", "333-4444");
//Display the statement
System.out.println("Values of attributes for person 1.");
//Display person "p1" first name by calling method "getPersonFirstName"
System.out.println("First Name: " + p1.getPersonFirstName());
//Display person "p1" last name by calling method "getPersonLastName"
System.out.println("Last Name: " + p1.getPersonLastName());
//Display person "p1" email addressby calling method "getPersonEmailAddress"
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Convert the following UML diagram into the Java code. Write constructor, mutator and accessor methods for the given class. Create an instance of the class in a main method using a Demonstration class. Note: The structure of the class can be compiled and tested without having bodies for the methods. Just be sure to put in dummy return values for methods that have a return type other than void. Exercise Log ExerciseID: integer ExerciseCategory: string TimeSpent: float Calories: floatarrow_forwardcreate java method to count the number of employees and their salary ranges according to your assumptions. You can think about any assumption . Create main class to call the methodarrow_forwardImagine you have two classes: Employee (which represents being an employee) and Ninja (which represents being a Ninja). An Employee has both state and behaviour; a Ninja has only behaviour. You need to represent an employee who is also a ninja (a common problem in the real world). By creating only one interface and only one class (NinjaEmployee), show how you can do this without having to copy method implementation code from either of the original classes.arrow_forward
- Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have thefollowing methods:public Date(int year, int month, int day)Constructs a new Date object to represent the given date.public void addDays(int days)Moves this Date object forward in time by the given number of days.public void addWeeks(int weeks)Moves this Date object forward in time by the given number of seven-day weeks. public int daysTo(IDate other)Returns the number of days that this Date must be adjusted to make it equal to the given other Date.public int getDay()Returns the day value of this date; for example, for the date 2006/07/22, returns 22.public int getMonth()Returns the month value of this date; for example, for the date 2006/07/22, returns 7.public int getYear()Returns the year value of this date; for example, for the date 2006/07/22, returns 2006.public boolean isLeapYear() Returns true if the year of this date is a leap year. A leap year occurs every four…arrow_forwardTrue or False? Interface can be used to store a common method implementation.arrow_forward5. Create an interface MessageDecoder that has a single abstract method decode (cipherText), where cipher Text is the message to be decoded. The method will return the decoded message. Modify the classes 8.5 Graphics Supplement SubstitutionCipher and ShuffleCipher, as described in Exercises 16 and 17, so that they implement Message Decoder as well as the interface MessageEncoder that Exercise 15 describes. Finally, write a program that allows a user to encode and decode messages entered on the keyboard. 703arrow_forward
- In Java Programming: Example, 8-8, defined the class Person to store the name of a person. The methods that we included merely set the name and print the name of a person. Redefine the class Person so that, in addition to what the existing class does, ypu can: 1. Set the last name only. 2. Set the first name only. 3 Set the middle name. 4. Check whether a given last name is the same as the last name of this person. 5. Check wether a given first name is the same as the first name of this person. 6. Check whether a given middle name is the same as the middle name of thi person. 7. Add the method equals that returns true if two objects contain the same first, middle, and last name. 8. Add the method makeCopy that copies the instance variables of a Person object into another Person object. 9. Add the method getCopy that creates and returns the address of the object, which is a copy of another Person object. 10. Add a copy constructor. 11. Write the definitions of the methods of the class…arrow_forwardKindly discribearrow_forward⚫ Task 1: Create a Class Tasks Define a class named Person with attributes name and age. Write a method greet() that prints a greeting message including the person's name and age. ⚫ Task 2: Rectangle Class Create a class Rectangle that takes length and width as parameters. Add methods area() and perimeter() to calculate and return the area and perimeter of the rectangle. ⚫ Task 3: Object Interaction Create a Library class that contains a list of books and methods to add, remove, and list all books in the library. • Task 4: Movie Class Create a class Movie with attributes title, director, and rating. Add a method display_info() that prints the movie's details and a method rate_movie(new_rating) to update the movie's rating. • Task 5: Ticket Class(homework) Define a class Ticket' with attributes event_name, date, and price. Add methods apply_discount(discount_percentage) to reduce the price by a given percentage and display_ticket() to print the ticket details including the final price…arrow_forward
- 1. Implement the following classes and interface in Java.• Shape interface which has the following methods:– public double perimeter(); // doesn’t have any parameters, returns the perimeter of the shape.– public double area(); // doesn’t have any parameters, returnsthe area of the shape.– public void info(); // doesn’t have any parameters, prints theperimeter and area of the shape.• Circle class that implements Shape interface and has a constructorthat takes the radius.• Rectangle class that implements the Shape interface and has a constructor that takes the width and height.• Square class that extends the Rectangle class and has a constructorthat takes the edge length.– Square constructor should only call the super constructor withcorrect parameters.– Square constructor should not explicitly implement the Shapeclass, but it should inherit the perimeter, area and info methodsfrom the Rectangle class.2. Create a Test class, and create one Circle, one Rectangle and one Squareobjects.…arrow_forwardImplement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Write the class declarations, the constructors, and the Supply a methods toString for all classes. test program for these classes and methods.arrow_forwardObjective: Write a class that will test dates and times inputted by the user and determine whether or not it is valid. This will focus on the usages of methods to organize code. First download the driver and put it in your project DO NOT ALTER THE DRIVER! Use this to run your project The driver : public class DateAndTimeDriver { public static void main(String[] args) { // TODO Auto-generated method stub DateAndTimeTester dtTester = new DateAndTimeTester(); dtTester.run(); } } Write a class file called DateAndTimeTester This DOES NOT have a main method Create the following methods run: This method returns nothing and takes no parameters. This is called by the driver and should handle all of the input from the Scanner and dialog for the user. isValid: returns true or false if a given String has the correct date and time. The String parameter should be formatted “MM/DD hh:mm” This method should call the methods isValidDate and isValidTime to determine this. isValidDate: returns…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