Java Programming, Loose-leaf Version
8th Edition
ISBN: 9781337685917
Author: Joyce Farrell
Publisher: Cengage Learning
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 “A”.
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
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…
What 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}
The 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.
Chapter 2 Solutions
Java Programming, Loose-leaf Version
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. 1GZCh. 2 - Prob. 2GZCh. 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
- Python3 code: Create a simple text file called mycandy The first line of the file will be Candy Name, Candy Calories, Total Fat Grams Next, add five lines to the file by hand using your favorite five candy bars information. Each line's data will be separated by commas. Create a class called Candy which keeps track of the three pieces of information Read in the file line by line and create a Candy class instance for each candy bar you have, and add that new instance to a list. Once you have the list created, loop through the list and print the candy bar info out to the console Add a line of code to append one more candy bar’s information to your mycandy file. Show what your new text file looks like after the appendarrow_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_forwardFor 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_forward
- please 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_forwardRight click on the BlueJ workspace and select New Class. This will require you to enter a name. Enterthe word Activity1PayStub as the name. -Make sure you adhere to the Checkstyle conventions with your code. Now copy and paste the following code into the editor. import java.util.Scanner;/*** Activity1PayStub class is part of Lab 3 and* creates a simple pay stub.** @author (your name)* @version (date)*/public class Activity1PayStub{public static final double OVERTIME_RATE = 1.5;/*** It all starts with the main method.** @param args command-line arguments (not used)*/public static void main(String[] args){}} (a) Declare a Java Scanner object (notice the import statement in the code above) to get user inputvalues for the following data. Do not use the class given last week. It's time to use the realScanner class! You will need a variable for the (single!) Scanner object, as well as variables foreach of the data items below: Employee name Employee social security number (with hyphens)…arrow_forwardI 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.arrow_forward
- I'm stuck on this question and I don't know how I should be approaching this. What should I do? My code so far: ----------------- #include <iostream> using namespace std; class Student{ public: Student():grade(0.0){} void setGrade(double value){ grade = value; } void setName(string value){ name = value; } void setMajor(string value){ major = value; } double getGrade(){ return grade; } string getName(){ return name; } string getMajor(){ return major; } void addStudent(double grade, string value1, string value2){ Student::setGrade(grade); Student::setName(value1); Student::setMajor(value2); } void display(){ cout<<"Name: "<<Student::getName()<<endl; cout<<"Major: "<<Student::getMajor()<<endl; cout<<"GPA: "<<Student::getGrade()<<endl; cout<<"Grade: "; } private: class GPA{ public: GPA(){} void getLetterGrade(double grade) const{ if (grade >= 3.5){ cout<<"A"; } if (grade >= 2.5…arrow_forwardCreate an application that accepts employee data interactively. Users might make any of the following errors as they enter data: The employee number is not numeric, less than 1000 or more than 9999 The hourly pay rate is not numeric, less than R9.00 or more than R25.00 Create a class that stores an array of six usable error message that describe the preceding mistakes; save the file as EmployeeMessages.java. Create an EmployeeException class; each object of this class will store one of the messages. Save the file as EmployeeException.java. Create an application that prompts the user for employee data, and display the appropriate message when an error occurs. If no error occurs, display the message “Valid Employee data”. Save the program as EmployeeDataEntery.java (in java form)arrow_forwardI need this debugged. Thanks in advance. // Application looks up home price// for different floor plans// allows upper or lowercase data entryimport java.util.*;public class DebugEight3{public static void main(String[] args){Scanner input = new Scanner(System.in);String entry;char[] floorPlans = {'A','B','C','a','b','c'};int[] pricesInThousands = {145, 190, 235};char plan;int x, fp = 99;String prompt = "Please select a floor plan\n" +"Our floorPlanss are:\n" + "A - Augusta, a ranch\n" +"B - Brittany, a split level\n" +"C - Colonial, a two-story\n" +"Enter floorPlans letter";System.out.println(prompt);entry = input.next();plan = entry.charAt(1);for(x = 0; x < floorPlans.length; ++x)if(plan == floorPlans[x])x = fp;if(fp == 99)System.out.println("Invalid floor plan code entered");else{if(fp >= 3)fp = fp - 3;System.out.println("Model " +plan + " is priced at only $" +pricesInThousands[fp] + ",000");}}}arrow_forward
- 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.arrow_forwardPlease 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_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
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK 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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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