In the Winter quarter of 2016 we will begin our plans to colonize Mars. To begin
ID: 3662672 • Letter: I
Question
In the Winter quarter of 2016 we will begin our plans to colonize Mars. To begin with we will need a list of people to accomplish the mission. These can be represented by Java objects. The classes are diagrammed and explained on the following pages. We need astronauts/colonists and we will also need three shifts of ground crew to support the colony and the ships. There are two kinds of ships. The first is a cargo ship (Galactica) which has a crew of three. The second is a transport ship (Enterprize) to get the colonists to Mars. General Requirements: Write a complete program that will read a file containing the mission personnel list. This will be stored in a single ArrayList. Once the file is processed, you must write a report of the contents of the ArrayList without sorting it. An example of the output format will be provided This report will have the "Ship Roster", the Ground Crew Roster" and the "Colony Roster" e" Ground Crew Roster" and the "Colony Roster" Another file will be provided that updates the initially stored data on the personnel. It can add or remove members or change their characteristics. Once you have processed that file, you must write an updated report of the Array List contents without sorting it. This will be the same format as the initial output format. This report will have the "Ship Roster the "Ground Crew Roster" and the "Colony Roster" Finally,you will be required-te-previde-reperts ef )Alistof the erew members on eaeh ship-the fermat-will be previded 2) Alist of mission personnel sorted-by-identifieation-number-the-format-willbe previded ach class must have a constructor that provides the ability to provide all initial values for the object ou will need a driver class, named Mission, read, update, and report your activities. ead the syllabus for general instructions on all assignments. that provides the ability to provid all nitial valusfor the objeet Grading Criteria:Explanation / Answer
See sample code for main function below and update it accordingly:
------------------------------------------------
package missionmars;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
/**
* Class containing sample main function for mission personnel
*
*/
public class Mission {
/**
* Sample main function
*/
public static void main(String[] args) {
// ArrayList for mission persons
ArrayList<Person> persons = new ArrayList<Person>();
String initFileName = "./src/missionmars/Init.dat"; // change path as
// per your location
String updateFileName = "./src/missionmars/Update.dat"; // change path
// as per your
// location
Scanner scanner = null;
// Reading a "Init.dat" file
System.out.println("Processing Init.dat file...");
try {
scanner = new Scanner(new BufferedReader(new FileReader(initFileName)));
while (scanner.hasNext()) {
String keyword = scanner.next();
Person person = new Person(); // creates a new person
if (keyword.equals("Add")) {
/*
* You can replace print statements to set the corresponding
* properties of mission "person" in this block You can also
* replace the variables created by me accordingly.
*/
String personnelType = scanner.next();
System.out.println("Personnel type:" + personnelType);
String lastName = scanner.next();
System.out.println("Last name:" + lastName);
String firstName = scanner.next();
System.out.println("First name:" + firstName);
String birthDate = scanner.next();
System.out.println("Birth date:" + birthDate);
int idNumber = scanner.nextInt();
System.out.println("Id Number:" + idNumber);
String shipSpeciality = scanner.next();
System.out.println("Ship speciality/Ground job:" + shipSpeciality);
if (scanner.hasNextDouble()) {
double height = scanner.nextDouble();
System.out.println("Height:" + height);
double weight = scanner.nextDouble();
System.out.println("Weight:" + weight);
String shipAssignment = scanner.next();
System.out.println("Ship assignment:" + shipAssignment);
String colonySpeciality = scanner.next();
System.out.println("Colony speciality:" + colonySpeciality);
} else {
String shift = scanner.next();
System.out.println("Shift:" + shift);
}
persons.add(person); // adds a person to ArrayList persons
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (scanner != null) {
scanner.close();
}
}
// Prepare the report without sorting ArrayList
Iterator<Person> iterator = persons.iterator();
while (iterator.hasNext()) {
Person person = iterator.next();
/*
* Process this person object to prepare report here as per
* requirement.
*/
}
// sort the list
// Collections.sort(persons); //for this to work, your Person class
// should implement Comparable<Perosn> interface for compareTo() method.
// Report for sorted list can be prepared as given above.
// Reading "Update.dat" file
System.out.println("Processing Update.dat file...");
try {
scanner = new Scanner(new BufferedReader(new FileReader(updateFileName)));
while (scanner.hasNext()) {
String keyword = scanner.next();
Person person = new Person(); // creates a new person
if (keyword.equals("Add")) {
/*
* You can replace print statements to set the corresponding
* properties of mission "person" in this block You can also
* replace the variables created by me accordingly.
*/
String personnelType = scanner.next();
System.out.println("Personnel type:" + personnelType);
String lastName = scanner.next();
System.out.println("Last name:" + lastName);
String firstName = scanner.next();
System.out.println("First name:" + firstName);
String birthDate = scanner.next();
System.out.println("Birth date:" + birthDate);
int idNumber = scanner.nextInt();
System.out.println("Id Number:" + idNumber);
String shipSpeciality = scanner.next();
System.out.println("Ship speciality/Ground job:" + shipSpeciality);
if (scanner.hasNextDouble()) {
double height = scanner.nextDouble();
System.out.println("Height:" + height);
double weight = scanner.nextDouble();
System.out.println("Weight:" + weight);
String shipAssignment = scanner.next();
System.out.println("Ship assignment:" + shipAssignment);
String colonySpeciality = scanner.next();
System.out.println("Colony speciality:" + colonySpeciality);
} else {
String shift = scanner.next();
System.out.println("Shift:" + shift);
}
persons.add(person); // adds a person to ArrayList persons
} else if (keyword.equals("Remove")) {
int idNumber = scanner.nextInt();
System.out.println("Id number to remove:" + idNumber);
// write corresponding statements here to remove idNumber
// from list
} else if (keyword.equals("Change")) {
int idNumber = scanner.nextInt();
System.out.println("Id number to change:" + idNumber);
String token = scanner.next();
if (token.equals("W")) {
double wt = scanner.nextDouble();
System.out.println("New weight value:" + wt);
// write corresponding statements to change weight here
// of a person as per the Id number.
} else if (token.equals("H")) {
double ht = scanner.nextDouble();
System.out.println("New height value:" + ht);
// write corresponding statements to change height here
// of a person as per the Id number.
} else {
System.out.println("New shift value:" + token);
// write corresponding statements to change shift here
// of a person as per the Id number.
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (scanner != null) {
scanner.close();
}
}
}
}
----------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.