You are on page 1of 8

Design a Java interface for ADT Stack. Implement this interface using array.

Display the result for the


1.
following input 3,4,5,9,77 and print the output.

Write a program to perform string operations using Array List. Write functions for the following
2.
a. Append – add at end
b. Insert – add at index 2
c. Search
d. List all string starts with given letter

Write a Java program to implement user defined exception handling. Display the result for the
3.
following input a=1, b=0 perform c=a/b.

4. Develop a Java application to generate Electricity bill. Create a class with the following members:
Consumer no., consumer name, previous month reading, current month reading, type of EB
connection (i.e. domestic or commercial). Compute the bill amount using the following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
First 150 units – Rs. 1 per unit
151-250 units – Rs. 2.50 per unit
251 -500 units – Rs. 4 per unit
> 501 units – Rs. 6 per unit
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
First 150 units – Rs. 2 per unit
151-250 units – Rs. 4.50 per unit
251 -500 units – Rs. 6 per unit
> 501 units – Rs. 7 per unit

5. Develop a java application to implement currency converter (Dollar to INR, EURO to INR, Yen to INR
and vice versa), distance converter (meter to KM, miles to KM and vice versa), time converter (hours
to minutes, seconds and vice versa) using packages.

6. Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate Professor
and Professor from employee class. Add Basic Pay (BP) as the member of all the inherited classes
with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for staff club fund.
Generate pay slips for the employees with their gross and net salary.

7. To Write a Java Program to create an abstract class named sumOfTwo and sum of Three. Perform
addition of two numbers and addition of three numbers.

/abstract class
abstract class Sum{
//abstract methods
public abstract int SumOfTwo(int n1, int n2);
public abstract int SumOfThree(int n1, int n2, int n3);
//Regular method
public void disp(){
System.out.println("Method of class Sum");
}
}

class AbstractDemo extends Sum{


public int SumOfTwo(int num1, int num2){
return num1+num2;
}
public int SumOfThree(int num1, int num2, int num3){
return num1+num2+num3;
}
public static void main(String args[]){
AbstractDemo obj = new AbstractDemo();
System.out.println(obj.SumOfTwo(3, 7));
System.out.println(obj.SumOfThree(4, 3, 19));
obj.disp();
}
}

8. Write a Java program that reads a file name from the user, displays information about whether the
file exists, whether the file is readable, or writable, the type of file and the length of the file in bytes.

9. Create a new class which implements java.lang.Runnable interface and override run() method.
Perform multithreading operation.

class MultiThread implements Runnable {

@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("Thread " + Thread.currentThread().getId()+ " is running");
}
}
}

public class JavaApplication4 {

public static void main(String[] args) {


Thread object = new Thread(new MultiThread());
object.start();
for (int i = 0; i < 10; i++) {
System.out.println("Main Thread id: " + Thread.currentThread().getId());
}
}
}

10. Design a calculator using event-driven programming paradigm of Java with Decimal manipulations.

11. Write a program to Check Prime Number using Interface.

