A car garage sells cars. Every time a customer buys a new car, a computer program creates a Car object in computer memory. Each object stores:
  • The name of the car eg "Toyota Camry"
  • The engine size of the car eg 3.6
  • The cost of the car eg $24000USD
Design a Constructor method for the Car class. Every time a Car object is constructed, the three pieces of data above are passed as parameters into the object and stored safely.
A computer game character has the following attributes:
  • Strength Index eg 1, 7, 10 etc
  • Health Indicator eg 1, 2, 3 etc
  • Color eg "Green", "Red", "Blue"
  • A weakness indicator: this is 0 if the Strength Index is less than 5 and 1 if the Strength index is more or equal to 5
Design a Constructor method for the Character class. Every time a Character object is constructed, the first three pieces of data above are passed as parameters into the object and stored safely.The last piece of data is assigned by some code within the Constructor method.
An airline company stores flight information in Flight objects. It stores 2 pieces of data in each object: the flight code and the destination. The flight codes are always 2 letters followed by three numbers eg sp065 or fr103. The two letters indicate the destination and are limited to:
  • fr = "france"
  • sp = "spain"
  • gy = "germany"
  • pg = "portugal"
Design a Constructor method for the Flight class. Every time a Flight object is constructed, only the flight code is passed as a parameter into the object and stored safely.The destination is determined by some code within the Constructor method and then stored safely.