CSE1115 Final 233
CSE1115 Final 233
Page 1 of 4
}
class ShapeTest{
//write code for draw method here
public static void main(String[] args) {
Shape r = new Rectangle(5,6);
Shape s = new Square(3);
draw(r);
draw(s);
}
}
i. Complete the code for the Square class.
ii. Implement the method draw in ShapeTest class so the following output is produced.
Q2: (a) Suppose that you are given a text file named “input.txt” with random texts. Now you have to check how [6+6]
many consonants are in the file and write it to another text file named “output.txt”. For example, if the input file
contains the following text - “Don’t be upset”, you should write “7” in the output file. Both the files should be
in the “src” directory. Now, write a program in Java to perform this task.
(b)
i. What happens if an exception is not caught or handled in Java?
ii. Write the output of the following code.
import java.util.*;
import java.lang.*;
import java.io.*;
Page 2 of 4
[4+4]
Q3: (a) Suppose that you are required to write a Java program for implementing a GUI using any layout. GUI
initially contains a single button named ADD. ADD button dynamically adds a new button to the frame when it
is clicked. Each new button should have a unique label too (such as b1, b2, b3 ...). Note that the buttons or
labels should not overlap. Now do the following task to demonstrate your skill:
Write only the codes to create the user interface and an event-handling method for ADD button.
(b) Assume that the following window is already created.
The names for text field variable are n1, n2, n3, and result. For buttons, the names are max, min, avg, and clr.
Now write the proper event handling method to do the following task,
I. After clicking the maximum button, the result field should show the maximum of n1, n2, and n3.
II. The minimum button will set the minimum value of n1, n2, and n3 in the result field.
III. Average button will find the average of all these inputs.
IV. Clear button will clear all the text fields.
int getZip_code(){
return zip_code;
}
}
Based on the above class, complete the following tasks:
class Test{
public static void main(String[] args){
//Task 1: Create an empty Arraylist of Address type
/*
Task 2: Add the following objects in the Arraylist
"19/A","Dhanmondi","Dhaka",1209
"2/A","Tejgaon","Dhaka",1215
"65","Nirala","Khulna",9100
*/
/*
Task 3: Add the below object at index 1 of the Arraylist
"215","Aamtola","Barishal",8200
*/
/*
Task 4: Set the object at index 2 to
Page 3 of 4
"36","Gulshan","Dhaka",1212
*/
/*
Sort the arraylist in, ascending order of zip codes using a
comparator for comparing objects of Address class [You can also
define the Comparator as a separate class if you want]
*/
/*
Task 5: Delete the object at index 2
*/
}
}
Q5: Asfaq, a first-year programming student, learned how to find the highest number from an array using the Java [6]
program. Excited with his newfound knowledge, he started to wonder if he could concurrently do the same for
multiple arrays. One of his seniors told him to use Thread which facilitates to run multiple tasks concurrently.
Based on the idea, in order to help Asfaq, your task is to
- write a Java program that can find the highest numbers from 4 integer arrays concurrently and next, compute
the maximum of these highest numbers and print the maximum number. Consider the arrays as
{3, 1, -5, 10}, {-2, 6, 7, 8, 0}, {12, -6, 4, 2, 1}, {10, 5, -9, 18, 7}.
Page 4 of 4