introductory java university of wollonogng 2003 - assignment 1

4
CSCI213 Autumn Session, 2003 Assignment 1: Learning to use the JDK Due: 21 March 2003 (midnight) You should attend the Java lecture of Weeks 1 & 2 and complete "Laboratory Exercise of Week 2" before starting this assignment. Aims Objectives Specifications Task : Procedural style coding using basic Java classes Submission Marking Plagiarism Aims This assignment aims to establish a basic familiarity with the JDK development system and its associated on-line class documentation (API documentation). It also introduces the use of some simple Java library (package) classes including i/o reader/printer classes, and strings. You will soon learn that the biggest difference from C++ is that you write very little of your Java programs. Instead, you construct them from library classes. Objectives The assignment involves the following task: Code a simple procedural style program (with one class) that handles bank transactions of three users Alice, Bob, and Chris. The program will use some classes already given in the Java library, e.g., Hashtable, StringTokenizer, BufferedReader, etc. On completion of this assignment you should be able to: code and run Java programs using the development environment ("textpad" or equivalent editor, "javac" compiler, and "java" run-time interpreter). make effective use of the on-line documentation system (/packages/java/jdk/1.4.0_01/docs/api/index.html) that supports the development environment. alternatively you could use Borland JBuilder 9 Personal Edition (www.borland.com) (That link to the documentation will only work in the labs; here is an alternative link to documentation at Sun 's site.) code programs using Java in a hybrid style ("procedural" code using instances of simple classes). use collection and associated iterator classes from the java.util package. use simple text oriented i/o facilities. manipulate string data. Specifications: Code “a bank transaction handler” that prints out user transaction information in terms of given inputs. Well, it is not a real banking system. All transactions for Alice, Bob, and Chris are hard-coded as a String array in your program: private static final String[] users = { "Alice,20020115,100,20020314,-2,20020520,50,20030220,-34,20030724,-10,20030801,5", "Bob,20020213,98,20020422,-4,20020611,60,20030310,-43,20030807,-9,20030904,6", "Chris,20020317,10,20020521,30,20020601,5,20030320,-10,20030907,8,20031004,10"}; The first value of each string is the user name. The rest are transactions arranged as YearMonthDate,Dollars,YearMonthDate,Dollars,... Notice that no white spaces in each string. users[] is an array consisting of three strings elements. You manipulate the strings to obtain a proper output. A skeleton code has been provided. Your coding should be based on the skeleton code; however, if you want to apply your way of coding, you do not have to follow the skeleton (you must use the string provided above) . The program comprises three tasks. Task 1. Break the transaction string for each user into tokens using StringTokenizer and upload the tokens into a Hashtable in a form: For Alice Key Value 20020115 100 UOW:CSCI213:Session 1:2001:Assignment 1. 1/22/2015 file:///H:/Uni/plw19/213/Ass1/Specification/a1.html 1 / 4

Upload: eword

Post on 17-Jul-2016

1 views

Category:

Documents


0 download

DESCRIPTION

Introductory Java University of Wollonogng 2003 - Assignment 1

TRANSCRIPT

Page 1: Introductory Java University of Wollonogng 2003 - Assignment 1

CSCI213 Autumn Session, 2003

Assignment 1: Learning to use the JDK

Due: 21 March 2003 (midnight)

You should attend the Java lecture of Weeks 1 & 2 and complete "Laboratory Exercise of Week 2" before starting this assignment.

AimsObjectivesSpecifications

Task : Procedural style coding using basic Java classesSubmissionMarkingPlagiarism

Aims

This assignment aims to establish a basic familiarity with the JDK development system and its associated on-line class documentation (APIdocumentation). It also introduces the use of some simple Java library (package) classes including i/o reader/printer classes, and strings.

You will soon learn that the biggest difference from C++ is that you write very little of your Java programs. Instead, you construct them from libraryclasses.

Objectives

The assignment involves the following task:

Code a simple procedural style program (with one class) that handles bank transactions of three users Alice, Bob, and Chris. The program will usesome classes already given in the Java library, e.g., Hashtable, StringTokenizer, BufferedReader, etc.

On completion of this assignment you should be able to:

code and run Java programs using the development environment ("textpad" or equivalent editor, "javac" compiler, and "java" run-time interpreter).make effective use of the on-line documentation system (/packages/java/jdk/1.4.0_01/docs/api/index.html) that supports the developmentenvironment.alternatively you could use Borland JBuilder 9 Personal Edition (www.borland.com)

(That link to the documentation will only work in the labs; here is an alternative link to documentation at Sun's site.)

code programs using Java in a hybrid style ("procedural" code using instances of simple classes).use collection and associated iterator classes from the java.util package.use simple text oriented i/o facilities.manipulate string data.

Specifications:

Code “a bank transaction handler” that prints out user transaction information in terms of given inputs. Well, it is not a real banking system. Alltransactions for Alice, Bob, and Chris are hard-coded as a String array in your program:

private static final String[] users = { "Alice,20020115,100,20020314,-2,20020520,50,20030220,-34,20030724,-10,20030801,5",

"Bob,20020213,98,20020422,-4,20020611,60,20030310,-43,20030807,-9,20030904,6", "Chris,20020317,10,20020521,30,20020601,5,20030320,-10,20030907,8,20031004,10"};

The first value of each string is the user name. The rest are transactions arranged as

YearMonthDate,Dollars,YearMonthDate,Dollars,...

Notice that no white spaces in each string. users[] is an array consisting of three strings elements.

You manipulate the strings to obtain a proper output. A skeleton code has been provided. Your coding should be based on the skeleton code;however, if you want to apply your way of coding, you do not have to follow the skeleton (you must use the string provided above) . The programcomprises three tasks.

Task 1. Break the transaction string for each user into tokens using StringTokenizer and upload the tokens into a Hashtable in a form:

For Alice

Key Value20020115 100

UOW:CSCI213:Session 1:2001:Assignment 1. 1/22/2015

file:///H:/Uni/plw19/213/Ass1/Specification/a1.html 1 / 4

Page 2: Introductory Java University of Wollonogng 2003 - Assignment 1

20020314 -220020520 5020030220 -3420030724 -1020030801 5

Your program takes Alice and YearMonthDate as input and outputs the daily transaction value from the hashtable. For example, taking 2002 03 14as input, your program outputs -2. A sample run of my program is as follows:

---<<Java Bank>>---1. Daily transaction info2. Yearly transaction info3. Period transaction infox. ExitYour choice? 1 View Daily Transactions --Users--BobChrisAliceName: Alice Input DateYear(YYYY): 2002Month(MM): 03Day(DD): 14 Transaction = -2 ---<<Java Bank>>---1. Daily transaction info2. Yearly transaction info3. Period transaction infox. ExitYour choice?

The bold font indicates user inputs. We have selected “1” for Task 1. “2” and “3” are used for Task 2 and Task 3, respectively. You do not have tofollow the format exactly, but it should not be too much different.

Obviously, you have to use Java I/O classes to handle “read/write”. There are a number of ways to carry out I/O from a file, but in this assignmentyou use only the BufferedReader class to read data from the command line. The lecture in Week 2 will cover it. You will also practice using this classin your labs.

You have only one class named Bank.java. This class consists of a few methods. Each of methods handles a part of the task.

Your program is to utilize classes from the java.io packages and to utilize the following classes from the Java libraries:

· String: words are represented as instances of java.lang.String.· StringTokenizer: a string can be broken down into elements using a StringTokenizer (java.util); the delimiter characters are chosen by the

programmer.· Hashtable from java.util.· BufferedReader (also InputStreamReader): input utilizes instances of the BufferedReader class (connected to files via FileReader objects

or to keyboard via an InputStreamReader and the System.in object); input is line oriented using the readLine() method ofBufferedReader. You use it only for input from the console.

Task 2 Get a yearly transaction summary (balance) for each user. Your program takes a username and a year as input and outputs the sum of ayearly transaction. You handle this task using StringTokenizer and Hashtable. It should be straightforward if you attend the lectures. A sample run forTask 2 is as follows. ---<<Java Bank>>---1. Daily transaction info2. Yearly transaction info3. Period transaction infox. ExitYour choice? 2 View Yearly Transactions --Users--BobChrisAliceName: Bob

UOW:CSCI213:Session 1:2001:Assignment 1. 1/22/2015

file:///H:/Uni/plw19/213/Ass1/Specification/a1.html 2 / 4

Page 3: Introductory Java University of Wollonogng 2003 - Assignment 1

Input YearYear(YYYY): 2002 Year Transaction = 154 ---<<Java Bank>>---1. Daily transaction info2. Yearly transaction info3. Period transaction infox. ExitYour choice? Task 3. Get the sum of transactions between two dates. Your program takes as input two dates for a user’s transactions and outputs the sum of thecorresponding transactions. Again, you handle this task using StringTokenizer and Hashtable. A simple run for Task 3 is as follows. ---<<Java Bank>>---1. Daily transaction info2. Yearly transaction info3. Period transaction infox. ExitYour choice? 3 View Customer Transactions --Users--BobChrisAliceName: Chris Input Start DateYear(YYYY): 2002Month(MM): 05Day(DD): 21Input End DateYear(YYYY): 2003Month(MM): 03Day(DD): 20 Period Transaction(20020521 to 20030320) = 25 ---<<Java Bank>>---1. Daily transaction info2. Yearly transaction info3. Period transaction infox. ExitYour choice? Error handling. Your program should be able to handle incorrect inputs. When an invalid input is given, it returns a warning message and asks theuser to re-enter the data. Only exception handling is for BufferedReader. The examples for BufferedReader are given in labs and the lectures. You should take care to use meaningful names for all functions (methods), variables and constants and indent your code to maximize readability. A"procedural" style Java program should be organized like Pascal code - your "program" class starts with definitions of constants, then declarations ofquasi-global variables, then definitions of auxiliary functions and finally the main() function. Your program must be rewritten according to the Java Code Conventions.

Submission

The due date for submission is 21 March 2003.

For CSCI213, assignments are submitted electronically via the "submit" system. For this assignment you submit your two programs via the command:

submit –u user_name -c csci213 -a 1 Bank.java

You must use the exact file names (notice that Unix is case-sensitive). This assignment does not require additional documentation files. Comments incode files should be concise. A header should give your information (including name, student ID, and Unix login name) and briefly summarize the contentsof the file - identifying purpose of program, listing classes etc. Classes may have brief header comments if these are considered necessary. Individualfunctions should only require comment if they are complicated or result in non-obvious side effects etc.

Marking

UOW:CSCI213:Session 1:2001:Assignment 1. 1/22/2015

file:///H:/Uni/plw19/213/Ass1/Specification/a1.html 3 / 4

Page 4: Introductory Java University of Wollonogng 2003 - Assignment 1

This information is primarily for the tutors who will be marking the assignment; but some of you might be interested.

Mark to 0.5 divisions, no 0.1 fractional marks!

Three parts to marks (2, 8):

1. General coding style and quality - start by allocation of 2 marks and deduct for any errors. The deduction for each error is 0.5 (themaximum 2 marks). Common problems include: poor choice of identifiers, bad indentation, failure to break code into small welldefined functions, failure to use class (static) and instance members correctly, failure to define constants properly, errors involvingredundant creation of objects, failure to use specified classes from Java libraries; failure to check for input errors; uncheckedarguments that could lead to runtime errors; failure to comply with functional specifications of programs.

2. The code:§ Task 1: 4 marks for correct implementation. The deduction for each error is 0.5.§ Task 2: 2 marks for correct implementation. The deduction for each error is 0.5.§ Taks 3: 2 marks for correct implementation. The deduction for each error is 0.5.

Your assignment will be printed out. You will receive an email from your tutor providing you with the marking result.

PlagiarismA plagiarised assignment will be given a negative mark (and penalised according to the university rules). Plagiarism detection software could be usedin this session.

UOW:CSCI213:Session 1:2001:Assignment 1. 1/22/2015

file:///H:/Uni/plw19/213/Ass1/Specification/a1.html 4 / 4