## Practice Problems: Creating Classes and Objects

Try these problems, don’t just look at the answers. If you do look at the answers and find you made mistakes, write the answers out again by hand, even if you are mostly copying the answers. People learn differently from writing versus reading details: you are much more likely to absorb the pattern of defining classes if you actually write it down yourself. If you type instead of write by hand, don’t use cut and paste. You actually have to write out the characters yourself to help you absorb the patterns.

### 1The Problems

• Create a class that captures students. Each student has a first name, last name, class year, and major. Create two examples of students.

• Create a class that captures planets. Each planet has a name, a distance from the sun, and its gravity relative to Earth’s gravity. For distance and gravity, use the type double which captures real numbers. Make objects for Earth and your favorite non-earth planet.

• Create classes that capture bank customers and bank accounts. A customer has a first and last name. An account has a customer and a balance. Make objects for two accounts held by the same customer.

• Create a class that captures airline tickets. Each ticket lists the departure and arrival cities, a flight number, and a seat assignment. A seat assignment has both a row and a letter for the seat within the row (such as 12F). Make two examples of tickets.