


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Unknown 1989;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Last Time We started looking at a ticket machine, and started looking at the parts.
Say we have a class named Counter that has one field: int count. What does the constructor look like? Say we have a class named Animal that has two fields: String variety, and int numLegs. What does the constructor look like? Methods We’ve seen a bunch of methods already. Some of them returned information about the state of the object – others changed the state of the object. Let’s look at the getPrice method (in class TicketMachine). Two parts:
The first 6 statements print the ticket. They call a special method provided by Java: System.out.println. This method takes the contents of its parameter, and displays it in a text window. The first 3 lines just print a String (followed by a newline – that is, the cursor is positioned at the beginning of the next line after the String is displayed.) The next line is more interesting: System.out.println(“# “ + price + “ cents.”); The ‘+’ operators construct a single String from the parts. When used with a String and anything else (an int, another String, etc.), the + operator generates a new String with the parts concatenated. The last println() doesn’t have a parameter – what does it do? Exercise (IN PAIRS)