Menu - /* * Jesus Campos * CS-116-004 * Final Project -...

Info iconThis 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]));
Background image of page 1

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

View Full DocumentRight 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]);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/18/2009 for the course CS 116 taught by Professor Theys during the Spring '07 term at Central Texas College.

Page1 / 6

Menu - /* * Jesus Campos * CS-116-004 * Final Project -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online