LockerApp - { Locker tempLocker = new Locker(); int i = 0;

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
package lab5; import java.util.*; import java.io.*; public class LockerApp { p public static void main(String[] args) { p int MAXSIZE = 15; Locker [] lockerArr = new Locker [MAXSIZE]; String input, decision, line; S Scanner console = new Scanner(System.in); System.out.println("Enter File Name: >"); input = console.next(); FileRead file = new FileRead(input); line = file.readLine(); String id, combo; int idd; System.out.println("CURRENT LOCKERS AND COMBINATIONS"); for(int i = 0; line!=null; i++) { int comma = line.indexOf(","); id = line.substring(0,comma); combo = line.substring(comma+1, line.length()); idd = Integer.parseInt(id); lockerArr[i]=new Locker(idd, combo); System.out.println(lockerArr[i].toString()); line = file.readLine(); } System.out.println("WOULD YOU LIKE TO SWAP THE FIRST AND LAST LOCKERS? Y/N >"); decision = console.next(); if(decision.equalsIgnoreCase("y"))
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { Locker tempLocker = new Locker(); int i = 0; while(lockerArr[i]!=null) { { i++; } tempLocker = lockerArr[0]; lockerArr[0] = lockerArr[i-1]; lockerArr[i-1] = tempLocker; System.out.println("PRINTING FILE. PLEASE WAIT"); } else { System.out.println("NO CHANGES MADE. PRINTING FILE. PLEASE WAIT"); } System.out.println("CHOOSE A NAME FOR YOUR OUTPUT FILE >"); String outFile = console.next(); Locker lockerTrick = new Locker(100000, "Empty"); for(int i = 0; i<lockerArr.length-1; i++) { if(lockerArr[i]!=null) { lockerArr[i]=lockerArr[i]; } else { lockerArr[i]=lockerTrick; } } try{ FileWrite file1 = new FileWrite(outFile); for(int i =0; i<lockerArr.length-1; i++) { file1.writeToObject(lockerArr[i].toString()); line = file.readLine(); } file1.close(); } catch(IOException ioe){ioe.printStackTrace(); } } }...
View Full Document

This note was uploaded on 09/10/2009 for the course CS 102 taught by Professor Kanipiakins during the Spring '09 term at University of Maryland Baltimore.

Page1 / 2

LockerApp - { Locker tempLocker = new Locker(); int i = 0;

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

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