Assignment 1 Answer at least any 10 questions − maximum 100 marks. Each question is worth 10 marks. You must score at least 50 to pass the assignment.
1. Design a class called ‘Parliament’. Identify and explain its key states and behaviour.
2. What are interfaces? Why do we need them? Write an interface for the class called ‘Parliament’ from question 1.
3. Explain the structure of a Java program. Write a program in that exemplifies and tests the functionalities of all any four (4) methods of the class ‘String’.
4. What is an inner class? Can you define an inner class inside a method? What variables can you access from within the inner class? Explain with an example program.
5. How many types of literals are there in Java? Which characters may be used as the second character of an identifier, but not as the first character of an identifier? Explain with an example program.
6. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? Explain with an example program.
7. What is the range of basic data types in Java? Explain with an example program.
8. Explain about enum data types in Java with an example program. Write a program to generate random numbers in the range of 1 to 10.
9. What are differences between break and continue in Java? Explain with an example program.
10. Differentiate between a while statement and a do-while statement. Explain with example programs.
11. Write a recursive program that calculates the greatest common divisor (GCD) of three (3) input numbers.
12. Write a program to determine if an input string is a palindrome.
13. Write a program that reads the scores of nine innings of a baseball game between two teams from console and decides the winner. How would you extend the program to compute the winners of N number of games between the two teams? (No need to write a complete program for the extension part.)
14. Using a Java program, explain different types of methods in Java.
15. Design a class that represents the notion of ‘environmental disasters’.
16. Design a class that represents the notion of ‘corruption in politics’.
17. Design a class that represents the notion of ‘writing competency’.
18. Identify five typical error messages from the Java compiler. Develop code and compile the code to produce these errors.
19. Identify five typical warnings from the Java compiler. Develop code and compile the code to produce these warnings.
20. Differentiate between String and StringBuffer classes with an example program.
21. What is object-oriented programming? What might be a potentially popular programming methodology 25 years from now? Explain.
22. Design a Java class that captures information on supernovas. Refer to http://en.wikipedia.org/wiki/Supernova for additional information on them.
23. Write a program that prompts the user to enter the number of days (e.g., 100) and displays the resultant number of hours and minutes.
24. Write a program that prompts the user to enter the exchange rate from Canadian dollars (CAD) to Indian rupees (INR). Prompt the user to enter 0 to convert from Canadian dollars to Indian rupees, and 1 to convert from Indian rupees to Canadian dollars. Prompt the user to enter the amount in Canadian dollars or Indian rupees to convert it to Indian rupees or Canadian dollars, respectively.
25. Write a program that computes the following expression up to four (4) decimal places: