JAVA Lab Assignment - 2017
01-08-2017    3204 times
JAVA Lab Assignment

WBUT or West Bengal university of technology is conducted MCA along with various technical courses. According to their MCA syllabus, students learn JAVA in the 5th semester. We are trying to give some guidance to the WBUT students by previous year solved papers. Here we discuss the Java assignment 2017.

1 ) A set of two linear equations with two unknowns x1 and x2 is given below:
ax1 + bx2 = m
cx1 + dx2 = n The set has a unique solution:

x1 = (md – bn ) / ( ad – bc )
x2 = ( na – mc ) / (ad – bc) provided the denominator ad- bc ≠ 0.
Write a program that will read the values of constants a, b, c, d ,m and n and computes the values of x1 & x2.An appropriate message should be printed when (ad-bc)=0.

2)For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency is given by:

Frequency = √ [( 1 / LC ) – ( R2/4C2 )]

It is desired to study the variations of the frequency with C (capacitance). Write a program to calculate the frequency of difference values of C starting 0.01 to 0.1 in steps of 0.01.

3) Given are two one-dimensional arrays A & B, which are sorted in ascending order. Write a program to merge them into single sorted array C that contains every item from arrays. A & B, in ascending.

4) The annual examination results of 100 students are tabulated as follows:

Roll No. Subject 1 Subject 2 Subject 3
...................... ..... ..... .....
...................... ...... ...... ......

Tutorial at home
Tutorial at home

Write a program to read the data and determine the following:

  • Total marks obtain by each student
  • The highest marks in each subject and the roll no of the student who secured it
  • The student who obtained the highest total marks

 

5) Write a program that takes a String from the user on the command-line and print it in reverse.

 Ans. Solution

6) Write a program to accept a string from the user and find out the following statistics:

  • Count of uppercase character
  • Count of lowercase character
  • Count of digits
  • Count of spaces

 Ans. Solution

Tutorial at home

7) Create a class called Time, which has three private instance variables – hour, min and sec. It contains a method called add ( ) which takes one Time object as parameter and print the added value of the calling Time object and passes Time object. In the main method, declare two Time objects and assign values using constructor and call the add()

 Ans. Solution

8) Create a class Stack that declares a stack and the methods to perform push(), pop() and checkEmpty() operations on the stack. Create two stacks and write a menu-driven program to perform operations on the two stacks. Whenever the number of elements in the two stacks becomes equal, a message should automatically be generated displaying the number of elements in each

 Ans. Solution

Tutorial at home

9) Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the super class of the hierarchy. The instance variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. Write a program that instantiates objects of your classes and outputs each object's area (except Quadrilateral).

 Ans. Solution

10) Write a program to create a class named Vehicle having protected instance variables regnNumber, speed, color, ownerName and a method showData ( ) to show “This is a vehicle class”. Inherit the Vehicle class into subclasses named Bus and Car having individual private instance variables routeNumber in Bus and manufacturerName in Car and both of them having showData ( ) method showing all details of Bus and Car respectively with content of the super class’s showData ( ) method.

11) Create an interface Department containing attributes deptName and deptHead. It also has abstract methods for printing the attributes. Create a class hostel containing hostelName, hostelLocation and numberOfRooms. The class contains method printing the attributes. Then write Student class extending the Hostel class and implementing the Department interface. This class contains attributes studentName, regdNo, electiveSubject and avgMarks. Write suitable printData method for this class. Also implement the abstract methods of the Department interface. Write a driver class to test the Student class. The program should be menu driven containing the options:
i)Admit new student
ii) Migrate a student
iii)Display details of a student

For the third option a search is to be made on the basis of the entered registration

 Ans. Solution

Tutorial at home
Tutorial at home

12) Create a package containing classes that define all input / output methods. Use this package for input / output operations in all the subsequent

13)Complete the following:

  1. Create a package named shapes.
  2. Create some classes in the package representing some common geometric shapes like Square, Triangle, Circle and so on. The classes should contain area and perimeter methods in them.
  3. Compile the package.
  4. Use this package to find area and perimeter of different shapes as chosen by the

 Ans. Solution

14) Write a program called Factorial.java that computes factorials and catches the result in an array of type long for reuse. The long type of variable has its own range. For example 20! Is as high as the range of long type. So check the argument passed and “throw an exception”, if it is too big or too small. If x is less than 0 throw an IllegalArgumentException with a message

“Value of x must be positive”. If x is above the length of the array throw an IllegalArgumentException with a message “Result will overflow”. Here x is the value for which we want to find the factorial.

15) Define an exception called “NoMatchFoundException” that is thrown when a string is not equal to “University”. Write a program that uses this

16)Write multithreaded program that continuously prints the strings “ping” and “PONG” in the console at random distances at intervals of one second. Use two threads one for “ping” and another for “PONG”.

17)Write a program to sort a list of strings using multithreading. Create one of the threads that take a string as input from the user, another thread that sorts the strings and finally another thread that displays the sorted list of

18) Write a java application that behaves like a malicious program in the sense that, whenever the application is executed, it keeps on invoking the “NOTEPAD”, once in every

19) Write a program to implement a stack using the built-in Stack class of java.

20) Write multithreaded applet that continuously prints the strings “ping” and “PONG” on the applet window at random distances at intervals of one second. Use two threads one for “ping” and another for “PONG”.

21) Design a web page (say, your own home page) and embed an applet in that page, so that whenever the browser loads the page, a small window (telling “I AM A VIRUS”) keeps on opening once in every

22) Write a program to calculate the future value of an investment amount and years. The formula for the calculation is as follows:

futureValue = investment_amount x (1 + interest_rate)years

Use textfields for interest rate, investment amount and years. Display the future value in a text field, when clicking the button.

23) Make the calculator using a Frame. The calculator should behave as a calculator, i.e. when you hit the keys 3 + 2 = the screen should show 5, and so

freenotes
    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post