OOP CS2104 Assignment-2
OOP CS2104 Assignment-2
Create a subclass of this class Savings Account and add the following details:
Data members: (a) rateOf Interest
Methods:
(a) calculateAmount()
(b) display() to display rate of interest with new balance and full account holder details
Create another subclass of the Accounts class, i.e. Current Account with the following: ith the follow Data members:
(a) overdraftlimit
Method: (a) display() to show overdraft limit along with the full account holder details Create objects of these two
classes and call their methods. Use appropriate constructors.
(a) Push and pop elements from the stack. (b) Check whether the stack is empty or not.
Implement the stack with the help of arrays and if the size of the array becomes too small to hold the elements,
create a new one. Test this interface by inheriting it in its subclass StackTest.java.
4. Design an interface named Queue with the following methods:
(a) To add and remove elements from the queue.
(b) Check whether queue is empty or not Implement the queue with the help of arrays and if the size of the array
becomes too small to hold the elements, create a new one. Test this interface by inheriting it in its subclass
QueueTest.java
5. You are given an incomplete class name ‘submarine’ having three attributes named : depth:int ,loc_x:int
and loc_y:int. The class have two inner class controlPanel and fireControl. You are required to complete the class
as per the commented specification.
Here edges are undirected and numbers over edge represent the cost of wire. When two edges are connected to
the same pair of cities and cost of wire is different than it is called parallel edge. If start and end city of an edge
are same then it is called loop. Consider the following declaration.
class Edge {
private String start; // start node of an edge
private String end; // End node of an edge
private int cost; // cost of wire
Edge(String s, String e, int w)
{
start =s;
end =e;
cost =w;
} } // end of edge class
class Graph
{
private ArrayList <Edge> list_edges; // list of edges of a graph
Graph(ArrayList <Edge> n) // constructor
{
list_edges =n;
}
public void removeLoop()
{
(a.)/* write the java code to remove loops from the list_edges:ArrayList. */
}
public Edge findParallelEdge(Edge n)
{
(b.) /* This function finds a parallel edge of n:Edge in list_edges:ArrayList. If parallel edge exists it returns parallel
edge otherwise null. Write the java code*/
}
public void removeParallel()
{
(c.)/* This method traverses list_edges:ArrayList and finds a parallel edge. if an Edge’s parallel edge is found and
Edge’s cost is higher than parallel edge it removes Edge. Write the java code */
}
public void print()
{
(d.) // write the java code to print edges of list_edges:ArrayList
}}
7. Write a Java Program of performing reading and writing operation using FileReader and FileWriter class.
8. Write difference between comparator and comparable interface. Explain it by sample codes.
9. What do you understand about package? Explain different methods of creating packages
10. What do you understand by Exceptions? Explain Types of exception i.e. Checked & Unchecked
11. WAP to explain user defined Exception and create a user defined exception and throw it in another class?
12. Differentiate among Exception keywords: try, catch, finally, throw, throws.
13. Explain thread life cycle in Java. What are the options of creating threads in java?
14. Write a java program to create the thread to print the number in reverse order by extending the Thread class.
15. To write a java program for generating two threads, one for generating even number and one for generating odd
number.