Java - Assignment 2 [Archive] - Eyes Out Entertainment Forums

View Full Version : Java - Assignment 2


Kurosaki
03-15-2006, 08:44 PM
Hmm... Anyone know java? Apologies. Its a big post. If you want it removing just say :P

MANCHESTER METROPOLITAN UNIVERSITY
DEPARTMENT OF COMPUTING & MATHEMATICS
ASSIGNMENT COVER SHEET
__________________________________________________ ___________

COURSE: Computer Studies Network

UNIT: Advanced Programming

LECTURER: J.Tyrrell/R.Saberton

ASSIGNMENT NUMBER: 2 ASSIGNMENT TYPE:(GROUP/INDIVIDUAL)

ISSUE DATE: 6 February 2006

HAND-IN DATE: 17th March 2006
(after which maximum obtainable mark is 40%)

ABSOLUTE DEADLINE: 31 March 2006
(after which mark is 0%)

HAND-BACK DATE: 24 April 2006

No responsibility is accepted by the Department if an assignment is lost. To cover this eventuality, you are advised to take a photocopy of your assignment or to ensure you have the means of re-creating it.


PLAGIARISM: Students are reminded that plagiarism (copying) is a serious disciplinary matter. Checks are regularly made for misuse of the web and other existing materials. See Regulations for Undergraduate Programmes of Study

PROCEDURE FOR HANDING IN WORK: see Faculty Student Handbook. Follow any specific instructions given on the assignment specification.

PENALTIES FOR LATE HAND-IN: see Regulations for Undergraduate Programmes of Study

EXCEPTIONAL FACTORS AFFECTING YOUR PERFORMANCE: see Regulations for Undergraduate Programmes of Study

ASSESSMENT CRITERIA: see attached assignment specification
__________________________________________________ ___________



CS Network
Advanced Programming: Assignment 2

The aim of this assignment is to provide a GUI interface for classes Person and Store. It is important therefore, that Date, Person and Store are all working. You will not need classes Student and PartTime for this assignment.

Requirements

You are required to produce a system that allows a user to do the following:

a) enter a Person record using a form displayed on the screen;
b) save the entered record to a store;
c) retrieve and display records from the store; each time
this option is selected the next record is displayed; when the
end of the store is reached the first record is displayed;
d) save a store to a file;
e) retrieve a store from a file.

A complete system should be robust – e.g. if a user tries to retrieve records and none
are saved it should not crash, and should preferably display an error message. Similarly it
should prevent a user from opening a new store without saving an existing one – or better
still ask the user to confirm the action.

A complete system will also allow photographs to be stored and retrieved with each person.
A collection of photographs you may use will be found on:

There was a link here to where you could find photo's of some of us in the class to use...but, theres one of me there and im hideous so the link has been removed for the sake of you tearing your eyes out.

The following provides a step by step guide to the assignment. You may, if you wish, tackle it in your own way.


Step 1. Amend Class Store

Add the following to class Store.

private int current =0;

public incrementPointer()
// pre: store is not empty
// post: increments current;
// if current is already pointing to the
// last record in the Store then reset it to 0

public Person currentRecord()
// pre: store is not empty
// post: returns the person accessed by current
// e.g. if current = 6, then the object at location 6
// will be returned

Step 2 Design Basic Frame with Menus

Design a basic frame for your system – make it inherit from CloseableFrame.
You could begin with a menu bar which has two menus: File and Record
The menu items for File would be New, Save and ReadIn
The menu items for Record would be Add, Display and Clear.
leave the event handlers until a little later.

Step 3 Design an InputForm

Design an input form for a Person. First make a drawing of the input form
you wish to use. Then code it within the frame you have already developed.
(You will probably need to use Panels)


Step 4 Add some variables to your frame

Add to your frame class an instance variable of type Store.
Also add the following boolean instance variables: storeOpen, fileOpen, fileSaved.
These will be used later to allow you to prevent users from doing things which
could be fatal to the system.


Step 5 Add Event Handlers to Your Frame

Add the following methods to your frame class.

private void newStore()
// pre: true
// post: if storeOpen and not fileSaved
// displays error message
// else creates Store with default max size of 100
// sets storeOpen to true
// sets fileSaved to true

private void clear()
// pre true
// post: all text fields set to default values



private void add()
// pre: true
// post: if storeOpen
// creates Person (local variable) from input form values
// adds Person to Store
// sets fileSaved to false
// else displays error message

Note – one way to display error messages is to use a dedicated text field.
When you have coded the above methods you should then complete the event
handlers that will call each of the above methods.
At this point your system should be able to create a Store and to add records to it.

Step 6 Implement the Event Handler which Displays records in the Store

Implement the following method. You may either display a record on the
input form, or on a Canvas.

private void display()
// pre: true
// post: if not storeOpen
// display error message
// else if store is empty
// display error message
// else
// retrieve current record from Store and display it
// advance pointer in store

Now implement the event handler.

