Object Oriented Programming csc2071 Lab Plan – 4 Topic : Constructors



Download 31.54 Kb.
Date15.03.2021
Size31.54 Kb.
#56069
CSC2071 - Lab Plan 4
Ali Muhammad 1089 Lab2 SQL

Object Oriented Programming - CSC2071

Lab Plan – 4

Topic : Constructors






Create a Trip class which contains destination, distance traveled, total cost of gasoline, and number of gallons consumed data members. Write appropriate constructors and properties. Add additional methods that calculates miles per gallon and the cost per mile.









Write a class Fraction that define method Compare. The Compare method accepts two Fraction objects f1 and f2. The method returns:

-1 if f1 is less than f2

0 if f1 is equal to f2

+1 if f1 is greater than f2



Also write appropriate constructor which copies the Fraction object.









There are a number of national and state parks available to tourists. Create a Park class which should have name of park, location, type of (i.e., national, state, local) facility, fee, number of employees, number of visitors recorded for the past 12 months, and annual budget data members. Write instance methods that:

  1. Return a string representing name of the park, the location and type of park.

  2. Return a string representing the name of the park, the location and facilities available

  3. Compute cost per visitor based on annual budget and the number of visitors during the last 12 months.

  4. Compute revenue from fees for the past year based on number of visitors and fee.









Write a program that includes an Employee class which should have employee number, name, date of hire, job description, department, and monthly salary data members. The class should be to calculate and print the take-home pay for a commissioned sales employee. All employees receive 7% of the total sales. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Write instance methods to calculate the commission income, federal and social security tax withholding amounts and the amount withheld for retirement. Use appropriate constants, design an object-oriented solution, and write constructors. Include at least mutator and one accessor method; provide properties for the other instance variables. Allow the user to enter values for the name of the employee and the sales amount for the week.









Create a Motorway class that can be used as extra documentation with directions. Include data members such as name of motorway, type (i.e., Road, Street, Avenue, Blvd., Lane, etc.), direction (i.e., E, W, N, or S), surface (i.e., blacktop, gravel, sand, concrete), number of lanes, toll or no toll, and the party that maintains it. Write instance methods that returns the full name of the motorway, whether it is toll or not, and the number of lanes. Write appropriate method that returns all data members with appropriate values. Include enough constructors to make the class flexible and experiment with using the class diagram to create the property members.









Write a class MealCard that keeps track of a student’s food purchases at the campus cafeteria. A meal card is assigned to an individual student. When a meal card is first issued, the balance is set to the number of points. If the student does not specify the number of points, then the initial balance is set to 100 points. Points assigned to each food item are a whole number. A student can purchase additional points at any time during a semester. Every time food items are bought, points are deducted from the balance. If the balance becomes negative, the purchase of food items is not allowed. Write appropriate Main method to check the working of the class.



/1

Download 31.54 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page