CSC 2000 Computer Programming Final Exam
5 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is an array?

An array is a data structure that stores a collection of elements of the same data type in contiguous memory locations.

Clearly explain what each part of the method declaration below implies: public static void main(String args[])

public: This keyword means that the main method is accessible from anywhere in the program.
static: This keyword means the main method is associated with the class itself, not with any particular object of the class. This allows the method to be called without creating an object of the class. void: This keyword means the main method does not return any value. main: This is the name of the method. It is a special method that is the entry point for every Java program. The Java Virtual Machine (JVM) executes the code inside the main method first when it runs a Java program. (String args[]): This is the parameter list for the main method. It takes an array of strings as input. This array contains any command-line arguments that are passed to the Java program when it is executed.

How does Java achieve platform independence?

Java achieves platform independence through its bytecode compilation mechanism. It compiles source code (.java) into bytecode (.class), which is platform-independent and can be run on any system that has a Java Virtual Machine (JVM).

Briefly discuss four key characteristics of Java.

<p>Java is known for several characteristics, including:</p> <ol> <li> <strong>Object-oriented:</strong> Java is built on the concept of objects, which are self-contained components that encapsulate data and behavior.</li> <li> <strong>Platform-independent:</strong> As mentioned earlier, Java achieves platform independence through its bytecode compilation, allowing programs to run on various operating systems without modification.</li> <li> <strong>Secure:</strong> Java's security features help prevent malicious code from accessing sensitive system resources.</li> <li> <strong>Robust:</strong> Java's strong type checking, exception-handling mechanisms, and garbage collection contribute to creating robust and reliable code.</li> </ol> Signup and view all the answers

What are the four access modifiers in Java?

<p>The four access modifiers in Java are:</p> <ol> <li> <strong><code>public</code>:</strong> Members declared with <code>public</code> access are accessible from anywhere in the program.</li> <li> <strong><code>private</code>:</strong> Members declared with <code>private</code> access are only accessible within the same class.</li> <li> <strong><code>protected</code>:</strong> Members declared with <code>protected</code> access are accessible within the same package or subclasses of the class.</li> <li> <strong><code>default</code> (package private):</strong> Members declared with <code>default</code> access (or no explicit modifier) are accessible only within the same package.</li> </ol> Signup and view all the answers

Study Notes

CSC 2000 Computer Programming Final Exam

  • Date: 19th November 2021
  • Time: 09:00hrs - 12:00hrs
  • Duration: 3 hours
  • Venue: NSLT
  • Instructions:
    • Two sections in the exam paper
    • Java programming language only
    • Answer all questions in Section A
    • Choose three questions from section B

Section A - Short Answers (40 marks)

  • Question 1:
    • Part a: Write code for a Polygon base class with abstract methods area() and perimeter(). (3 marks)
    • Part b: Write code for a Triangle class that extends Polygon with implemented area() and perimeter() methods. (6 marks)
    • Part c: Create Isosceles and Equilateral triangle classes inheriting from Triangle with appropriate side relationships. (6 marks)
    • Part d: Implement an IllegalTriangleException to ensure triangle side lengths satisfy the triangle inequality (sum of any two sides > third side). Modify the Triangle constructor to throw this exception. (5 marks)
  • Question 2:
    • Part a: Define Object and Class. (4 marks)
    • Part b: Explain the parts of the public static void main(String args[]) method declaration. (4 marks)
    • Part c: Describe Java's platform independence. (4 marks)
    • Part d: Discuss four key characteristics of Java. (4 marks)
    • Part e: List the four access modifiers in Java. (4 marks)

Section B (40 marks)

  • Question 1:

    • Part a: Define an array. (2 marks)
    • Part b: Describe how the class reads scores (0-100 or -1 to quit) from the keyboard. (4 marks)
    • Part c: Store scores in one array and corresponding grades (A,B,C,D,F) in a parallel array. (6 marks)
    • Part d: Implement a method to count the total number of each grade (A,B,C,D,F). (4 marks)
    • Part e: Write a method to compute the average score and grade. (4 marks)
  • Question 2:

    • Describe the classes (Customer, Toy, and potentially Child, their members (fields&methods), and write a Java program that meets the specifications.
  • Question 3:

    • Part a: Define a loop. (2 marks)
    • Part b: Describe how conditions relate to loops. (2 marks)

Other Instructions / Content

  • Question 4:

    • List Java primitive data types. (4 marks)
    • Commands to compile & execute a HelloWorld.java file. (4 marks)
    • Rules for valid Java identifiers (3 marks)
    • Naming conventions for classes, constants, and variables. (3 marks)
    • Importance of code comments. (2 marks)
    • Correctness of sample code provided. (4 marks)
  • Question 5:

    • Illustrate state transitions in a Java thread. (6 marks)
    • Define state and behavior in Java. (4 marks)
    • Declare variables with access modifiers. (4 marks)
    • Briefly explain different programming error types in Java. (6 marks)

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge of Java programming through this comprehensive final exam from CSC 2000. The quiz covers abstract classes, inheritance, and exception handling with a focus on geometry. Prepare to tackle questions related to polygons and triangles while demonstrating your coding skills.

More Like This

Java Abstract Classes
18 questions
Abstract Classes and Methods Quiz
18 questions
Use Quizgecko on...
Browser
Browser