Starting from:
$28

$19.60

SOLVED Assignment 14: Space Craft

Objectives

  • Create a Space Craft class.
  • Create classes which build on Space Craft: Space Station and Space Shuttle.
  • Create a toString method for each class.
  • Store a list of objects in an ArrayList.

Motivation

In this program, you will be creating an application to hold various types of space craft.

Instructions

Name your project FirstnameLastnameAssignmentNumber

The Space Craft Class

A space craft is a generic term for an object in space which holds people. The SpaceCraft class needs to be a public abstract class. People sit in seats. Your SpaceCraft class should have the fields:

  • String name; // The name of the space craft
  • int seats; // How many people can sit in this space craft.
  • Constructor(String name, int seats): Assigns the parameters to the fields.
  • getName(): String: Returns the name of the space craft.
  • getSeats(): int: Returns the number of seats.
  • Override toString(): String: Returns a string containing the name and number of seats in this generic space craft.

Methods

The Space Station Class

A space station doesn't move in space. It houses people. The SpaceStation class needs to extend SpaceCraft. It should have the following fields:

  • int ports; // Number of ports on this space station.
  • Constructor(String name, int seats, int ports): Assigns the parameters to the fields.
  • getPorts(): int: Returns the number of ports.
  • Override toString(): String: Returns the name and number of ports on this space station.

Methods

The Space Shuttle Class

A space shuttle moves people around in space. A space shuttle has engines. The SpaceShuttle class needs to extend SpaceCraft. It should have the following fields:

  • int engines; // Number of engines on this space station
  • Constructor(String name, int seats, int engines): Assigns the parameters to the fields.
  • getEngines(): int: Returns the number of engines.
  • Override toString(): String: Returns the name and number of engines on this space shuttle.

Methods

Main Method

Your main method should begin with an empty ArrayList of SpaceCraft objects.

Write a menu based application which does the following:

  1. Adds a new station to the list. You will need to prompt for three parts of a station.
  2. Adds a new shuttle to the list. You will need to prompt for three parts of a shuttle.
  3. Display the number of space craft in the list.
  4. Display the number total number of seats in all space craft in the list.
  5. Display a description of all space craft.
  6. Quit the software.
  7. The only class which is allowed to have print statements is the class with your main method. If any methods have a print statement outside this class, you will get an automatic 0. I'm writing this because it is a bad programming practice to put print statements in methods outside of main.

Notes

Example Run

In this example run, I add Deep Space Station K-12 and the Enterprise to my space craft organizer. Your organizer should behave like this for full credit.

Welcome to James Church's Space Craft Organizer.
1. Add a new space station.
2. Add a new space shuttle.
3. Display count of all space craft.
4. Display count of number of seats.
5. Display description of all space craft.
6. Quit.
Enter an option from 1 to 6: 1

Enter a new Space Station.
Enter the name: K-12
Enter the number of seats: 1000
Enter the number of ports: 100

1. Add a new space station.
2. Add a new space shuttle.
3. Display count of all space craft.
4. Display count of number of seats.
5. Display description of all space craft.
6. Quit.
Enter an option from 1 to 6: 2

Enter a new Space Shuttle.
Enter the name: Enterprise
Enter the number of seats: 500
Enter the number of engines: 2

1. Add a new space station.
2. Add a new space shuttle.
3. Display count of all space craft.
4. Display count of number of seats.
5. Display description of all space craft.
6. Quit.
Enter an option from 1 to 6: 3

There are 2 space craft.

1. Add a new space station.
2. Add a new space shuttle.
3. Display count of all space craft.
4. Display count of number of seats.
5. Display description of all space craft.
6. Quit.
Enter an option from 1 to 6: 4

There are 1500 seats across all space craft.

1. Add a new space station.
2. Add a new space shuttle.
3. Display count of all space craft.
4. Display count of number of seats.
5. Display description of all space craft.
6. Quit.
Enter an option from 1 to 6: 5

All Space Craft.
Space Station K-12 has 100 ports.
Space Shuttle Enterprise has 2 engines.

1. Add a new space station.
2. Add a new space shuttle.
3. Display count of all space craft.
4. Display count of number of seats.
5. Display description of all space craft.
6. Quit.
Enter an option from 1 to 6: 6

Documentation

Your source code must include the following documentation:

  • Your name
  • The class (CS 2070) and the section number (on ground is 08, online is W1).
  • The date on which you turned in the assignment.
  • A short description of the software. Usually a sentence or two is sufficient.

Turning it in.

To turn in your application, find the folder containing your entire project (not the folder with the "java" file), zip it up, and turn it in.