Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CSC3101 – OBJECT-ORIENTED PROGRAMMING SEM 2 2022/2023

Lab 8
(Lab Assignment 4)
File Management

Learning outcome:
Construct and Demonstrate Input/Output Class in Solving Programming Problems (P4, A3)

 For each problem, students need to submit:


i. All .java files including test class.
ii. Input file

Submission Date: Observation\Evaluation during Lab session

** Copy or other forms of cheating is forbidden. The standard penalty for the first offence is to
award 0 to all parties concerned.

LEVEL 1 LEVEL 2 LEVEL 3 LEVEL 4 LEVEL 5


NO CRITERIA
Very Poor Poor Good Very Good Excellent
1 Ability to Unable to Able to identify Able to identify Able to identify Able to identify
analyze identify any only one input or correctly some correctly all input correctly all
problem, input, output output but mistake input, output and and output, input , output and
identify and construct on design design construct correctly provide
requirement solution. and use proper alternative. Able
and elements construct
demonstrate correctly, use
design proper elements
solution and
(input and documentation
output file)
2 Functionality Unable to The program is The program The program works The program
(ability to construct a producing incorrect produces correct and produces the works correctly
run/debug) program results results but does correct results and and meets all
not display them displays them specifications
correctly correctly. It also
meets most other
specifications
3 Readability Unable to The code is poorly The code is The code is fairly The code is
(Comment/ organize the organized and very readable only by easy to read, simple exceptionally well
Description, code, no difficult to read, someone who comments and organized and
indentation/N documentation simple comment in knows what it is header that useful in very easy to
aming code supposed to be understanding the follow,
Convention/cr doing, simple code documentation is
eativity) comments in clearly explains
code with proper what the code is
format accomplishing
4 Schedule The code was The code was The code was The program was The program was
more than 3 within 3 days of the within 2 days of delivered within a delivered on time
days overdue due date the due date day of the due
date/time

Dr. Noridayu Manshor


Lab9(G2)
CSC3101 – OBJECT-ORIENTED PROGRAMMING SEM 2 2022/2023

QUESTION 1

Based on Lab Assignment 1 (Question 1), the info of patient health is stored in a text file known
as patientData.txt. Contents of the file as below (instance data field) are separated by a delimiter “:”.
Write a test program that will implement the HealthRisk class. Your program should have exception
handling to test whether the input file and already created or not. If the input file is not found, throw
the exception, show a message “Input file not found!!” and exit from the program. Write the output
file as similar to the output that you have produced in this question or any creativity output.

patientData.txt

Ramli Ahmad:M:80:
Ina Ghani:F:143:
John Elwis:M: 70:
Mary Elton: F: 90:
Ridzuan Ismail: M:100:
Herri Johnny:M:79:

QUESTION 2

Diberi satu gambar rajah UML bagi kelas yang dikenali sebagai Document. Kelas ini
mempunyai medan data infile berjenis java.io.File. Ia juga mempunyai pembina dan kaedah.
Kaedah countCharacters() mengira bilangan aksara dalam infile tidak termasuk aksara
whitespaces . Kaedah countWords() membilang perkataan dalam infile. Kaedah countLines()
membilang baris dalam infile. Perkataan dipisahkan oleh aksara whitespaces.
Document
-infile: java.io.File
+Document()
+Document(infile: java.io.File)
+countCharacters(): int
+countWords(): int
+countLines(): int

Anda dikehendaki:
a) Implemen kelas Document.
b) Implemen program Test yang akan mewujudkan objek File bagi fail input bernama
upm.txt yang terdapat di direktori C:\MyDocument\. Program ini akan mewujudkan
objek Document untuk objek File yang telah dibina. Program ini akan mencetak
bilangan aksara, bilangan perkataan, dan bilangan baris yang terdapat dalam fail
upm.txt ke dalam satu fail output dipanggil output.txt.
Program anda perlulah mempunyai pengendalian pengecualian untuk menentukan
kewujudan fail input.

Dr. Noridayu Manshor


Lab9(G2)
CSC3101 – OBJECT-ORIENTED PROGRAMMING SEM 2 2022/2023

Given is a UML diagram for a class known as Document. The class contains a data field
infile of type java.io.File. It also contains constructors and methods. Method countCharacters()
calculates the number of characters excluding whitespace characters in infile. Method
countWords() counts the words in infile. Method countLines() counts the lines in infile. Words
are separated by whitespace characters.

Document

-infile: java.io.File

+Document()
+Document(infile: java.io.File)
+countCharacters(): int
+countWords(): int
+countLines(): int

You are required:


a) Implement the class Document.
b) Implement a Test program that will create File object for an input file named upm.txt
contained in directory C:\MyDocument\. This program will create Document object for
the created File object. This program will print out number of characters, number of
words, and number of lines in upm.txt file into an output file called output.txt.
Your program should have exception handling to determine the existence of the input file.

Dr. Noridayu Manshor


Lab9(G2)

You might also like