Sale!

WIX1002 Lab 7 File Input and Output solution

$30.00 $25.50

Category:

Description

5/5 - (3 votes)

Fundamentals of Programming
1. Write a program that store the table below in a binary file name course.dat. Then, ask
the users to enter a course code. The program will display the course name from
course.dat.
Course Code Course Name
WXES1116 Programming I
WXES1115 Data Structure
WXES1110 Operating System
WXES1112 Computing Mathematics I
2. The code below is used to read the contents of a Web page. Write the contents of the
Web page into a text file name index.htm.
import java.util.Scanner;
import java.net.URL;
import java.io.InputStream;
import java.net.URLConnection;

try {
URL u = new URL(“http://www.fsktm.um.edu.my”);
URLConnection cnn = u.openConnection();
InputStream stream = cnn.getInputStream();
Scanner in = new Scanner(stream);

}
catch (IOException e) {
System.out.println(“IO Error:” + e.getMessage());
}
3. Write the statements that replace each line of a text file with its reverse and save it to
a new text file name reverse.txt.
4. Write a program that display the number of characters, words and lines in a text file.
Assume that each word is separated by one space character.
5. Write a program that read data from a binary file person.dat. (Please download the
binary file from the Web site.) Then, display the name, age and gender (M – Male, F
– Female) in ascending order sort by name. The structure of the binary file is as
below:


2

6. Write programs that merge data from two text files namely product.txt and
order.txt. (Please download the text file from the Web site.) The product.txt
contains the ProductID, ProductName, ProductPrice separated by comma. The
order.txt contains the OrderID, ProductID, OrderQuantiy separated by comma. You
program will display the ProductID, ProductName, OrderQuantity, PricePerUnit and
TotalPrice for each order. (You can use the String.split(), Integer.parseInt(String) and
Double.parseDouble(String))