Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2, Problem 13E
Explanation of Solution
Given:Â The following fields are:
private boolean alive;
private Person tutor;
private Game game;
To find:Â The name of the following fields:
private boolean alive;
private Person tutor;
private Game game;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
There should only be one constructor for every class.
True
False
Question 1
public class Flat {
private int noOfRooms;
private double area;
private boolean seaView;
public Flat() { noOfRooms = 3; area = 200; seaView = true; }
%3D
public void setFlat(int n, double a, boolean s) { noOfRooms = n; area = a; seaView = s; }
public int getNoOfRooms( ) { return noOfRooms; }
public double getArea( ) { return area; }
public boolean getSeaView( ) { return seaView; }
}
Write a static method named findFlats that takes as a parameter an array of type Flat named list.
The method should count and return the number of flats that have 3 or more rooms and with a sea view.
The method prototype is:
public static int findFlats (Flat[] list);
Note: assume the array is already declared, populated with data in the main method and ready to be used.
QUESTION 12
There is a static field named bestFriend in a class called Friend.
There is a local variable in the main () with the same
name.
Code the assignment of the local to the field.
Chapter 2 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Ch. 2 - Create a TicketMachine object on the object bench...Ch. 2 - What value is returned if you get the machine's...Ch. 2 - Prob. 3ECh. 2 - Prob. 4ECh. 2 - Create another ticket machine for tickets of a...Ch. 2 - Prob. 6ECh. 2 - Does it matter whether we write...Ch. 2 - Prob. 8ECh. 2 - Put back the word public, and then check whether...Ch. 2 - From your earlier experimentation with the ticket...
Ch. 2 - Prob. 11ECh. 2 - Prob. 12ECh. 2 - Prob. 13ECh. 2 - Prob. 14ECh. 2 - In the following field declaration from the...Ch. 2 - Prob. 16ECh. 2 - Prob. 17ECh. 2 - To what class does the following constructor...Ch. 2 - How many parameters does the following constructor...Ch. 2 - Prob. 20ECh. 2 - Suppose that the class Pet has a field called name...Ch. 2 - Challenge exercise The following object creation...Ch. 2 - Compare the header and body of the getBalance...Ch. 2 - If a call to getPrice can be characterized as...Ch. 2 - If the name of getBalance is changed to getAmount,...Ch. 2 - Prob. 26ECh. 2 - Try removing the return statement from the body of...Ch. 2 - Compare the method headers of getPrice and...Ch. 2 - Do the insertMoney and printTicket methods have...Ch. 2 - Create a ticket machine with a ticket price of...Ch. 2 - How can we tell from just its header that setPrice...Ch. 2 - Complete the body of the setPrice method so that...Ch. 2 - Prob. 33ECh. 2 - Is the increase method a mutator? If so, how could...Ch. 2 - Prob. 35ECh. 2 - Write down exactly what will be printed by the...Ch. 2 - Add a method called prompt to the TicketMachine...Ch. 2 - Prob. 38ECh. 2 - What about the following version?
Ch. 2 - Prob. 40ECh. 2 - Add a showPrice method to the TicketMachine class....Ch. 2 - Create two ticket machines with differently priced...Ch. 2 - Modify the constructor of TicketMachine so that it...Ch. 2 - Give the class two constructors. One should take a...Ch. 2 - Implement a method, empty, that simulates the...Ch. 2 - Prob. 46ECh. 2 - Predict what you think will happen if you change...Ch. 2 - Rewrite the if-else statement so that the method...Ch. 2 - Prob. 49ECh. 2 - In this version of printTicket, we also do...Ch. 2 - Is it possible to remove the else part of the...Ch. 2 - After a ticket has been printed, could the value...Ch. 2 - So far, we have introduced you to two arithmetic...Ch. 2 - Write an assignment statement that will store the...Ch. 2 - Write an assignment statement that will divide the...Ch. 2 - Prob. 56ECh. 2 - Modify your answer to the previous exercise so...Ch. 2 - Why does the following version of refundBalance...Ch. 2 - What happens if you try to compile the...Ch. 2 - What is wrong with the following version of the...Ch. 2 - Add a new method, emptyMachine, that is designed...Ch. 2 - Rewrite the printTicket method so that it declares...Ch. 2 - Challenge exercise Suppose we wished a single...Ch. 2 - List the name and return type of this method:
Ch. 2 - Prob. 65ECh. 2 - Write out the outer wrapping of a class called...Ch. 2 - Write out definitions for the following fields:
Ch. 2 - Write out a constructor for a class called Module....Ch. 2 - Prob. 69ECh. 2 - Correct the error in this method:...Ch. 2 - Write an accessor method called getName that...Ch. 2 - Write a mutator method called setAge that takes a...Ch. 2 - Write a method called printDetails for a class...Ch. 2 - Draw a picture of the form shown in Figure 2.3,...Ch. 2 - Prob. 75ECh. 2 - Create a Student with name "djb" and id "859012"....Ch. 2 - Prob. 77ECh. 2 - Challenge exercise Modify the getLoginName method...Ch. 2 - Consider the following expressions. Try to predict...Ch. 2 - Open the Code Pad in the better-ticket-machine...Ch. 2 - Now add the following in the Code Pad:...Ch. 2 - Add the following: t1.InsertMoney500; What would...Ch. 2 - Prob. 83ECh. 2 - Prob. 84ECh. 2 - Add a field, pages, to the Book class to store the...Ch. 2 - Are the Book objects you have implemented...Ch. 2 - Add a method, printDetails, to the Book class....Ch. 2 - Add a further field, refNumber, to the Book class....Ch. 2 - Modify your printDetai 1 s method to include...Ch. 2 - Prob. 90ECh. 2 - Add a further integer field, borrowed, to the Book...Ch. 2 - Prob. 92ECh. 2 - Prob. 93ECh. 2 - Prob. 94E
Knowledge Booster
Similar questions
- Write out definitions for the following fields: ■ a field called name of type String ■ a field of type int called age ■ a field of type String called code ■ a field called credits of type intarrow_forwardStatic & 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…arrow_forwardA field has access that is somewhere between public and private. static final Opackage Oprotectedarrow_forward
- How can you protect class fields from accidental corruption?arrow_forwardIf Cat is a derived class and Animal is a base class, which statement uses an Animal variable to reference a Cat object? Question 11 options: Cat myCat = new Animal(); Cat myCat = new Cat(Animal); Animal myAnimal = new Cat(); Animal myAnimal = new Animal(Cat);arrow_forwardHow to Define methods on a class?arrow_forward
- Which statement is true? Question 14 options: An abstract method is a method that appears in a base class but expects to be overridden in a derived class. An abstract method has only a header and no body. When an abstract method appears in a class, it must be overridden in any class that is derived from the class. All of the above.arrow_forwardComplete the Car class by creating an attribute purchase_price (type int) and the method print_info() that outputs the car's information. Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, then print_info() outputs: Car's information: Model year: 2011 Purchase price: $18000 Current value: $5770 1 class Car: 23 2 3 4 5 567 6 8 9 10 11 12 13 14 15 16 17 if 18 19 20 21 22 definit__(self): self.model_year # TODO: Declare purchase_price attribute self.current_value = 0 def calc_current_value(self, current_year): depreciation_rate = 0.15 # Car depreciation formula car_age = = __name__ year price current_year round(self.purchase_price* (1 - depreciation_rate) ** car_age) # TODO: Define print_info() method to output model_year, purchase_price, and current_value 0 current_year - self.model_year self.current_value "__main__": int(input()) int(input()) = 23 24 25 26 my_car.print_info() 27 = int(input()) my_car =…arrow_forwardPlease help me solve this with java..I posted it many times and got rejected I don't ? Game class instructions:• Game class has three attributes: points (which represent the number of points awarded when winning the game), status (false if the game has not been played and true if the game has been played), and description (which is a text description of the game). Note that description attribute is a read-only variable. • In the constructor, initialize points to zero, status to false, and description to the given parameter.• isPlayed method returns true if the game has been played, and false otherwise.• getPoints is a getter method for points attribute.• play method is an abstract method.• Override toString method to return the game description.• Override equals method so that two games are the same if their descriptions are the same. :instructions class ) HangMan• HangMan is a game in which a player tries to guess a word based on a given hint. For example, if the given hint is…arrow_forward
- Which of the statements regarding the super keyword is incorrect? (not correct) You can use super to invoke a super class constructor. You can use super to invoke a super class method. You can use super to access a field in the super class if it is protected. You can use super to access a field in the super class if it is private.arrow_forwardFill in the blanks to indicate the type of relationship between the classes listed below (use IS_A, HAS_A or N/A) Student String Schedule Student UniversityMember BookStorePreferredCustomer Student BookStorePreferredCustomer CanGraduate UniversityMember Student IDarrow_forwardPlease help with the question on the picturearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
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
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning