Android Study Jam Quiz
Android Study Jam Quiz
2. Write a program that asks the user for her name and greets her with her name.
3.Create the equivalent of a four-function calculator. The program should ask the user to
enter a number, an operator, and another number. (Use floating point.) It should then carry
out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the
two numbers. Use a switch statement to select the operation. Finally, display the result.
When it finishes the calculation, the program should ask whether the user wants to do
another calculation. The response can be ‘y’ or ‘n’.
Some sample interaction with the program might look like this:
Enter first number, operator, second number: 10 / 3
Answer = 3.333333
Do another (y/n)? y
Enter first number, operator, second number: 12 + 100
Answer = 112
Do another (y/n)? n
Point of this quiz: handling inputs from user, conditional checking, infinite loop
4.
Use for loops to construct a program that displays a pyramid of Xs on the screen. Ask the
user to input number of lines to show. The pyramid should look like this if user input 5.
X
XXX
XXXXX
XXXXXXX
XXXXXXXXX 1
One way to do this is to nest two inner loops, one to print spaces and one to print Xs, inside
an outer loop that steps down the screen from line to line.
5.
Create a class called time that has separate int member data for hours, minutes, and
seconds. One constructor should initialize this data to 0, and another should initialize it to
fixed values. Another member function should display it, in 11:59:59 format. The final
member function should add two objects of type time passed as arguments.
A main() program should create two initialized time objects (should they be f inal ?) and
one that isn’t initialized. Then it should add the two initialized values together, leaving the
result in the third time variable. Finally it should display the value of this third variable.
Make appropriate member functions final .
6.
Write a program that will read a sequence of positive real numbers entered by the user and
will print the same numbers in sorted order from smallest to largest. The user will input a
zero to mark the end of the input. Assume that at most 100 positive numbers will be
entered.
7.
Write a program in Java to print Fibonacci series up to given number? Write both
iterative
and
recursiveversion.
Fibonacci series a popular number series and very popular programming question in Java, in
which number is equal to sum of previous two numbers, starting from third. Fibonacci series
is also a good recursion exercise and often asked in Interviews as well. Try doing this quiz by
using both Iteration (loops) and recursion. For help see H
ow to print Fibonacci series in Java
using recursion.
8.
In the last exercise, we will create the following class hierarchy:
For each exercise, you will probably want to write a main method in a separate class to test
the classes you are implementing as you go.