EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 9PE
Program Plan Intro
A class “Apartment”
Program plan:
- In a file “Apartment.java”, create a class “Apartment”,
- Declare the necessary variables.
- Define the constructor to set the initial values for the necessary variables.
- Define the method “get_AptNumber()” to return the apartment number.
- Define the method “get_Bedrooms()” to return the number of bed rooms.
- Define the method “get_Baths()” to return the number of bath rooms.
- Define the method “get_Rent ()” to return the rent.
- In a file “TestApartments.java”, create a class “TestApartments”,
- Define the method “main ()”,
- Create “Scanner” object.
- Call the constructor “Apartment()” that instantiates “5” objects.
- Declare the necessary variables.
- Prompt the user to enter the minimum number of bed rooms.
- Get the minimum number of bed rooms.
- Prompt the user to enter the minimum number of bath rooms.
- Get the minimum number of bath rooms.
- Prompt the user to enter the maximum rent ready to pay.
- Get from the user the maximum rent ready to pay.
- Print the string with user criteria.
- Execute if “true”,
- If it is true, call the method “display1()” for apartment-1.
- Increment the count by “1”.
- Execute if “true”,
- If it is true, call the method “display1()” for apartment-2.
- Increment the count by “1”.
- Execute if “true”,
- If it is true, call the method “display1()” for apartment-3.
- Increment the count by “1”.
- Execute if “true”,
- If it is true, call the method “display1()” for apartment-4.
- Execute if “true”,
- If it is true, call the method “display1()” for apartment-5.
- Increment the count by “1”.
- Check whether the count is “0”,
- If it is true, print invalid message.
- Define the method “checkAptm()”,
-
- Set the Boolean value to “false”.
- Check whether the number of available bed rooms, bath rooms, and rent is greater than or equal to the expected number of bed rooms, bath rooms, rent,
- If it is true, set the Boolean value to “true”.
- Return the Boolean value.
- Define the method “display1()”,
-
- Print the output.
- If it is true, print invalid message.
- Define the method “main ()”,
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Static & Not Final Field: Accessed by every object, Changing
Non-Static & Final Field: Accessed by object itself, Non-Changing
Static & Final: Accessed by every object, Non-Changing
Non-Static & Not Final Field: Accessed by object itself, ChangingRead the following situation and decide how the variables should be defined.
You have a class named HeartsPlayerA round of Hearts starts with every player having 13 cardsPlayers then choose 3 cards to “trade” with a player (1st you pass left, 2nd you pass right, 3rd you pass across, 4th you keep)Players then strategically play cards in order to have the lowest scoreAt the end of the round, points are cumulatively totaled for each player.If one player’s total is greater than 100, the game ends and the player with the lowest score wins.
1. How should the following data fields be defined (with respect to final and static)?(a) playerPosition (These have values of North, South, East, or West)(b) directionOfPassing(c) totalScore…
a - Create a FitnessTracker class that includes data fields for a fitness activity, the number of minutes spent participating, and the date. The class includes methods to get each field. In addition, create a default constructor that automatically sets the activity to running, the minutes to 0, and the date to January 1 of the current year. Save the file as FitnessTracker.java. Create an application that demonstrates each method works correctly, and save it as TestFitnessTracker.java.
b - Create an additional overloaded constructor for the FitnessTracker class you created in Exercise 3a. This constructor receives parameters for each of the data fields and assigns them appropriately. Add any needed statements to the TestFitnessTracker application to ensure that the overloaded constructor works correctly, save it, and then test it.
c - Modify the FitnessTracker class so that the default constructor calls the three-parameter constructor. Save the class as FitnessTracker2.java. Create an…
This is the question I am stuck on -
Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds.
Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects.
This is what I have so far -
public class Recording {
private String song;
private String artist;
private int playTime;
public void setSong(String title) {
this.song = title;
}
public void setArtist(String name) {
this.artist = name;
}
public void setPlayTime(int time) {
this.playTime = time;
}
public String getSong() {
return song;
}
public String…
Chapter 5 Solutions
EBK JAVA PROGRAMMING
Ch. 5 - Prob. 1RQCh. 5 - Prob. 2RQCh. 5 - Prob. 3RQCh. 5 - Prob. 4RQCh. 5 - Prob. 5RQCh. 5 - Prob. 6RQCh. 5 - Prob. 7RQCh. 5 - Prob. 8RQCh. 5 - Prob. 9RQCh. 5 - Prob. 10RQ
Ch. 5 - Prob. 11RQCh. 5 - Prob. 12RQCh. 5 - Prob. 13RQCh. 5 - Prob. 14RQCh. 5 - Prob. 16RQCh. 5 - Prob. 17RQCh. 5 - Prob. 18RQCh. 5 - Prob. 19RQCh. 5 - Prob. 20RQCh. 5 - Prob. 1PECh. 5 - Prob. 2PECh. 5 - Prob. 3PECh. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Prob. 9PECh. 5 - Prob. 10PECh. 5 - Prob. 1GZCh. 5 - Prob. 2GZCh. 5 - Prob. 3GZCh. 5 - Prob. 4GZCh. 5 - Prob. 5GZ
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
- Create the StockTask1 Java project Create a Stock object class that contains the following information: The symbol of the stock is stored in a private string data field called symbol. The stock's name is stored in a private string data field called name. previousClosingPrice is a private double data area that stores the stock price for the previous day. currentPrice is a private double data area that stores the stock price at the current time. A constructor for creating a stock with the given symbol and name. For the data fields, there are accessor methods (get-methods). For the data fields, there is a mutator method (set-methods). A method named getChangePercent()that returns the percentage changed from previousClosingPrice to currentPrice. Formula:perc_change = (current price - previous closing price) / previous closing price x 100 Create a test class named testStockthat creates a Stockobject with the stock symbol SUNW, the name Sun Microsystems Inc., and the previous closing…arrow_forwardA __________ is a field that cannot be changed by any statement in the class. a. static field b. class name c. key field d. constant fieldarrow_forwardCreate an application named SalesTransactiobDemo that declares several SalesTransaction objects and displays their values and their sum. Name - The salesperson name (as a string) sales Amount- The sales amount (as a double) commission- The commission (as a double) RATE- A readonly field that stores the commission rate (as a double). Define a getRate() avcessor method that returns the RATE Include 3 constructors for the class. One constructor accepts values for the name, sales amount, and rate, and when the sales value is set, the constructor computes the commission as sales value times commission rate. The second constructor accepts a name and sales amount, but sets the commission rate to 0 The third constructor accepts a name and sets all the other fields to 0arrow_forward
- Design an application that tracks airline flights. The Flight Schedule is the most important part of the application, which is a collection of flights. Each flight has several attributes, including the Airline and the Aircraft information. The Airline is identified by a name, such as Delta Air, and a code for all of its flights, such as DL. For simplicity, you can assume that every airline has a fleet of one particular type of aircraft. This allows the user to enter only the airline code to fill the rest of the aircraft data when the flight data is entered into the system. Flight Schedule Design: Define the structure for the Flight Schedule. Identify data fields for Airline Name, Airline Code, Aircraft Name/Model, Seat Capacity, and Class-specific seat numbers. Identify data fields for each flight, including Airline Code, Flight number, Flight status, and Flight Type. Define Departure data fields: Day-of-the-week, Departure Time, Airport Code, Departure Gate. Define Arrival data…arrow_forwardDon't put incorrect code..arrow_forwardHappyTunes is an application for downloading music files. Each time a file is purchased, a transaction record is created that includes the music genre and price paid. The available genres are Classical, Easy Listening, Jazz, Pop, Rock, and Other. Develop an application that accepts input data for each transaction and displays a report that lists each of the music genres, along with a count of the number of downloads in each of the following price categories: Over $10.00 $6.00 through $9.99 $3.00 through $5.99 Under $3.00arrow_forward
- Create an application named SalesTransactionDemo that declares several SalesTransaction objects and displays their values and their sum. The SalesTransaction class contains the following fields: Name - The salesperson's name (as a string) salesAmount - The sales amount ( as a double) commission - The commission (as a double) RATE - A readonly field that stores the commission rate (as a double). Define a getRate() accessor method that returns the RATE Include three constructors for the class. One constructor accepts values for the name, sales amount, and rate, and when the sales value is set, the constructor computes the commission as sales value times commission rate. The second constructor accepts a name and sales amount, but sets the commission rate to 0. The third constructor accepts a name and sets all the other fields to 0. An overloaded + operatoradds the sales values for two SalesTransaction objects and returns a new SalesTransaction object. In order to prepend the $ to…arrow_forwardkindly answer asap!!arrow_forwardDice Rolling Class In this problem, you will need to create a program that simulates rolling dice. To start this project, you will first need to define the properties and behaviors of a single die that can be reused multiple times in your future code. This will be done by creating a Dice class. Create a Dice class that contains the following members: Two private integer variables to store the minimum and maximum roll possible. Two constructors that initialize the data members that store the min/max possible values of rolls. a constructor with default min/max values. a constructor that takes 2 input arguments corresponding to the min and max roll values Create a roll() function that returns a random number that is uniformly distributed between the minimum and maximum possible roll values. Create a small test program that asks the user to give a minValue and maxValue for a die, construct a single object of the Dice class with the constructor that initializes the min and max…arrow_forward
- Write a class named RetailItem that holds data about an item in a retail store. The class should have the following properties:• Description—The Description property should hold a brief description of the item.• UnitsOnHand—The UnitsOnHand property should hold the number of units currently in inventory.• Price—The Price property should hold the item’s retail price. Write a constructor that accepts arguments for each property.The application should create an array of three RetailItem objects containing the following data: Description Units on Hand PriceItem 1 Jacket 12 59.95Item 2 Jeans 40 34.95Item 3 Shirt 20 24.95The application should have a loop that steps through the array, displaying each element’s properties.arrow_forwardComplete the following tasks: Design a class named StockTransaction that holds a stock symbol (typically one to four characters), stock name, and price per share. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. Design an application that declares two StockTransaction objects and sets and displays their values. Design an application that declares an array of 10 StockTransactionobjects. Prompt the user for data for each object, and then display all the values. Design an application that declares an array of 10 StockTransactionobjects. Prompt the user for data for each object, and then pass the array to a method that determines and displays the two stocks with the highest and lowest price per share.arrow_forwardThe dealership sells different types of vehicles: cars and trucks. All vehicles have a make, model, and year. However, a truck has an additional attribute - maximum load capacity (in pounds). Create a class named Vehicle with the following attributes: make, model, and year. Include the following methods: display_info(): This method should print all these details in a formatted string. get_age(): This method should calculate and return the age of the vehicle based on the current year. Tip: You will need to import functionality from the datetime module to do this. Create a class named Truck that inherits from the Vehicle class. This class should have an additional attribute, max_load, which represents the maximum load capacity of the truck. Include the following methods: display_info(): This method should override the method from Vehicle, and when it's called, it should display the truck's make, model, year, and maximum load capacity. can_carry(weight): This method should take a…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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
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