Handson exam CS 21a Section B

  1. Download the following BlueJ Project . Extract and compile the programs under the project. (You will notice that BusTester2.java does not compile). Read the following instructions carefully and carry out all the tasks indicated.
  2. There is a working Bus class provided in the project. BusTester1 is the tester program that creates a Bus object and calls the methods under this class. Execute BusTester1 and study the methods of the Bus class. Observe that:
  3. For this handson exam, you will revise Bus.java and complete BusTester3.java (a bare program has been provided).
  4. Revise Bus.java, so that a bus now has a passenger capacity and the fare collected is stored (there should be two additional instance fields). In particular: BusTester2.java tests this new version of Bus. Study that program and understand what it is testing. You will know you are done with your revisions if this program compiles and produces the following output:
    Bus has 85 passengers; fare collected: 1912.50
    Some passengers were not loaded
    Bus has 100 passengers; fare collected: 2250.00
    Bus has 0 passengers; fare collected: 2250.00
    -----
    Bus has 15 passengers; fare collected: 337.50
    Some passengers were not loaded
    Bus has 25 passengers; fare collected: 562.50
    Some passengers were not loaded
    Bus has 25 passengers; fare collected: 562.50
    Bus has 0 passengers; fare collected: 562.50
    Bus has 15 passengers; fare collected: 900.00
    
  5. Complete BusTester3.java so that it first asks the user for the following input (use the Scanner class): Then, create a bus object with the provided passenger capacity, make three calls to loadPassengers(), one for each of the sizes provided, and then print the resulting passenger count and fare collected for the bus. Here is a sample execution of BusTester3 (portions in bold represents user input):
    Type in bus passenger capacity: 100
    Type in the size of first set of passengers: 10
    Type in the size of second set of passengers: 20
    Type in the size of third set of passengers: 30
    Bus has 60 passengers; fare collected: 1350.00
    
    If, in the above execution, you instead input 50 as the capacity, one message should be printed (indicating some passengers were not loaded) and the bus should result in 50 passengers and 1125.00 in fare collected.
  6. Make sure that your name is written in the header comment portion of Bus.java and BusTester3.java. Zip the revised BlueJ project, and rename the zipfile to Handson1B-[Lastname].zip. Submit the zip file via moodle .