public class Main {

public static void main(String[] args) {

int num = 29;


boolean flag = false;
for (int i = 2; i <= num / 2; ++i) {
// condition for nonprime number
if (num % i == 0) {
flag = true;
break;
}
}

if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}

12. (i) Write a program to display Fibonacci series using recursion

class FibonacciExample1{
public static void main(String args[])
{
 int n1=0,n2=1,n3,i,count=10;
 System.out.print(n1+" "+n2);//printing 0 and 1

 for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed
 {
  n3=n1+n2;
  System.out.print(" "+n3);
  n1=n2;
  n2=n3;
 }

}}

(ii) Write a Java Program to Check a Leap Year using inheritance concept.
public class Main {

public static void main(String[] args) {


int year = 1900;
boolean leap = false;

if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;

if (leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}

13 Write a java program to find the maximum value from the given type of elements using a
generic function.

14 Write a java program that prints numbers from 1 to 10 line by line after every 5 seconds.
public class Threads{
  public static void main(String[] args){
  Thread th = new Thread();
  System.out.println("Numbers are printing line by line after 5 seconds : ");
  try{
  for(int i = 1;i <= 10;i++)
    {
  System.out.println(i);
  th.sleep(5000);
  }
  }
  catch(InterruptedException e){
    System.out.println("Thread interrupted!");
  e.printStackTrace();
  }
  }
}

15 Develop the Internal mark calculation system based on the attendance percentage using Java. Get
the student name, register number, total number of working days in the semester and Number of
days present. Calculate attendance percentage of the students and award attendance mark based
on the following condition.
Attendance percentage >=90 – 5 Marks
Attendance percentage >=80 and < 90 – 4 Marks
Attendance percentage >=75 and < 80 – 3 Marks
Attendance percentage < 75 - 0 Marks

16 Write a Java program for implementing producer consumer problem using Inter-thread
communication.

import java.util.LinkedList;

public class Threadexample {


public static void main(String[] args)
throws InterruptedException
{
final PC pc = new PC();
Thread t1 = new Thread(new Runnable() {
@Override
public void run()
{
try {
pc.produce();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
});

Thread t2 = new Thread(new Runnable() {


@Override
public void run()
{
try {
pc.consume();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
});

t1.start();
t2.start();
t1.join();
t2.join();
}

public static class PC {


LinkedList<Integer> list = new LinkedList<>();
int capacity = 2;
public void produce() throws InterruptedException
{
int value = 0;
while (true) {
synchronized (this)
{
while (list.size() == capacity)
wait();

System.out.println("Producer produced-"
+ value);
list.add(value++);
notify();
Thread.sleep(1000);
}
}
}
public void consume() throws InterruptedException
{
while (true) {
synchronized (this)
{

while (list.size() == 0)
wait();
int val = list.removeFirst();

System.out.println("Consumer consumed-"
+ val);
notify();
Thread.sleep(1000);
}
}
}
}
}
17 Write 2 Java programs one implementing Arithmetic exception and the other implementing
ArrayIndexOutOfBound exception.

18 Write a java program that implements a multi-threaded application that has three threads.
First thread generates a random integer every 10 second and if the value is even, second
thread computes the square of the number and prints. If the value is odd, the third thread will
print the value of cube of the number.

19 Write a java program to insert an element into an array and reverse an array using
packages.

public class ReverseArray {
    public static void main(String[] args) {
        //Initialize array
        int [] arr = new int [] {1, 2, 3, 4, 5};
        System.out.println("Original array: ");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        System.out.println("Array in reverse order: ");
        //Loop through the array in reverse order
        for (int i = arr.length-1; i >= 0; i--) {
            System.out.print(arr[i] + " ");
        }
    }
}

20 Write a program to exhibit simple inheritance, multilevel inheritance and hybrid inheritance
concepts.

1. Develop a Java application to generate Electricity bill. Create a class with the following
members: Consumer no., consumer name, previous month reading, current month reading,
type of EB connection (i.e domestic or commercial). Compute the bill amount using the
following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
First 100 units – Rs. 1 per unit
101-200 units – Rs. 2.50 per unit
201 -500 units – Rs. 4 per unit
> 501 units – Rs. 6 per unit
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
First 100 units – Rs. 2 per unit
101-200 units – Rs. 4.50 per unit
201 -500 units – Rs. 6 per unit
> 501 units – Rs. 7 per unit

2. Develop a java application to implement currency converter (Dollar to EURO, Yen to


Euro, INR to Euro and vice versa), distance converter (meter to KM, inches and feet), time
converter (hours to minutes, hours to seconds, minutes to seconds and vice versa) using
packages.

3. An Mobile bill for the following rates to mobile users


1. Local call - 10 paisa per call
2. ISD call – Rs 1.00 per call
3. Net package cost - 1 GB – Rs 500

4. Write a java program that implements a multi-threaded application that has three
threads. First thread generates a random integer every 5 second and if the value is prime,
second thread computes the square of the number and prints and if the value is odd, the third
thread will print the value of cube of the number.

5. Write a Java Program to create an abstract class named Shape that contains two
integers and an empty method named printArea(). Provide three classes named Rectangle,
Triangle and Circle such that each one of the classes extends the class Shape. Each one of the
classes contains only the method printArea() that prints the area of the given shape.
6. Develop a java program for employee salary calculation using multi level Inheritance

7. To write a Java program that reads a file name from the user, displays information about
whether the file exists, whether the file is readable, or writable, the type of file and the length of
the file in bytes.

8. Write a java program to find the factorial of a number using interface concept.
class FactorialExample{  
 public static void main(String args[]){  
  int i,fact=1;  
  int number=5;//It is the number to calculate factorial    
  for(i=1;i<=number;i++){    
      fact=fact*i;    
  }    
  System.out.println("Factorial of "+number+" is: "+fact);    
 }  
}  

9. To write a java program to find the maximum value from the given type of elements
using a generic function.

10. Write a java program to insert an element into an array and reverse an array using
packages

11. Design a calculator using event-driven programming paradigm of Java with Decimal
manipulations

12. Design a Java interface for ADT Stack. Implement this interface using array. Provide
necessary exception handling in both the implementations.

13. Write a program to perform string operations using ArrayList. Write functions for the
following
a. Append – add at end
b. Insert – add at particular index
c. Search
d. List all string starts with given letter

You might also like