CSC186 Lab Assignment 5 – File Input and Output solution

$25.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

3.1 Given the input file of FTMSK.txt that includes the following attributes such as
MatricNumber, StudentName, Program, Part and Gender (either M (Male) or F
(Female)).

The following input text file includes all records of FTMSK students.
Write a
program that reads each record from FTMSK.txt and filter the records into two
output text files called CS110Male.txt and CS111Male.txt. The first output
text file will store all male students from CS110, while the second output file will
store all male students from CS111. Calculate and display the total records for
each output text file.

Examples of output text file for CS110Male.txt.

Examples of output text file for CS111Male.txt.
Use exception-handling operations to deal with the input-output errors.

3.2 H&M Car Motors Bhd is in the process of updating the record of cars
information. You are given a file named car.txt that contains the
following details:
• car type
• car plate number
• car price
A sample of car.txt file.

Write a complete program to perform the following:
a) Design a complete class named Vehicle consist of the following method:
i) Constructor
ii) Setter/mutator
iii) Getter/Assessor

b) Write Java Application program to perform the following tasks:
i) Create an array of object for Vehicle named arrCar.
ii) Read all records from the file named car.txt and store
each object onto array of object named arrCar

iii) Write thefollowing information into afile namedselangor.
txt:
a. Information for all cars that are manufactured in Selangor,
where the plate numbers start with the letter ‘B’.
b. Calculate the total price for all cars that are manufactured in
Selangor.

iv) Write the following information into a file named
terengganu. txt:
a. Store the information for all cars that are manufactured
in Terengganu, where the plate numbers start with the
letter ‘T’.

b. Calculate the total price for all cars that are manufactured in
Terengganu.
v) Use exception to handle possible file errors and wrong data type
errors.
Sample of selangor.txt
Sample of terengganu.txt

3.3 You are given a text file named deliveroo. txt, which contains a list of food
delivery orders for a food delivery company. The data consists of the delivery date
(DDIMMIYYYY), day, start time, end time,, restaurant name, total price, delivery
distance in kilometres, and price multiplier.
Figure 1: deliveroo. txt

Write a complete Java program using File 1/0 operation to perform the following
tasks:
a) Read all records from the text file named deliveroo. txt in Figure
1.
b) Generate an output file named earnings.txt which contains the
profit and summary of the orders. The profit for each delivery is calculated
using the following formula:
profit= (price multiplier x final price) – final price

The final price that the buyer must pay is the sum of the order’s total price
multiplied by the price multiplier. The price multiplier was set based on the type
of customers and the coupon they used.
A sample of earnings. txt is shown inFigure 2.

Figure 2: earnings. txt
c) Count the number of deliveries with start time at 9 PM or later and display it
on the console.
d) Close all file streams in use.
e) Apply exception handling mechanism in the program.

3.4 Ahmad Jimat Supermarket is a convenient store that sells varieties of goods
to its customers. All sales are recorded in text files. The text files are named
according to the date of the sales. The stored data contains item name,
quantity and unit price. The file is named “20180221.txt” records all the
sales on 21
st February 2018 as follows:
A sample of 20180221.txt

Write a complete Java program using file I/O to perform the following
tasks:
a) Design a complete class named Supermarket consist of the following
method:
i) Constructor
ii) Setter/mutator
iii) Getter/Assessor

b) Write Java Application program to perform the following tasks:
i) Create an array of object for named arrStore.
ii) Read all records from the file named 20180221.txt and
store each object onto array of object named
arrStore
iii) Write the following into a file named reportSale.txt:
• Calculate and display the total sale on 21
st February 2018 by

summing up the subtotal of all the records in the text file for
each record. For example, the subtotal of the first record is
shown below:
Sub total = 5 * 1.20 = 6.00
• The expected output of the program is shown below:

A sample of reportSale.txt
iv) Use exception handling operations to deal with possible file
input/output error.