0% found this document useful (0 votes)
10 views

Assignment 02

Uploaded by

diwiyem997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment 02

Uploaded by

diwiyem997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 2 CSCE 156 Fall 2022

CSCE 156 Assignment 2 –


Classes and Objects

Notes:
• There are Two programming questions in this homework.
• Follow instructions carefully, failure to do so may result in points being deducted. You may
discuss problems with your classmates, but all work must be your own. The CSE academic
integrity policy is in effect (see http://cse.unl.edu/ugrad/resources/academic_integrity.php).

Program 1: Octal Array

Implement the following class and its methods: An OctalArray represents arbitrarily long sequences of
integer variables (each digit ranges from 0-7). The private data representation is an array of integer
variables. For instance, the representation of the OctalArray “65412” would be an array of length 5
storing 6, 5, 4, 1, 2 in array indices 4, 3, 2, 1, and 0 respectively. The OctalArray class has the following
functionality:
i. A one-parameter constructor that contains an Integer. Throw an IllegalArgumentException if
there are illegal digits (i.e., greater than 7).
ii. An override toString method.
iii. A get and set method to access or change a variable at a particular index.
iv. A size method that returns the number of octal variables in the OctalArray.
v. Your program should be able to handle the following boundary cases:
o Throw an IllegalArgumentException if the integer given is invalid (ex. 548 should print an
error message such as “Input Integer can only contain digits from 0-7).
o If an invalid index (i.e. beyond the length of the array) is given in the set() or get()
method, an appropriate message should be provided
vi. Method to covert the OctalArray to get the equivalent decimal number.

Place your code in a Java class called OctalArray (the source file will be OctalArray.java) in part1 package
and have it accepted an integer value to be read in from command line arguments representing the
octal number. That is, your program should be executable from the command line by calling:

~> java OctalArrayDemo 421 which will output an appropriate message to the standard output.
Assignment 2 CSCE 156 Fall 2022

Program 2: Parsing Persons Data File

In this exercise, will focus on the design and implementation of several Java classes to model the various
entities captured from a flat file. You need to write a parser to process a “flat" data file containing data
about persons and build instances of each object. This file is in a non-standard semi-colon and comma
separated value format.
It contains data about persons in a system where each line represents full data about one person. The
file name is Persons.csv. The format of this file is as follows: the first line will contain a single integer
indicating the total number of records. Each subsequent line contains comma delimited data fields
following the pattern:

personCode, lastName, firstName, address, emailAddress (es)

Details:

• Person Code – a unique alpha-numeric


• Name - the person’s name in lastName, firstName format
• Address - the physical address of the person. The format is as follows: STREET, CITY, STATE, ZIP,
COUNTRY
• Email Address(es) - an (optional) list of email addresses; if there are multiple email addresses,
they will be delimited by a comma.

Place your code in a Java class(es) in part2 package. You should run your code from class
PersonsDataConverter class where you will read a file (‘data/Persons.dat’) and create an object of for
each record in the file. Next, you need to sort the persons based on their last name then first name
(alphabetical order). Lastly, print the persons list containing each person last name, first name and email
addresses.

Bonus (Extra 20 points): Objects represent and model real-world entities. The state of an object consists
of the pieces of data that conceptually define what that object is. Often it is necessary to be able to
transmit objects between different systems, which may use completely different languages and
technologies. The transfer of such data is known as Electronic Data Interchange (EDI) and is achieved by
translating objects into a platform-independent data format such as XML (Extensible Markup Language)
or JSON (JavaScript Object Notation) representations. Once transferred, the data on the other end can
then be translated into an object in the second system. Different languages and frameworks have their
own terminology for this process (marshaling/unmarshaling, serialization/deserialization, etc.). Write
your objects into JSON file.

You might also like