Chapter 2 Questions

2.2 The value returned is zero
2.6  public student TicketMachine
{
}
public LabClass TicketMachine
{
}
2.9 Fields: private int price; private int balance;  private int total
private int total;
Constructors: * Create a machine that issues tickets of the given price.
* Note that the price must be greater than zero, and there
* are no checks to ensure this.
Methods: price = ticketCost;
balance = 0;
total = 0;
2.10 No, the constructors are very similar to the methods of the class.
2.11 int, string, string
2.12 boolean alive, person tutor, Game game
2.15 private int status
2.16 student class
2.17 two parameters; types: string and double
2.18 private int Book
2.19 public Pet(string petsName)
{
private string name;
name=petsName;
}
2.20 take away the int before price
2.21 there is no difference besides the balance and price parts
2.22 What is the current balance?
2.24 The get methods of a ticket machine perform similar tasks-returning the value of one of their object's fields
2.26 get price returns data while the printTicket prints information
2.27 They do not have return statements because one stores money and the other displays it
2.29 You can tell because it says void
2.31 return price+increase;
2.32 return price-discount;
2.35: They show two different outputs because the costs are different.
2.36: It would print out just price, not the user inputted price..
2.37: It would probably come up with an error, because cents is not defined.
2.38: No, because one doesn’t display the price, and the other has an error.
2.44: nothing is going to change because zero is positive.
2.45: it controls the size of the circles and the intergers associated with it.
2.47: yes it could be set to negative
2.49: price * discount = saving;
2.50: total / count = mean;
2.51: if ( price>budget)
{
comment = “Topo expensive.”;
}
else
{
comment = “Just right.”;
}
2.52: if ( price>budget)
{
comment = “Topo expensive.”;
}
else
{
comment = “Please enter the correct amount:” price;
}
2.53: because it is returning the balance after it clears it.
2.54: because you are returning the balance and then instantly clearing it, so your actualy balance shown will not be correct.
2.55: it is both
2.59: the name is getCode and the return is code
2.60: the name is setCredits and the parameter is creditValue
2.62: allows the input of characters to spell out a name, allows the input of numbers to write an age, allows the input of characters to write out a code, allows the input of numbers to shows credits
2.65: public int getAge()
2.68: public class printDetails
{
private String name;
name = setName;
comment = “The name of this person is:” name;
}
2.74: 102, catfish, cat9, 12cat, cat12
Advertisement

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.