Question: (1)a. Java is a platform independent language. What does this mean? b. What is polymorphism in Java? Given an example. 2. (10 marks) Write a
(1)a. Java is a platform independent language. What does this mean? b. What is polymorphism in Java? Given an example.
2. (10 marks) Write a program that helps the user count his change. The program should ask how many quarters the user has, then how many dimes, and then how many nickels. Then the program should tell the user how much money he has, expressed in dollars.
3. (10 marks) a. What is a block statement in Java? How are block statements used? b. What is a graphical user interface? What are events?
4. (10 marks) Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consists of a number, followed by an operator, followed by another number. The operators that are allowed are +, ?, *, and /. You can read the numbers with TextIO.getDouble() and the operator with TextIO.getChar(). Your program should read an expression, print its value, read another expression, print its value, and so on. The program should end when the user enters 0 as the first number on the line.
5. (10 marks) Given: public class Boxer1 { Integer i; int x; public Boxer1(int y) { x=i+y; System.out.println(x); } public static void main(String[] args) { new Boxer1(new Integer(4)); } } What is the result? a. The value 4 is printed at the command line. b. Compilation fails because of an error in line 5. c. Compilation fails because of an error in line 9. d. A NullPointerException occurs at runtime. e. A NumberFormatException occurs at runtime. f. An IllegalStateException occurs at runtime.
6. (10 marks) a. Explain the enum data type with an example program. b. What is a dynamic array?
7. (10 marks) Explain what is meant by the terms instance variable and instance method. Also explain what is meant by the terms subclass and superclass. What is the relation between polymorphism and subclass?
8. (10 marks) A news magazine wants to conduct a survey across the four research universities in Alberta. For each university, the magazine wants to gather data on the number of departments, the number of students doing research in each department, courses taken by each research student, and marks scored by these students in courses. Design and develop a class to capture this information. Then write a program to find the average marks scored by students in a given discipline across all four universities. Note: a discipline might include a number of courses.
9. (10 marks) a. What are dynamic arrays in Java? Explain with an example. b. Write a program in a class NumberAboveAverage that counts the number of days that the temperature is above average. Read ten temperatures from the keyboard and place them in an array. Compute the average temperature and then count and display the number of days on which the temperature was above average.
10. (10 Marks) a. How to declare and initialize a two dimensional Array in Java? Explain with an example. b. Explain with an example how a two-dimensional array can be passed to a Method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