Step 7 Add File Handling Capabilities

Modify your system so that it will Save the Store to a File, and will
also retrieve a Store from the file. In class Store:

public void fileOut()
{
try
{
FileOutputStream output = new FileOutputStream("data.dat");
ObjectOutputStream objOut = new ObjectOutputStream(output);
objOut.writeObject(this);
objOut.close();
}
// you will need to catch the relevant exception
}
public Store fileIn()
{
Store newStore= null;
try
{
FileInputStream input = new FileInputStream("data.dat");
ObjectInputStream objIn = new ObjectInputStream(input);
newStore = (Store) objIn.readObject();
objIn.close();
}
// you will need to catch the relevant exceptions

return newStore;
}


In your main frame

private void saveToFile()
//pre : true
// if not storeOpen || store empty
// display error message
// else if not fileSaved
// call fileOut in Store
// set fileSaved to true


private void readIn()
// pre : true
// if storeOpen and not fileSaved
// display error message
// else
retrieve Store from file


Step 8 Add File Dialogs

Modify your system so that it allows the user to select the filename to
be written to/read from using a dialog. You might also add a dialog
which when a user quits asks for confirmation if the currrent store
has not been saved.






Step 9 Add image handling capabilities to your system

Modify your system so that it will Store a photo with a Person.
It should also display the photo with the Person on the screen.
Note this will require you to allow a user to select a photo at run time,
using a file dialog. You will need to save the image filename (a
String) rather than the image itself in class Person.

e.g. you will need to add the following methods to Person

public void setPhoto(String fileName)

public String getPhoto()


Assignment Requirements


Basic Pass (40%)

Your system must compile and execute and allow a user to input data
into a form and to clear the data.

Moderate Pass (50%)

Your system must allow a user to save items to a Store

Good Pass (60%)

Your system must allow a user to save a Store to a file
and to retrieve a Store from a file.

Distinctive Work (70%)

Full capabilities including the use of file dialogs and the ability to
save images along with text data.


Hand In:

You should hand in a hard copy of classes Store, Person, the frame class
and any other class you have developed especially for assignment 2.

You will be asked to demonstrate your work on March 20/21.

John Tyrrell February 2006

Im pretty sure no-one from my University and my course (student / professor) comes here so, if they do THIS IS NOT PLAIGARISM! This is STRICTLY a thread for me to spaz out and just say WTF?!?!?!?!?!

Sykoi
03-15-2006, 08:59 PM
HAND-IN DATE: 17th March 2006
(after which maximum obtainable mark is 40%)


Procrastinate much? :haha:

selmo
03-15-2006, 09:41 PM
wow Basic Pass (40%)

Your system must compile and execute and allow a user to input data
into a form and to clear the data.

Moderate Pass (50%)

Your system must allow a user to save items to a Store

Good Pass (60%)

Your system must allow a user to save a Store to a file
and to retrieve a Store from a file.

Distinctive Work (70%)

Full capabilities including the use of file dialogs and the ability to
save images along with text data.

I wish that was the grading policy in my school

Jin
03-16-2006, 07:17 PM
Hey cool, I've done something very similar to this assignment; In class and at the National Institutes of Health (NIH). Wish I could help, but I'm currently on vacation now. Seems pretty straight forward though, good luck!

Kurosaki
03-16-2006, 07:47 PM
Simple...i wish. Ive given up. I got the 40% basic pass covered. But i get loads of compiling errors when im reading in files and outputing files aswell as saving to store. Not to mention ive forgotten how to sort out serialisation. If i had another week i could finish it with few problems but my deadlines in 10 hours.. and ive got to be in work in 6 hours.. so go figure.

I happened to stumble accross this brief definition of Java
"Java is an OO language similar 2 C++ but simplified to eliminate language features that cause common programming errors"

My opionion...... C++ is easier than java. So ugh.... SCREW whoever came up with that definition.

Anyway. Im going to have to make do with 40%.. I got 52% on the last assignment and now ive just got my Java exam to revise for on the 3rd of May. A lovely 3 hour paper with nothing but java source code to read through / edit / correct / interpret. Oh the joys of computing degree's! :(

nobody4422
03-17-2006, 08:21 PM
Just curious is the professor of this class a Doctorate by any chance.

The reason I ask is that the criteria (grading scale, coding exam) seem to be a pain in the ass. One of my programming teachers had similar criteria and was a, very recent, PhD and very much an arrogant pain in the ass. Either that or the course is some sort of grad level class.

Just my opinion but programming teachers that do coding exams deserve to be fired, strung up by there toes, and beaten with whiffle bats by angry midgets. They've clearly lost touch with reality or are just doing it to be total pricks.

moses
03-17-2006, 10:25 PM
nobody... your exactly right!

Kurosaki
03-20-2006, 01:11 AM
Nope, hes just an ass. Im guessing the mark scheme is the way it is due to the fact that if we get 70%+ for all assignments and exams we walk away with the degree title + Honours.