Menu - Jesus Campos CS-116-004 Final Project Menu Class The...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/** * Jesus Campos * CS-116-004 * Final Project - Menu Class * The menu class is the program driver. It performs the tasks that the user wants to do. It uses methods * from the other classes to accomplish changes in the data. **/ package code2; import java.io.IOException; import java.util.Scanner; i public class Menu { FileRead fr; String line; String [] tokens; Scanner console = new Scanner(System.in); /** * The readFile method uses the file reader to read the data from the selected file. It creates objects * depending on the data that is fed throught the file reader. It reads one line at a time. It creates an * array of Strings. It uses the line.split command to separate the line into smaller strings. Each string * is then put into a slut in the array. Then depending on how many elements the array has, it determines what * type of object (structure, damaged, destroyed, etc) it should be. It then places each object into the main array. * @param someList * @param someString */ public void readFile(List someList, String someString) { FileRead fr = new FileRead(someString); line = fr.readLine(); while(line!=null) { tokens = line.split(","); if(tokens.length==5) { Structure tempStructure = new Structure(new Id(tokens[0]), tokens[1], tokens[2], Double.parseDouble(tokens[3]), Integer.parseInt(tokens[4]), tokens[5]); someList.insert(tempStructure); } else if(tokens.length==6) { Destroyed tempDestroyed = new Destroyed(Integer.parseInt(tokens[6])); tempDestroyed.setId(new Id(tokens[0])); tempDestroyed.setAddress(tokens[1]); tempDestroyed.setType(tokens[2]); tempDestroyed.setValue(Double.parseDouble(tokens[3])); tempDestroyed.setPriority(Integer.parseInt(tokens[4]));
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
tempDestroyed.setNotes(tokens[5]); someList.insert(tempDestroyed); line = fr.readLine(); } else if(tokens.length==7) { Condemned tempCondemned = new Condemned(Integer.parseInt(tokens[6]), Integer.parseInt(tokens[7])); tempCondemned.setId(new Id(tokens[0])); tempCondemned.setAddress(tokens[1]); tempCondemned.setType(tokens[2]); tempCondemned.setValue(Double.parseDouble(tokens[3])); tempCondemned.setPriority(Integer.parseInt(tokens[4])); tempCondemned.setNotes(tokens[5]); someList.insert(tempCondemned); line = fr.readLine(); } else if(tokens.length==8) { Damaged tempDamaged = new Damaged(Integer.parseInt(tokens[6]), Integer.parseInt(tokens[7]), Double.parseDouble(tokens[8])); tempDamaged.setId(new Id(tokens[0])); tempDamaged.setAddress(tokens[1]);
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern