0% found this document useful (0 votes)
155 views2 pages

Digital Assignment 2 Due Date 18-10-21

This document provides instructions for four Java programming assignments: 1. Reading and writing text files, getting file names from the user, and handling exceptions. 2. Designing custom exception classes for specific error cases. 3. Simulating event registration for 1000 students using multiple threads to count registrations and displaying unregistered students. 4. Submitting a report with program code and output in PDF or Word format to VTOP by September 18th for evaluation. Plagiarism will result in reduced marks.

Uploaded by

Majety S Lskshmi
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)
155 views2 pages

Digital Assignment 2 Due Date 18-10-21

This document provides instructions for four Java programming assignments: 1. Reading and writing text files, getting file names from the user, and handling exceptions. 2. Designing custom exception classes for specific error cases. 3. Simulating event registration for 1000 students using multiple threads to count registrations and displaying unregistered students. 4. Submitting a report with program code and output in PDF or Word format to VTOP by September 18th for evaluation. Plagiarism will result in reduced marks.

Uploaded by

Majety S Lskshmi
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

DIGITAL ASSIGNMENT -2

FALL 2021-2022

SCHOOL OF COMPUTER SCIENCE AND ENGINEERING

CSE1007 - Java Programming

ETH (SLOT-A1+TA1)

Q1. Reading and writing text files

public class ReadWriteFileTest1


{
public static void main(String[] args)
{
// Specify a filename directly
File inFile = new File(“text1.txt" );
Scanner in = new Scanner(inFile );
PrintWriter out = new PrintWriter(“text1.out.txt" );
int lineNumber = 1;
// Read the input and write the output
while (in.hasNextLine())
{
String line = in.nextLine();
out.println("/* " + lineNumber + " */ " + line);
lineNumber++;
}
in.close();
out.close();
System.out.println(“Program terminated.”);
}
}
(a) ReadWriteFileTest1: Does the program execute? If not, what is the error
displayed?
(b) ReadWriteFileTest2: Solve the error in the above question. What happens
when the input file is not found? Is it checked or unchecked exception that is
thrown? Why?
(c) ReadWriteFileTest3: Update the program to get input from system console
from the user for the input filename and the output filename.
(d) ReadWriteFileTest4: Use try/catch statements to handle exceptions and
enable user to re-specify file name. Use try/finally statements to close resources.
Also, checked for unchecked exceptions. Given e is an exception object, what
does e.printStackTrace() do?
(e) ReadWriteFileTest5: Update the program to get the input and output
filenames using JFile-Chooser. Ensure that all the checked exceptions are
handled and make sure that the unchecked exceptions do not occur. Also, enable
user to re-specify a valid file name in case "Cancel" is clicked.

Q2. Designing your own exception classes


• Sometimes, the names of the available exception classes may not make
perfect sense for the specific exception that you plan to handle. For e.g.,
if the withdrawal amount is greater than balance, the withdraw operation
should not be allowed and instead, InsufficientFundsException mustbe
thrown. This exception class should extend the RuntimeException as it is
an unchecked exception. You may also name the exception class as
InvalidAmountException.
• Need to identify an appropriate name for the exception class.
• Need to analyze whether this is a checked or an unchecked exception and
should inherit from superclass accordingly.

Q3. Multithreading

Five events E1, E2, E3, E4 and E5 are going to be organized for Gravitas in VIT,
registration is open for all B.Tech students. With the total strength of 1000
students, simulate the registration for each event by generating 1000 random
numbers in the range of 1 – 5. (1 for event E1, 2 for E2… 5 for E5) and store the
values in an array. Create six threads to equally share the task of counting the
number of registration details for all the events. Use synchronized method or
synchronized block to update the count variables. The main thread should receive
the final registration count for all events and display the list of students who have
not registered in any event.

Submission:
i) You must submit:
(a) A short report (in PDF or word), which should be uploaded to the VTOP, as a
single file. For programs, provide the source code and output in your report.
Similarity of your report, will be checked. If the answers are unique, then the
maximum marks will be given others will get less marks.
(b) Any submission after the deadline (18-09-2021) will not be considered for
evaluation of marks.

You might also like