{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment02 - 2.65 – public int getAge return age 2.73...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
2.9 – Fields: private int price; private int balance; private int total; Constructor: public TicketMachine(int ticketcost){ Methods: public int getPrice(){, public int getBalance(){, public void insertMoney(int amont){, public void printTicket(){ 2.26 – getPrice is an int (integer) class/method while printTicket is a void class/method 2.36 – Instead of printing out the actual value of the ticket, it would just print out the word “price” 2.42 – public setPrice(int cost){ price = cost; } Public setPrice(){ price = 500; } 2.57 – public void printTicket{ private int amountLeftToPay; amountLeftToPay = (balance - price); if(amountLeftToPay == 0){ System.out.print(“Ticket price fully paid.”); } else{ System.out.print(“Ticket not completely paid for, “ + amountLeftToPay + “ remains.”
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } 2.65 – public int getAge(){ return age; } 2.73 – if(name.length < 4 || id.length < 3){ return name.substring(0,name.length) + id.substring(0,id.length); } else{ return name.substring(0,4) + id.substring(0,3); } } 2.77 – public void printDetails();{ System.out.println(“Title: ” + title); System.out.println(“Author: ” + author); System.out.println(“Pages: ” + pages); } 2.80 – if(ref.length >= 3){ refNumber == ref; } else{ System.out.println(“ERROR”); } } 2.20 – The problem with the code is that price is being re-declared as an int in the method. The version does compile, but the value of ticketCost remains at zero because every time the method is called, price is re-declared and the value set to 0....
View Full Document

{[ snackBarMessage ]}