EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2, Problem 1RQ
Program Description Answer
After compilation, when a data in the
Hence, the correct answer is option “B”.
Expert Solution & Answer
Explanation of Solution
Constant:
The variable is defined as constant variable when the data item cannot be changed while the program is running.
- Constants are mostly used to define default values.
- For example: PI has the constant value 3.14.
- Consider the following statement in a Java class, the number 143 is constant, every time the java application containing the below statement with constant 143 is executed, the value 143 is displayed.
System.out.println(143);
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
I need to make a Java Application in Apache Netbeans 12.5 , I would like to ask for help please. The question is as follows:
To encourage good grades, Hermosa High School has decided to award each student a bookstore credit that is 10 times the student’s grade point average. In other words, a student with a 3.2 grade point average receives a R 32 credit. Create a class that prompts a student for a name and grade point average, and then passes the values to a method that displays a descriptive message. The message uses the student’s name, echoes the grade point average, and computes and displays the credit. Save the application as BookstoreCredit.java.
Rooms.txt (427 B)
Imagine we were creating a Textbased Adventure Program where a user can navigate through a series of rooms and pick up items, use them, put them down and get points. This assignment has us just reading the rooms of a game from a file into our program and displaying the rooms, not building the entire game.
Create a new Java Project. Name it TestReadRoomFile or something like that.
Add a Room class to the project according to the following UML.
Room
-roomNumber: int
the room number
-roomName: String
the name of the room
-description: String
the description of the room
+Room(roomNumber: int, roomName:String, description:String)
Constructor. Assign the parameters to the instance variables.
+getRoomName():String
returns the name of the room
+getRoomNumber(): int
returns the room number
+getDescription(): String
returns the description
+toString():String
returns a string with all the room information.
Create a ReadRoomFile class similar to the OOP example…
Write another Java class named Patient that contains:
■ A private integer data field called id.
■ A private static integer data field called numberOfPatients that counts the number of Patient objects created (default value 0).
■ A private String data field called name.
■ A private Address variable called address.
■ A private File variable called file that refers to a database.txt file.
■ A constructor that creates a patient object with specified name and address. Note that the id of patients is auto-incremented. If 3 patients are created the first one would have id 1, the second id would be 2 and the third id 3.
■ A static method getNumberOfPatients() that returns the number of patients.
■ A method getId() that returns the patient’s id.
■ A toString() method that returns a one-line description of the patient.
■ A savePatientToFile() method that is called every time a new patient object is created to save the patient information (patient object) to the database file.
Chapter 2 Solutions
EBK JAVA PROGRAMMING
Ch. 2 - Prob. 1RQCh. 2 - Prob. 2RQCh. 2 - Prob. 3RQCh. 2 - Prob. 4RQCh. 2 - Prob. 5RQCh. 2 - Prob. 6RQCh. 2 - Prob. 7RQCh. 2 - Prob. 8RQCh. 2 - Prob. 9RQCh. 2 - Prob. 10RQ
Ch. 2 - Prob. 11RQCh. 2 - Prob. 12RQCh. 2 - Prob. 13RQCh. 2 - Prob. 14RQCh. 2 - Prob. 15RQCh. 2 - Prob. 16RQCh. 2 - Prob. 17RQCh. 2 - Prob. 18RQCh. 2 - Prob. 19RQCh. 2 - Prob. 20RQCh. 2 - Prob. 1PECh. 2 - Prob. 2PECh. 2 - Prob. 4PECh. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - Prob. 7PECh. 2 - Prob. 8PECh. 2 - Prob. 9PECh. 2 - Prob. 10PECh. 2 - Prob. 11PECh. 2 - Prob. 12PECh. 2 - Prob. 13PECh. 2 - Prob. 14PECh. 2 - Prob. 15PECh. 2 - Prob. 16PECh. 2 - Prob. 1GZCh. 2 - Prob. 3GZCh. 2 - Prob. 1CPCh. 2 - Prob. 2CP
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
- For this exercise, you will create 2 classes: InputOutput class and AddNumbers class. ⦁ InputOutput Class: write a program that carries out the following tasks:⦁ Create an object of type PrintWriter and that writes into a file with the name greeting.txt.⦁ Print the message “Hello, world!” on the file.⦁ Close the file.⦁ Open the same file again.⦁ Read the message into a string variable (hint: use nextLine() method to read the text).⦁ Print the message on the screen. ⦁ AddNumbers Class: write a program that asks the user to input four floating-point numbers. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs. For example, the user might enter letters instead of numbers. In this case, use the exception handling mechanism to print a proper message. (hint: use InputMismatchException) Don’t forget to import java.util.*.arrow_forwardDo the following using Swift Xcode project (using macOS and choosing option/tab: Command line Tool): Create a class CarLoan (store it in a separate file – CarLoan.swift) which is having the following: Loan number, customer name, yearly interest rate, loan amount and duration (time period) as stored properties Define private setter for loan number and customer name Loan amount should not be negative or zero Interest rate should be positive and between 1.0% and 4.0 %. Default – 1.0% Time duration cannot be negative and cannot be more than 7 years. Min – 3 years You need to define property observers – didSet for interest rate, loan amount and time duration. Down payment should be at least 10% of loan amount or more but it cannot be equal to loan amount. Define it as computed property. Define two initializers, one which initializes all the properties to their default values and one which initializes to appropriate values. Define a Print as computed property which display all the instance…arrow_forwardThe calculator should have the features and functions similar to the calculator found in Windows OS. Given below is the interface of the calculator and you should also design a similar user interfaceAssignment Requirements Develop the complete application using Java. Your calculator should have mandatory functions such as Add, Subtract, Multiply and Divide. Ensure your program can handle exceptions.Note: You only need to include buttons for the numbers, addition, subtraction, multiplication, division, backspace, equal, cancel, and negation. Other buttons are not needed. The program must be well documented with proper comments where needed for readability and to explain relevant coding.arrow_forward
- Please provide JAVA source code for following assignment. Please attach proper comments and read the full requirements. The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license test The test has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C D D A A student must correctly answer 15 of the 20 questions to pass the exam. Write a class named Drivertest that holds the correct answers to the test in an array field. The class should also have an array field that holds the student’s answers. The class should have the following methods: passed. Returns true if the student passed the test, or false if the student failed totalCorrect. Returns the total number of correctly answered questions totalIncorrect. Returns the total number of incorrectly answered questions questionsMissed. An int array containing the…arrow_forwardplease code in python In a file named Shape.py create a class named Shape.The Shape class should have the following variables: name - (string - 'circle', 'rectangle', 'triangle'), area (float -area of the shape), perimeter (float - perimeter of the shape) and, position ((float,float) - x,y center position ofthe shape as a tuple).Adding 2 shapes together returns the sum of their perimeters.Multiplying 2 shapes together returns the sum of their areas.Subtracting 1 shape from another returns the distance from their positionsPrinting a shape (using the print() function) should return a string that displays the name and the centerposition. NOTE: You may assume that all shapes will have a unique x,y position for this problem.In a file named Shapes.py create the classes Circle, Rectangle, and Triangle. These shapes should inherit theShape Class.There Constructors(__init__ method) should take in all the necessary information needed.A Rectangle must take in a position (x,y), a width, and a…arrow_forwardWhat is a unit test? Assume a developer writes the following source code to calculate the sum of two numbers. Describe how a unit test can be developed to test this class. You may use code, pseudo code, or natural language. {eq}public\ class\ MyConcate\ \{ \\ \quad public\ String\ concatenate(String\ one,\ String\ two)\{ \\ \quad \quad return\ one+two; \\ \quad \} \\ \} {/eq}arrow_forward
- for c++ please pleaseneed two files which are employee.h productionWorker.h NB: please pleae make sure NEED ANSWER THE EXCEPTION PROJECT which is the image question the blow question is required not the question please please make sure need two files employee.h and productionWorker.h if you can add cpp file i would appricate thanks here is chapter 15 required 15, Employee and ProductionWorker Classes Design a class named Employee. The class should keep the following information in • Employee name • Employee number • Hire date Write one or more constructors and the appropriate accessor and mutator functions for the class. VideoNote Solving the Employee and ProductionWorker Classes Problem Programming Challenges 963 Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: • Shift (an integer) • Hourly pay rate (a double ) The workday is divided into two shifts:…arrow_forwardThis assignment uses the same account class created in Lab #4 with a more generally useful interface. It reads commands from a bank.txt file. Your program must process the followingfour commands. Create account amountDeposit account amountWithdraw account amountBalance account In all of the above commands, account is an integer and amount is a double. The following program behavior is required –1. Valid account numbers are 1-9. This requires the program to have an array of references to Account objects.2. If the first word on any line contains a command other than the four listed above, an error message should be displayed and that line ignored.3. The create command creates a new account object with the given account number and initial balance. If an account already exists with that number an error message should be displayed and the command ignored.4. The Deposit and Withdraw commands perform the indicated operation on an existing account. If no account with that number has been…arrow_forwardCreate a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need.(1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the following specifications: Private fields String itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 Default constructor Public member methods (mutators & accessors) setName() & getName() setPrice() & getPrice() setQuantity() & getQuantity() (2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call…arrow_forward
- Create a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need.(1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the following specifications: Private fields String itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 Default constructor Public member methods (mutators & accessors) setName() & getName() setPrice() & getPrice() setQuantity() & getQuantity() (2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call…arrow_forwardCreate a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need.(1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the following specifications: Private fields String itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 Default constructor Public member methods (mutators & accessors) setName() & getName() setPrice() & getPrice() setQuantity() & getQuantity()arrow_forwardLet's create our first Java file, called Welcome.java, which can be done in any text editor (like Notepad, Notepad++, Visual code, etc.). Open a file and paste the following Java code. public class Main { public static void main(String[] args) { System.out.println("mudau shudufhadzo welcome to BIS2142/ 2542 class"); } } Execute/ run it using a command prompt. Your output should contain a name and welcome to BIS2142/ 2542 class message. Therefore, your display message will look like this "mudau shudufhadzo "welcome to BIS2142/2542 class".arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY