MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
9th Edition
ISBN: 9780357505540
Author: Farrell; Joyce
Publisher: Cengage Learning US
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2, Problem 1RQ
Program Description Answer
After compilation, when a data in the program cannot be changed, then that data is defined as “constant”.
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
Choose correct option
It is disadvantageous to use public variables in classes because ___________
It results in compilation error
It cannot control its values
It cannot be accessed by other variables
Its values cannot be initialized
Fill-in-the-Blank
Creating a class object is often called _____________ the class.
In Python: Write a class named Pet, which should have the following data attributes:
_ _name (for the name of a pet)
_ _animal_type (for the type of animal that a pet is. Example values are 'Dog','Cat', and 'Bird')
_ _age (for the pets age)
The Pet class should have an _ _init_ _ method that creates these attributes. It should also have the following methods:
set_nameThis method assigns a value to the _ _name field
set_animal_typeThis method assigns a value to the _ _animal_type field
set_ageThis method assignsa value to the _ _age field
get_nameThis method assignsa value to the _ _name field
get_animal_typeThis method assignsa value to the _ _animal_type field
get_ageThis method assignsa value to the _ _age field
Once you have written the class, write a program that creates an object of the class and prompts the user to enter the name, type and age of his or her pet. This data should be stored as the objects attributes. Use the objects accessor methods to retrieve the pets…
Chapter 2 Solutions
MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
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
- A. Car Class Create a Python Program where you write a class named Car that has the following data attributes: • _ _year_model (for the car's year model) • __make (for the make of the car) • _ _speed (for the car's current speed) The Car class should have an _init_ method that accepts the car's year model and make as arguments. These values should be assigned to the object's _year_model and make data attributes. It should also assign 0 to the __speed data attribute. The class should also have the following methods: accelerate() The accelerate method should add 5 to the speed data attribute each time it is called. brake() The brake method should subtract 5 from the speed data attribute each time it is called. • get_speed() The get_speed method should return the current speed. Next, design a program that creates a Car object then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method…arrow_forwardIn previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing Dancing, Musical instrument, and Other. The class contains an auto-implemented property that holds a contestants name. The class contains fields for a talent code and description. The set accessor for the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. The talent description is a read-only property that is assigned a value when the code is set. Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this years competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. The program prompts the user for names and talent codes for each contestant entered. Along with the prompt for a talent code, display a list of the valid categories. After data entry is complete, the program displays the valid talent categories and then continuously prompts the user for talent codes and displays the names of all contestants in the category. Appropriate messages are displayed if the entered code is not a character or a valid code.arrow_forwardFill-in-the-Blank If you were writing a class declaration for a class named Canine and wanted to place it in its own file, what should you name the file? ___________________arrow_forward
- Python Programming2. Write a class named Pet, which should have the following data attributes:(a). __name (for the name of a pet)__animal_type (for the type of animal that a pet is. Example values are ‘Dog’, ‘Cat’, and ‘Bird’)__age (for the pet’s age)The Pet class should have an __init__ method that creates these attributes. It should also have the following methods:(b). set_name: This method assigns a value to the __name field.set_animal_type: This method assigns a value to the __animal_type field.set_age: This method assigns a value to the __age field.get_name: This method returns the value of the __name field.get_animal_type: This method returns the value of the __animal_type field.get_age: This method returns the value of the __age field.arrow_forwardQ3: You are designing a program for storing information about Computers. There are different types of computer for different purposes. Create a class Computer which will have attributes: CPUName=string, CPUClockSpeed_ghz-float, memory_gb3float. Now derive two classes from the Computer class, PC which will have attributes: operatingSystem3string, model=int, hasGPU=boolean and second class will be Smartphone which will have attributes: OSversion=string, battery_mAH=int. Write following functions for each class: > Constructor/Destructor > Deep Copy Constructor Parameterised Constructor Getter/Setter for dimension and length/radius Function to write the information to data file in append mode. Write a main function to create a dynamic array of PC and smartphone. Also write a function to get the PC with max CPUClockSpeed_ghz. Note: Write those functions which are asked. Be Precise in your answer.arrow_forwardclass SavingsAccount(object): RATE = 0.02 def __init__(self, name, pin, balance = 0.0): self._name = name self._pin = pin self._balance = balance def __str__(self): result = 'Name: ' + self._name + '\n' result += 'PIN: ' + self._pin + '\n' result += 'Balance: ' + str(self._balance) return result def __eq__(self,a): if self._name == a._name and self._pin == a._pin and self._balance == a._balance: return True else: return False def __gt__(self,a): if self._balance > a._balance: return True else: return False def getBalance(self): return self._balance def getName(self): return self._name def getPin(self): return self._pin def deposit(self, amount): self._balance += amount return self._balance…arrow_forward
- class SavingsAccount(object): """This class represents a savings account with the owner's name, PIN, and balance.""" RATE = 0.02 def __init__(self, name, pin, balance = 0.0): self._name = name self._pin = pin self._balance = balance def __str__(self): result = 'Name: ' + self._name + '\n' result += 'PIN: ' + self._pin + '\n' result += 'Balance: ' + str(self._balance) return result def getBalance(self): return self._balance def getName(self): return self._name def getPin(self): return self._pin def deposit(self, amount): """Deposits the given amount.""" self._balance += amount return self._balance def withdraw(self, amount): """Withdraws the given amount. Returns None if successful, or an error message if unsuccessful.""" if amount < 0: return 'Amount must be >=…arrow_forwardclass TicTacToePlayer: # Player for a game of Tic Tac Toe def __init__(self, symbol, name): self.symbol = symbol self.name = name def move(self, board): move = int(input(self.name + " make your move 1-9:")) move -= 1 y = move % 3 x = move // 3 board[x][y] = self.symbol def is_symbol(self, symbol): if symbol == self.symbol: return True class TicTacToe: # Game of TicTacToe in a class! def __init__( self, p1_symbol="X", p2_symbol="O", p1_name="Player1", p2_name="Player2" ): self.p1 = TicTacToePlayer(p1_symbol, p1_name) self.p2 = TicTacToePlayer(p2_symbol, p2_name) self.board = [[" " for x in range(3)] for x in range(3)] def play_game(self): turn = 0 winner_symbol = False while not winner_symbol: self._print_board() if turn % 2: self.p2.move(self.board) # replace this line with a call…arrow_forwardsolve in python Street ClassStep 1:• Create a class to store information about a street:• Instance variables should include:• the street name• the length of the street (in km)• the number of cars that travel the street per day• the condition of the street (“poor”, “fair”, or “good”).• Write a constructor (__init__), that takes four arguments corresponding tothe instance variables and creates one Street instance. Street ClassStep 2:• Add additional methods:• __str__• Should return a string with the Street information neatly-formatted, as in:Elm is 4.10 km long, sees 3000 cars per day, and is in poor condition.• compare:• This method should compare one Street to another, with the Street the method is calledon being compared to a second Street passed to a parameter.• Return True or False, indicating whether the first street needs repairs more urgently thanthe second.• Streets in “poor” condition need repairs more urgently than streets in “fair” condition, whichneed repairs more…arrow_forward
- A class may have several constructors and it is called __________.arrow_forwardProgram - Python This is my program for a horse race class (Problem below code) class Race: def __init__(self,name,time): self.name = name self.time = time self.entries = [] class Entrant: def __init__(self,horsename,jockeyname): self.horsename = horsename self.jockeyname = jockeyname race1 = Race('RACE 1','10:00 AM May 12, 2021')race2 = Race('RACE 2','11:00 AM May 12, 2021')race3 = Race('RACE 3','12:00 PM May 12, 2021') race1.entries.append(Entrant('Misty Spirit','John Valazquez'))race1.entries.append(Entrant('Frankly I’m Kidding','Mike E Smith')) race2.entries.append(Entrant('Rage against the Machine','Russell Baze')) race3.entries.append(Entrant('Secretariat','Bill Shoemaker'))race3.entries.append(Entrant('Man o War','David A Gall'))race3.entries.append(Entrant('Seabiscuit','Angel Cordero Jr')) print(race1.name, race1.time)for entry in race1.entries: print('Horse:',entry.horsename) print('Jockey:',entry.jockeyname) print()…arrow_forward#Python IDLE: #Below is my Pizza class ,how would I write the function described in the attached image,based on this class? # The Pizza class should have two attributes(data items): class Pizza: # The Pizza class should have the following methods/operators): # __init__ - # constructs a Pizza of a given size (defaults to ‘M’) # and with a given set of toppings (defaults to empty set). def __init__(self, size='M', toppings=set()): self.size = size self.toppings = toppings # setSize – set pizza size to one of ‘S’,’M’or ‘L’ def setSize(self, size): self.size = size # getSize – returns size def getSize(self): return self.size # addTopping – adds a topping to the pizza, no duplicates, i.e., adding ‘pepperoni’ twice only adds it once def addTopping(self, topping): self.toppings.add(topping) # removeTopping – removes a topping from the pizza def removeTopping(self, topping):…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
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
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
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