- Information
- AI Chat
Was this document helpful?
Excercise 1 practice basicsyntax
Course: Java programming (CSC1016S)
174 Documents
Students shared 174 documents in this course
University: University of Cape Town
Was this document helpful?
Assignment 2
Basic Syntax - Introduction to Objects and Java
Assignment Overview
The aim of this assignment is to introduce you to Java and object-oriented programming
concepts. You will build, test, and debug simple programs that create and manipulate
compositions of objects. This will help you transition from Python to Java by leveraging your
existing knowledge in a new context. The exercises are designed to be straightforward, akin
to Python problems you may have encountered in CSC1015F. However, the shift to
object-oriented programming requires a richer representation of concepts through the use of
classes for objects, rather than basic data types like Strings or integers.
Exercise One [50 Marks]
This exercise involves the use of Rectangle and Area classes of objects described as
follows:
Class Rectangle
ARectangle object represents a geometric rectangle defined by its width and height.
Constructors
●Rectangle(double width, double height)
Creates a Rectangle object with the specified width and height.
Methods
●public Area calculateArea()
Calculates and returns the area of the rectangle as an Area object.
●public String toString()
Returns a string representation of this Rectangle object in the form "Width: w,
Height: h".
Class Area
An Area object represents the area of a geometric shape.
Methods
●public double getValue()
Returns the numeric value of the area.