Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 1PE
Program Plan Intro
Overloading the method
Program plan:
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
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}}
For 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…
This 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…
Chapter 4 Solutions
Java Programming (MindTap Course List)
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. 1GZCh. 4 - Prob. 2GZ
Knowledge Booster
Similar questions
- Create 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_forwardIn 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_forward
- Write 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_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_forwardCarly’s Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows: Modify the method that sets the event number in the Event class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the event number is forced to A000. If the initial letter in the event number is not uppercase, force it to be so. Add a contact phone number field to the Event class. Add a set method for the contact phone number field in the Event class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more…arrow_forward
- A. 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_forwardWrite a class named Employee that has the following fields: name: The name field is a String object that holds the employee's name. idNumber: The idNumber is an integer variable that holds the employee's ID number. department: The department field is a String object that holds the name of the department where the employee works. position: The position field is a String object that holds the employee's job title. Write mutator methods that store values in these fields and accessor methods that return the values in these fields. Once you have written the class, write a separate program that creates three Employee objects to hold the following data. Name ID Number Azah Samsudin Mira Kamal Che Yah Sam Department Computer Science Biomedical Language Position Programmer Researcher Lecturer 11011 35125 80001 The program should store the data in the three objects and then display the data for each employee on the screen.arrow_forward● Create a class named Decimals. Write a static method named printDecimalDigits that takes a double as a parameter and does not return anything. ● ● ● The method should print out "Digits after decimal point: ", followed by all the digits after the decimal point on one line (do not include the decimal point). Additional rule: Your code must not contain any loops. Create a test class named DecimalsTest that contains the main method and use the sample usage below to check your code. Method Call Decimals.print DecimalDigits (37.2) Decimals.print DecimalDigits (1000) Method Output Digits after decimal point: 2 Digits after decimal point: 0 Decimals.printDecimalDigits (18.3927493038) Digits after decimal point: 3927493038arrow_forward
- Create a program named PaintingDemo that instantiates an array of eight Room objects and demonstrates the Room methods. The Room constructor requires parameters for length, width, and height fields (all of type int); use a variety of values when constructing the objects. The Room class also contains the following fields: Area - The wall area of the Room (as an int)Gallons - The number of gallons of paint needed to paint the room (as an int) A room is assumed to have four walls, and you do not need to allow for windows and doors, and you do not need to allow for painting the ceiling. A room requires one gallon of paint for every 350 square feet (plus an extra gallon for any square feet greater than 350). In other words, a 12 x 3 x 10 room with 9-foot ceilings has 396 square feet of wall space, and so requires two gallons of paint.arrow_forward3. Create a program for Smalltown Regional Airport Flights that accepts either an integer flight number or string airport code from the options in Figure 8-33. Pass the user’s entry to one of two overloaded GetFlightInfo() methods, and then display a returned string with all the flight details. The method version that accepts an integer looks up the airport code, name, and time of flight; the version that accepts a string description looks up the flight number, airport name, and time. The methods return an appropriate message if the flight is not found. Farrell, Joyce. Microsoft Visual C#: An Introduction to Object-Oriented Programming (MindTap Course List) (p. 347). Cengage Learning. Kindle Edition.arrow_forwardIn C#, Create a program named ConferencesDemo for a hotel that hosts business conferences. Allows a user to enter data about five Conference objects and then displays them in order of attendance from smallest to largest. The Conference class contains fields for the following: group - The group name (as a string) date - The starting date (as a string) attendees - The number of attendees (as an int) Include properties for each field. Also, include an IComparable.CompareTo() method so that Conference objects can be sorted in order from least to greatest attendees.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