0% found this document useful (0 votes)
40 views6 pages

OOP Assign1

This document is an assignment cover sheet for a student named Obey Sibanda completing Assignment 1 for the course Object Oriented Programming. The assignment instructions state it is worth 50 marks and to submit a PDF with answers to multiple questions, including listing variables for a salary system, commenting on the importance of comments, identifying valid/invalid variable names, correcting errors in Java code, calculating values for arithmetic statements, and writing a Java program to calculate area and perimeter of shapes.

Uploaded by

Obey Mathe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

OOP Assign1

This document is an assignment cover sheet for a student named Obey Sibanda completing Assignment 1 for the course Object Oriented Programming. The assignment instructions state it is worth 50 marks and to submit a PDF with answers to multiple questions, including listing variables for a salary system, commenting on the importance of comments, identifying valid/invalid variable names, correcting errors in Java code, calculating values for arithmetic statements, and writing a Java program to calculate area and perimeter of shapes.

Uploaded by

Obey Mathe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ZQMS-ARC-REC-002

ASSIGNMENT COVER

REGION: Bulawayo SEMESTER: 1 YEAR: 3

FULL NAME OF STUDEN T: Obey Sibanda PIN: P1910721r

EMAIL ADDRESS: [email protected]


PROGRAMME: Bachelor of Software Engineering Honors INTAKE: 7

CONTACT TELEPHONE/CELL: 0783998634 ID. NO.: 08-805631 M35

COURSE NAME: Object Oriented Programming COURSE CODE: BSEH231

ASSIGNMENT NO. e.g. 1 or 2: 1 STUDENT’S SIGNATURE O.S

DUE DATE: SUBMISSION DATE:

ASSIGNMENT TITLE: Assignment 1

Instructions
Marks will be awarded for good presentation and thoroughness in your approach.
NO marks will be awarded for the entire assignment if any part of it is found to be copied directly from
printed materials or from another student.
Complete this cover and attach it to your assignment. Insert your scanned signature.
Student declaration
I declare that:
• I understand what is meant by plagiarism
• The implications of plagiarism have been explained to me by the institution
• This assignment is all my own work and I have acknowledged any use of the published or
unpublished works of other people.

MARK ER’S COMMEN TS:

OVERALL MARK: MARK ER’S NAME:

MARK ER’S SIGNATURE:


DATE:

BSEH231 Assignment 1 (50 Marks) Please submit a pdf


Question 1 a. You intend to develop a program on workers salary system. Try list down the
variables and their data types that represent the information that is going to be used. [5]
int employeeNum;

String employeeFirstName ;

String employeeLastName;

int totalHoursWorked;

double overTimeRatePerHour;

double totalDeductions;

double netSalary;

b. What is the importance of comments in a program?

Using comments in a programs makes our code more understandable. It makes the program more
readable which helps us remember why certain blocks of code were written. Comments can also be
used to ignore some code while testing other blocks of code. It makes it easy to maintain the code and
to find errors easily.

c. State whether the variables below is valid or otherwise. For the variables that are invalid, please state
the following reasons: [5]

i. nameLength is a valid variable name.

ii. Name_length is a valid variable name.

iii. Import is valid variable

iv. 43650BBB is an invalid variable, a variable name cannot start with a digit.

v. BBB43650 is a valid variable name.

d) Rewriting the Java program by correcting the mistakes.

class Error{ public static void main(String args[]){

int length = 1;

int width = 15;

int area = length * width;

System.out.println(“Area is ” +area);

e) Giving values for each of the arithmetic statements below. Statement Value

Statement Value

i. 4 + 5.0 * 6 34.0

ii. (4 + 5) * 6 54

iii. 4 + 5 / 6 4.83333333…..

iv. (4 + 5) / 6 1.5

v. 4 + 5 % 3 6

vi. (4 + 5) % 3 0

f. What is the output that will be displayed by the following program segment: [4]

r = 2;

if (r > 1) System.out.println (“AAA”);

else System.out.println (“BBB”);


if (r < 1) System.out.println (“AAA”);

else System.out.println (“BBB”);

if (r != 1) System.out.println (“AAA”);

else System.out.println(“BBB”);

Exception in thread "main" java.lang.Error: Unresolved


compilation problems:
g. What’s the purpose of Static methods and static variables? [3]

Static methods provide direct access to static variables. Having static methods eliminates the
need for the caller to instantiate an object just to call the method.

Static variables are shared by each class instance. Static variables are set before a class is
loaded before any objects are generated from that class, and before any static methods are
called from that class.
h. Write java program to calculate Area and Perimeter of a rectangle and a circle. [10]

if you make a member static, you can access it without object.


import java.util.Scanner;

public class Practice {

public static void main(String[] args) {


// TODO Auto-generated method stub

int length, width, radius;


double pi = 3.14, area, perimeter;
Scanner s = new Scanner(System.in);
//void rectangle() {
System.out.print("Enter length of a rectangle: ");
length = s.nextInt();
System.out.print("Enter width of a rectangle: ");
width = s.nextInt();
area = length * width;
perimeter = 2 * (length + width);
System.out.println("area of a rectangle is: "+ area);
System.out.println("perimeter of a rectangle is: "+ perimeter);

System.out.println("Enter the radius of a circle: ");


radius=s.nextInt();
area = pi * radius*radius;
perimeter = 2*pi*radius;
System.out.println("area of a circle is: "+ area);
System.out.println("perimeter of a circle is: "+ perimeter);

}
}
i. Which of these statements about constructors is false?
C. There must be exactly one constructor defined for a class.
D. Constructors are almost always declared as public
j. What is Compound Statement?
It is a sequence of zero or more statements enclosed in {...}.
It is considered to be a single statement. A compound statement is a context.
k. Each declaration in the table below contains error. Give reason for the error. [7]
i. int intA[ ] = new double[10]; data types are not the same.
ii. int intA[ ] = new int[1.5]; the number is declared as a float instead of an integer data type

iii. double doubleA = newdouble [-10]; there is a negative element. Array elements must
always be a positive number.
iv. int intMatrik[ ][ ] = new int[10]; different array dimensions, one is defined as single
dimensional array while the other is a two dimensional array.

You might also like