Você está na página 1de 4

Java Assignment 2

Date of submission: 14th Mar-2016


1. Write a java Program that evaluates the given arithmetic expression (using methods from StringTokenizer
class methods). Sample output: (Given expression)

1 + 20

* 2 /

Output has to display the following format:


Operand1: 1
Operator 1: +
Operand 2: 20
Operator 2: *
Operand 3: 2
Operator 3: /
Operand 4: 4
Evaluated Expression is: 11
2. Create an array A of size 1000 with random values named as A1, A2, A3, A4 and A5. Similarly
Create an array B of size 1000 with random values named as B1, B2, B3, B4 and B5. Write a Java
program that accepts an input threshold value and displays the pair (Ai, Bi) of values which are
above or equal to the threshold value. When the user gives an input x or X then program has to
quit otherwise program has to continue for the next threshold value. And also display the array
values of A and B which were generated. (Use appropriate methods of user-defined to
demonstrate this.)

Sample output:

Strings generated for A and B arrays are:


S.no. A
B
------ ----1
A1
B1
2
A2
B1
3
A1
B2
4
A3
B2
5
A5
B1
6
A4
B2
.
.
.
.
.
.
1000 A5
B1
Enter the Threshold value: 100
-------------------------------------------A
B
Count
-------------------------------------------A1
B1
250
A1
B2
260
A2
B3
300
A3
B1
260
A4
B4
101

.
.
.
.
.
.
-------------------------------------------Do you want to continue(y/x): x
(Exit from program)
3. From the above program String Arrays A and B with size 1000 values has to generate the bitmaps
as shown below. Use the bitmaps generated from A and B, Program has to generate the output pair
of values according to the threshold value given by the user based on the
bitCount of the pairs.
Sample output:
Strings generated for A and B arrays are:
S.no.
-----1
2
3
4
5
6
.
.
1000

A
--A1
A2
A1
A3
A5
A4
.
.
A5

B
--B1
B1
B2
B2
B1
B2
.
.
B1

Bitmaps generated are:


A1
1
0
1
0
0
0
.
.
.

A2
0
1
0
0
0
0
.
.
.

A3
0
0
0
1
0
0
.
.
.

A4
0
0
0
0
0
1
.
.
.

A5
0
0
0
0
1
0
.
.
.

B1
1
1
0
0
1
0
.
.
.

B2
0
0
1
1
0
1
.
.
.

Enter the Threshold value: 100


-------------------------------------------A
B
Count
-------------------------------------------A1
B1
250
A1
B2
260
A2
B3
300
A3
B1
260
A4
B4
101
.
.
.
.
.
.
.
.
.
-------------------------------------------Do you want to continue(y/x): x
(Exit from program)

B3
0
0
0
0
0
0
.
.
.

B4
0
0
0
0
0
0
.
.
.

B5
0
0
0
0
0
0
.
.
.

4. Design a Maze Game as follows:

*
*

*
*
*
*
*

*
*
*
*
*

*
*

*
*

*
*

*
*

*
*

*
*

*
*
*
*
*

*
*
*
*
*

*
*
*
*
*

*
*

*
* E

The program has to start from S and reaches to end E by finding the empty spaces. Create your
own 2-d array which has the filled values as shown above. Use the direction keys
(d- Down
r-Right
l-Left
r-Right)
to move the symbol S. And also fill the empty spaces which are visited with . symbol. Program
has to quit when it finds the path from S to E
Example: Take the input from the user as following format:
<Direction Key> <number of moves>
Ex: d 5 (which moves S Down to 5 spaces).
Sample Output is as shown below:
1. Command: D 5
2. Command: R 3

.
.
.
.
.
S
*
*

*
*
*
*
*
*
*

*
*
*
*
*
*
*

*
*

*
*

*
*

*
*
*
*
*

*
*

*
*

*
*
*
*
*

*
*
*
*
*

*
*

.
.
.
.
.
.
*
*

3.Command: U 3

.
.
.
.
.
.
*
*

*
*
*
*
*
.
*
*

*
*
*
*
*
.
*
*

*
*
S
.
.
.
*
*

*
*

*
*

*
*
*
*
*

*
*
*
*
*

*
*
*
*
*

*
*

*
*

(and so on) program has to quit when S reaches to E.

*
*
*
*
*
.
*
*

*
*
*
*
*
.
*
*

*
*

*
*

*
*

*
*
*
*
*

S
*
*

*
*
*
*
*

*
*
*
*
*

*
*

*
*

5. Design an Interface named Stack with the following methods:


a. Push( ) and Pop( )
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. Use the above defined class to evaluate a user given expression.
6. 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.
c. 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 subclass
QueueTest.java
7. Write a Java program which accepts given a string where the string "OOP" appears at least two
times, find the first and last OOP in the whole string. Return the text from between the two OOP.
8. Suppose you have a string like this:"Once there was a woman name:angelina: and a man
name:tony: and their friend name:jane: and ...". Inside of a long text there are little "name:"
sections. Write a code snippet for a method printNames(String string) to find and print all the
names.
9. Create a class AmountInWords to convert the amount into words. (Consider the amount to be
not more than 100000.)
10. Define a Class Reverse that contains String object: result; Integer object: number; static void
Reverse(integer n), String toString() is a overridden method that returns the reverse of a given
number in words. Use accessor and mutator methods to get and set the input to number object
(note: without using primitive data types). Write a program that displays the reverse of a given
number in words.
11. Design a Package named as ArithmeticOperation that implements Arithmetic operations like add,
subtract, multiply, and divide. Write a Java program that uses the methods of the package
ArithmeticOperation and performs the operations based on user choice.

Você também pode gostar