Paperless checkout

/****

== Prototype ==

So far we have seen how to READ a sequential text-file.

It is also possible to WRITE data into a sequential text-file.

The writing must be SEQUENTIAL. That means it is NOT POSSIBLE

to insert new data into the middle of the file, or to change

the data that is already in the file.

The simplest way is to add data is to APPEND to the file - that means write some more

data at the end of the file. The following program uses this idea

to save the name and time for each student leaving from or returning

to a class. Each new event is simply appended (added) to the

end of the list. At the end of the day, all the events for the

entire day are stored in a long list.

The file must be OPENED with the following command:

PrintWriter file =

new PrintWriter(new FileWriter("log.txt",true));

The "true" flag means the data will be appended. Otherwise, the

ENTIRE FILE WILL BE ERASED before writing the data.

RUNPROGRAM is a special command in EasyApp that executes an

external program. This causes Explorer to display the text file.

== The Problem ==

The intention of this program is to REPLACE the paper sheets

used for keeping track of students who leave class. The paper

sheets are convenient for the signing in and out, but they present

a large problem for the office. There are 100 teachers each turning

in 5 sheets each week to the office. Then the secretary must read

all 500 sheets to collect information about individual students.

An automated program should be able to sort out the information

and present a clear list to the administration.

We will be creating this program over the next couple weeks.

Before proceeding, it's best to do a complete DESIGN of the

desired program, so that it meets the users' needs.

== Prototype ==

Part of the design process is creation of a PROTOTYPE. That is a

simple example program. It is not a "finished" program - rather it is

used to help the INTENDED USER and the DESIGNER to think about

the problem and to agree on useful FEATURES. We will start our

project with the following prototype.

== Starting ==

(1) Look at the EXISTING PAPER VERSION of the check-out system.

(2) Draw a diagram of the ENTIRE EXISTING SYSTEM.

(3) Run the prototype.

(4) Write down a few ideas related to the following questions:

CONVENIENCE -

Compare the prototype and paper in terms of convenience.

Suggest some changes that would improve convenience.

RELIABILITY -

Compare the prototype and paper in terms of reliability.

Suggest some changes that would improve reliability.

SECURITY -

Are there any security issues in this system?

Compare the prototype and paper in terms of security.

Suggest some changes that would improve security.

********/

import java.awt.*;

import java.io.*;

public class CheckOut extends EasyApp

{

public static void main(String[] args)

{

new CheckOut();

}

Button bSignOut = addButton("Sign out", 50,50,100,50,this);

Button bSignIn = addButton("Sign in ",150,50,100,50,this);

Button bReadLog = addButton("Read log",250,50,100,50,this);

public void actions(Object source, String command)

{

if (source == bSignOut)

{ signOut(); }

else if (source == bSignIn)

{ signIn(); }

else if (source == bReadLog)

{ readLog(); }

}

public void signOut()

{

try

{

String name = input("Name:");

String time = input("Time:");

String reason = input("Reason:");

PrintWriter file =

new PrintWriter(new FileWriter("log.txt",true)); // append

file.println("~~ Leaving ~~");

file.println(name);

file.println(time);

file.println(reason);

file.close();

}

catch (IOException ex)

{ output(ex.toString()); }

}

public void signIn()

{

try

{

String name = input("Name:");

String time = input("Time:");

PrintWriter file =

new PrintWriter(new FileWriter("log.txt",true)); // append

file.println("~~ Returning ~~");

file.println(name);

file.println(time);

file.close();

}

catch (IOException ex)

{ output(ex.toString()); }

}

public void readLog()

{

runProgram("explorer.exe log.txt");

}

}