0% found this document useful (0 votes)
21 views

OOP CS2104 Assignment-2

The document contains 15 questions related to OOP concepts in Java like classes, inheritance, interfaces, exceptions, files, threads etc. The questions cover topics like class creation, inheritance, abstract classes, interfaces, exceptions, file handling, threads and thread life cycle.

Uploaded by

armaan04062004
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)
21 views

OOP CS2104 Assignment-2

The document contains 15 questions related to OOP concepts in Java like classes, inheritance, interfaces, exceptions, files, threads etc. The questions cover topics like class creation, inheritance, abstract classes, interfaces, exceptions, file handling, threads and thread life cycle.

Uploaded by

armaan04062004
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/ 3

Faculty of Engineering

Department of Computer Science and Engineering


B.Tech. (Computer Science and Engineering)
Object Oriented Programming| CS 2104 | 4 Credits | 3 1 0 3
Session: Jul 23 – Nov 23| Class: III Semester

OOP Assignment-2 (Lecture 26-48)

Qus. Problem statements


1. Define a class MotorVehicle as described below:
Data members:
(a) modelName
(b) modelNumber
(c) modelPrice
Methods: (a) display() method to display the name, price, and model number.
Define another derived class named Car that inherits the class Motor Vehicle and has the following: Data members:
(a) discountRate
Methods: (a) display() method to display the Car name, Car model number, Car price, and the discount rate.
(b) discount () method to compute the discount Create the classes MotorVehicle and Car with suitable constructors
and test it.
2. Create an abstract class Accounts with the following details:
Data members: (a) balance
(b) account Number
(c) accountHoldersName (d) address
Methods:
(a) withdrawl() - abstract
(b) deposit() - abstract
(c) display() to show the balance of the account number

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.

3. Design an interface named Stack with the following methods:

(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.

public class submarine


{
int depth, int loc_x,int loc_y ;
public class controlPanel
{
//(a)define setter getter method for location and depth
}
public class fireControl
{
int artilleryAmount;
//(b)define a constructor to initialize artillery amount
public boolean isArtilleryavailable()
{
//(c) this method will return true if artillery is present otherwise return false
}
void fireOnTarget(int x,int y)
{
//(d) this method will search whether enemy target is available at x,y if yes it will set status inactive
}
}
public class enemyTarget
{
static int
target[][]={{10,20,1},{15,23,1},{22,78,1},{8,67,1},{56,11,1},{34,77,1},{33,80,1},{32,32,1},{56,45,1},{54,90,1}}
//first two no denote x and y coordinate and third no denote status 1 means active 0 means inactive
}
public class driver
{
public static void main(String args[])
{
//(e) create object of controlPanel class and fireControl
//(f) using fireControl object call fireOntarget until all enemy target is destroyed. Assume random no.
//between 0 -100 is passed as parameter
}
}
6. XYZ company has offices in different cities and wants to lay down the wire, to connect them with each other. The
wire cost is different to connect different pairs of cities. The notation is represented in the following figure.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy