Write code to define an abstract class

Assignment Help Basic Computer Science
Reference no: EM13689741

a. Write code to define an abstract class 'Passenger" with the following attributes: account_num, fname, lname, points, num_pass (NB this is a class variable which keeps a tally on the number of passenger objects created)
There is only one constructor that receives: account_num, fname, lname, points. You must also include the necessary 'getters' and 'setters' (where appropriate) to make the attributes available. Include an abstract method 'calcPoints' that returns nothing but accepts the cost of the ticket.

b. Write a method 'toString' for the Passenger object defined above. This method must return a string stating the: account_num, fname, lname, points of the Passenger in a well structured sentence/format.

c. Define a separate class 'Regular' which is a subclass of 'Passenger'. In the constructor of this new class ensure that you invoke the constructor of the parent class 'Passenger' to initialize the inherited variables. Implement the 'calcPoints' method as follows:
1. Finds the current points by dividing the ticket cost by 10 e.g. $1500 / 10 = 150 points
2. Adds the current points to the points already accumulated
[4 marks]

d. Define a separate class 'Premium' which is a subclass of 'Passenger'. In the constructor of this new class ensure that you invoke the constructor of the parent class 'Passenger' to initialize the inherited variables. Implement the 'calcPoints' method as follows:
1. Finds the current points by dividing the ticket cost by 5 e.g $1500 / 5 = 300 points
2. Adds the current points to the points already accumulated


e. Write a separate class 'Airline' which contains a main method. In the main method you must create four objects: two Regular Passenger and two Premium Passenger. Next you are required to create an array 'pass_arr' of type 'Passenger'of size 4. Store the four account objects in this array. Finally you are required to perform the following operations on the objects:
i. Traverse the array and display the information for each Passenger by invoking the 'toString()' method you wrote in part b.
ii. Traverse the array and invoke 'calcPoints' for each Passenger to update the points earned thus far.
iii. Output the updated array.

NB. To create the 'Regular' and 'Premium' Passenger objects above you are free to 'hard code' the attribute values.

Reference no: EM13689741

Questions Cloud

Determine the cheetahs average acceleration : The cheetah can reach a top speed of 114 km/h (71 mi/h). Determine the cheetah's average acceleration during the short sprint
Management information systems : Management Information Systems
What is the angle of incidence at the glass-to-air surface : A ray of light is incident on the mid-point of a glass prism surface at an angle of 20º with the normal. What is the angle of incidence at the glass-to-air surface on the side opposite where the ray exits the prism
Process the data fields through 2nf and 3nf : Process the data fields through 2NF and 3NF
Write code to define an abstract class : Write code to define an abstract class
What is its temperature in degrees fahrenheit : You work in a materials testing lab and your boss tells you to increase the temperature of a sample by 36.8oC. what is its temperature in degrees Fahrenheit
Final project plan : Final Project Plan
What is the force constant of this spring : You find that if you hang a 1.75kg weight from a vertical spring, it stretches 2 90cm. What is the force constant of this spring in N/m
What is his speed just before his feet : A 81-kg man steps out a window and falls (from rest) 1.2 m to a sidewalk. What is his speed just before his feet strike the pavement

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What sizes in memory in c++ and size of a char and a string

What are the sizes in memory of other data types in C++? I mean, I know that a double is 8 bytes and an int is 4 bytes. What is the size of a Char and a String?

  Compute the mean and standard deviation of the rolls

Also, your application should show a table that shows each possible roll of the dice and its frequency of occurrence in the simulation in a listbox. In other words, the table shows the count of a roll of 2, the count of a roll of 3, and so on up t..

  Write ethical issues involved in eliminating jobs in k-mart

Sears is losing market share, has been acquired by K-Mart, and is eliminating jobs; Wal-mart is gaining market share and hiring. Write ethical issues involved, and which firm has a more ethical position?

  Why does the label control that contains your name print

why does the label control that contains your name print above the page number?

  Discuss the issues of encryption and key management

Discuss the issues of encryption and key management in cloud computing, how it different for personal computers and traditional enterprising computing environments.(1300-1400 words)

  Which of these is a repository of security-related

Which of these is a repository of security-related documentation and also sponsors a number of security research projects? A) F-Secure B) Computer Emergency Response Team C) Microsoft Security Advisor D) SANS Institute.

  Dis-assemble each of the following

Dis-assemble each of the following MIPS R2000 object code into source code instructions. Use register names, such as $t2, instead of numbers, such as $20.

  Primarily a product survey of a small system

Primarily a product survey of a small system that would have the specifications to meet the requirements of an a financial investment or architectural firm

  Write some code that swaps their values

Given two int variables, firstPlaceWinner and secondPlaceWinner , write some code that swaps their values. Declare any additional variables as necessary.

  Explain reasons for consulting different kinds of sources

Explain reasons for consulting different kinds of sources on the same subject.

  Discuss the role of incident containment in an incident

Discuss the role of incident containment in an incident response strategy and how a lack of planning for containment is a potential pitfall for any response strategy.

  Returns the bottom of the stack instead of the top

This function returns the bottom of the Stack instead of the top

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd