Java Programming, Loose-leaf Version
8th Edition
ISBN: 9781337685917
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 1PE
Program Plan Intro
Overloading the method
Filename: “FormLetterWriter.java”
- Define the “FormLetterWriter” class
- Define the main method.
- Call the “displaySalutation” method with single parameter.
- Call the “displayLetter” method.
- Call the “displaySalutation” method with two parameters.
- Call the method “displayLetter”.
- Define the “displaySalutation” method
- Display the “Dear Mr. or Ms.” followed by last name.
- Define the “displaySalutation” method
- Display the first name followed by last name.
- Define the “displayLetter” method
- Display the statement.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Create a class named Person that holds the following fields: two String objects for the person’s first and last name and a LocalDate object for the person’s birthdate. Create a class named Couple that contains two Person objects. Create a class named Wedding for a wedding planner that includes the date of the wedding, the Couple being married, and a String for the location.
Provide constructors for each class that accept parameters for each field, and provide get methods for each field.
I need help!
Modify the class named FormLetterWriter that includes two overloaded methods named displaySalutation(). The first method takes one String parameter that represents a customer’s last name, and it displays the salutation Dear Mr. or Ms. followed by the last name. The second method accepts two String parameters that represent a first and last name, and it displays the greeting Dear followed by the first name, a space, and the last name. After each salutation, display the rest of a short business letter using the displayLetter method: Thank you for your recent order.
public class FormLetterWriter {public static void main(String[] args) {displaySalutation("Kelly");displayLetter();displaySalutation("Christy", "Johnson");displayLetter();}
public static void displaySalutation(String lastName) {// Write your code here}
public static void displaySalutation(String firstName, String lastName) {// Write your code here}public static void displayLetter() {// Write your code here}}
Modify the class named FormLetterWriter that includes two overloaded methods named displaySalutation(). The first method takes one String parameter that represents a customer’s last name, and it displays the salutation Dear Mr. or Ms. followed by the last name. The second method accepts two String parameters that represent a first and last name, and it displays the greeting Dear followed by the first name, a space, and the last name. After each salutation, display the rest of a short business letter using the displayLetter method: Thank you for your recent order.
An example of the program is shown below:
Dear Mr. or Ms. Kelly,
Thank you for your recent order.
Dear Christy Johnson,
Thank you for your recent order.
Chapter 4 Solutions
Java Programming, Loose-leaf Version
Ch. 4 - Prob. 1RQCh. 4 - Prob. 2RQCh. 4 - Prob. 3RQCh. 4 - Prob. 4RQCh. 4 - Prob. 5RQCh. 4 - Prob. 6RQCh. 4 - Prob. 7RQCh. 4 - Prob. 8RQCh. 4 - Prob. 9RQCh. 4 - Prob. 10RQ
Ch. 4 - Prob. 11RQCh. 4 - Prob. 12RQCh. 4 - Prob. 13RQCh. 4 - Prob. 14RQCh. 4 - Prob. 15RQCh. 4 - Prob. 16RQCh. 4 - Prob. 17RQCh. 4 - Prob. 18RQCh. 4 - Prob. 19RQCh. 4 - Prob. 20RQCh. 4 - Prob. 1PECh. 4 - Prob. 2PECh. 4 - Prob. 3PECh. 4 - Prob. 4PECh. 4 - Prob. 5PECh. 4 - Prob. 6PECh. 4 - Prob. 7PECh. 4 - Prob. 8PECh. 4 - Prob. 9PECh. 4 - Prob. 10PECh. 4 - Prob. 11PECh. 4 - Prob. 12PECh. 4 - Prob. 1GZCh. 4 - Prob. 2GZ
Knowledge Booster
Similar questions
- Modify the class named FormLetterWriter that includes two overloaded methods named displaySalutation(). The first method takes one String parameter that represents a customer’s last name, and it displays the salutation Dear Mr. or Ms. followed by the last name. The second method accepts two String parameters that represent a first and last name, and it displays the greeting Dear followed by the first name, a space, and the last name. After each salutation, display the rest of a short business letter using the displayLetter method: Thank you for your recent order. An example of the program is shown below: Dear Mr. or Ms. Kelly, Thank you for your recent order. Dear Christy Johnson, Thank you for your recent order. public class FormLetterWriter { public static void main(String[] args) { displaySalutation("Kelly"); displayLetter(); displaySalutation("Christy", "Johnson"); displayLetter(); } public static void displaySalutation(String…arrow_forwardFor your homework assignment, build a simple application for use by a local retail store. Your program should have the following classes: Item: Represents an item a customer might buy at the store. It should have two attributes: a String for the item description and a float for the price. This class should also override the __str__ method in a nicely formatted way. Customer: Represents a customer at the store. It should have three attributes: a String for the customer's name, a Boolean for the customer's preferred status, and a list of 5 indexes to hold Item objects. Include the following methods: make_purchase: accepts a String and a double as parameters to represent the name and price of an item this customer is purchasing. Create a new Item object with this info and append it to the internal list. If the customer is a preferred customer based on the Boolean attribute's value, take 10% off the total sale price. __str__: Override this method to print the customer's name and every…arrow_forwardThis code is in java. Transportation Program Main file called transportation. It will create the sedan and coupe objects. You will pass in parameters for the number of exterior and interior color options. It will print a message from the car class that prints All cars have Wheels: #of wheels. ; Interior Color Options: # of interior colors ; Exterior Color Options: # of colors. A message from the sedan and the coupe classes that print the number of doors and cylinders. The car class is the parent class. It will have a constructor for the number of wheels (4), exterior colors (5), and interior colors (2). It will also have a method that prints the text. The sedan and coupe classes will be children classes to the car class. They will have a constructor that calls the car’s constructor and adds in variables for the number of doors and number of cylinders. sedans have 4 doors and 6 cylinder engines. coupes have 2 doors and 4 cylinder engines. The sedan and coupe classes will…arrow_forward
- Create a class named Person that holds the following fields: two String objectsfor the person’s first and last name and a LocalDate object for the person’sbirthdate. Create a class named Couple that contains two Person objects. Create aclass named Wedding for a wedding planner that includes the date of the wedding,the names of the Couple being married, and a String for the location. Provideconstructors for each class that accept parameters for each field, and provide getmethods for each field. Then write a program that creates two Wedding objectsand in turn passes each to a method that displays all the details. Save the files asPerson.java, Couple.java, Wedding.java, and TestWedding.java.arrow_forwardCreate a class named Commission that includes three variables: a double sales figure, a double commission rate, and an int commission rate. Create two overloaded methods named computeCommission(). The first method takes two double parameters representing sales and rate, multiplies them, and then displays the results. The second method takes two parameters: a double sales figure and an integer commission rate. This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission. Supply appropriate values for the variables, and write a main() method method. Save the file that tests each overloaded as Commission.java.arrow_forwardCreate a class named 'Programming'. While creating an object of the class, if nothing ispassed to it, then the message "I love programming languages" should be printed. Ifsome String is passed to it, then in place of "programming languages" the name of thatString variable should be printed.For example, while creating the object if we pass "cpp", then "I love cpp" should beprintedarrow_forward
- In python Add the following four methods to your Crew class: move(self, location): This takes in a location as a string, along with self, and attempts to move the crew member to the specified location. If location is one of the five valid location options ("Bridge", "Medbay", "Engine", "Lasers", or "Sleep Pods"), then this should change self.location to that new value. Otherwise, the function should print out the message: Not a valid location. repair(self, ship): first_aid(self, ship): fire_lasers(self, ship, target_ship, target_location): The above three methods represent tasks that a basic Crew member is not capable of (but one of its derived classes will be able to accomplish). So each of them should simply print out a message of the form: <Name> doesn't know how to do that. Examples: Copy the following if __name__ == "__main__" block into your hw12.py file, and comment out tests for parts of the class you haven’t implemented yet. if __name__ == '__main__': crew1…arrow_forwardmau Open Leathing inta... - The class has data members that can hold the name of your cube, length of one of the sides and the color of your cube. - The class has a constructor that accepts the name, length of one of the sides, and color as arguments and sets the data members to those values. - The class has the following methods to set the corresponding data member. setName(string newName) setSide(double newSide) setColor(string newColor) - The class has a method called getVolume() that returns the volume of the cube, calculated by cubing the length of the side. - The class has a method called volumelncrease(double newVolume) that receive the percent the volume should increase, and then the side to the corresponding value. i - For example, 2.5 indicates 2.5% increasing of the volume. So you take the current volume, increase it by 2.5%, and then find the cube root to calculate the new side length. You can use the built in function called cbrt, part of the math library, to find the cube…arrow_forwardWrite the C# application SwimmingWaterTemperature containing a variable that can hold a temperature expressed in degrees Fahrenheit. Within the class, create a method that accepts a parameter for a water temperature and returns true or false, indicating whether the water temperature is between 70 and 85 degrees and thus comfortable for swimming. If the temperature is not between 32 and 212 (the freezing and boiling points of water), it is invalid, and the method should throw an ArgumentException. In the Main() method, continuously prompt the user for data temperature, pass it to the method, and then display the following messages indicating whether the temperature is comfortable, not comfortable, or invalid: X degrees is comfortable for swimming. X degrees is not comfortable for swimming. Value does not fall within the expected range. Enter the value 999 to quit the program. using System; using static System.Console; class SwimmingWaterTemperature { static void Main() {…arrow_forward
- Design a class named Employee_Salary that contains:• A String data field named name representing the name of the employee.• A String data field named position representing the position of the employee• A double data field named salary representing the salary of the employee.• A constructor with the parameters that initialize the name, position, and salary.• A method named printInfo () to print the employees details (name, position, andsalary)Write a test program that creates an array of object to hold 5 employees object from employee class. Assign values to the object. Calculate the salary average, then find how many employees have a salary less than the average and how many employees have a salary greater than the average. Calling printInfo method to display the information of all employees and show the number of employees have a salary less than the average and the number of employees have a salary greater than the average.arrow_forwardThis code is in java. Transportation Program Main file called transportation. It will create the sedan and coupe objects. These will be in sedan.java and coupe.java. You will pass in parameters for the number of exterior and interior color options. It will print a message from the car class that prints All cars have Wheels: #of wheels. ; Interior Color Options: # of interior colors ; Exterior Color Options: # of colors. A message from the sedan and the coupe classes that print the number of doors and cylinders. The car class is the parent class. It will have a constructor for the number of wheels (4), exterior colors (5), and interior colors (2). It will also have a method that prints the text. The sedan and coupe classes will be children classes to the car class. They will have a constructor that calls the car’s constructor and adds in variables for the number of doors and number of cylinders. sedans have 4 doors and 6 cylinder engines. coupes have 2 doors and 4 cylinder…arrow_forwardA. Build a class named car. This class is defined as follows: It has the fields: Car ID, Car model, Car make, Car color, Car year. Build a constructor that accepts the five parameters (Car ID, Car model, Car make, Car color, Car year). Override the method toString() to return the string representation of Car ID, Car model, Car make, Car color, Car year. Build a method named display to print the values returned by toString() method. Override the equals() method to compare the Car model, Car make, Car color of two Car objects. The method returns true if all the values of these fields are the same, and false otherwise. In the equals method you must check the following: a. If you compare the Car object to itself, return true.! b. If you compare car object with another car object return true, otherwise return false. Hint use : instanceof operator for this purpose. Override the hashcode() method to return same hash codes for objects that are equal according to the equals() method you built…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT