Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / The independence institute of education PROGf5111 PROG5121 Question 1                                                                                                                                                              (Marks: 10) Multiple choice questions: Select one (1) correct answer for each of the following

The independence institute of education PROGf5111 PROG5121 Question 1                                                                                                                                                              (Marks: 10) Multiple choice questions: Select one (1) correct answer for each of the following

Computer Science

The independence institute of education

PROGf5111 PROG5121

Question 1                                                                                                                                                              (Marks: 10)

Multiple choice questions: Select one (1) correct answer for each of the following. In your answer booklet, write down only the number of the question and, next to it, the letter of the correct answer.

 

Q.1.1

To write a definite loop, you initialise a ______________?

(1)

 

(a)

Event control variable.

 

 

(b)

String control variable.

 

 

(c)

Boolean control variable.

 

 

(d)

Loop control variable.

 

 

 

 

 

Q.1.2

Wh at is the term for a variable that holds a memory address?

(1)

 

(a)

Reference

 

 

(b)

Class

 

 

(c)

Constructor

 

 

(d)

Inheritance

 

 

 

 

 

Q.1.3

A lit eral string is:

(1)

 

(a)

A named object of the String class.

 

 

(b)

An anonymous object of the String class.

 

 

(c)

A white space character object of the String class.

 

 

(d)

A null value object of the String class.

 

 

 

 

 

Q.1.4

The mathematical accuracy of a value:

(1)

 

(a)

Significant Digits

 

 

(b)

Ultimate Digits

 

 

(c)

Accurate Digits

 

 

(d)

Semantic Digit

 

 

 

 

 

       

Q.1.5

Comments that use a special case of block comments:

(1)

 

(a)

Line Comments

 

 

(b)

Embedded Comments

 

 

(c)

Outlined Comments

 

 

(d)

Documentation Comments

 

 

 

 

 

Q.1.6

Arch itecturally neutral describes the feature of Java that allows …

(1)

 

(a)

Developers to write programs to run on any platform.

 

 

(b)

Developers to write programs to run on specific platforms.

 

 

(c)

Developers to write programs to run public methods.

 

 

(d)

Developers to write programs to run the same method which will be mutated.

 

 

 

 

Q.1.7

Java Virtual Machine is a …?

(1)

 

(a)

Windows computer on which Java runs.

 

 

(b)

Hyper Threading computer on which Java runs.

 

 

(c)

Hypothetical computer on which Java runs.

 

 

(d)

None of the above.

 

 

 

 

Q.1.8

Asso ciativity refers to:

(1)

 

(a)

Values that are attached to the end of a string.

 

 

(b)

The order in which operands are used with operators.

 

 

(c)

Any value that occurs to the right of an expression.

 

 

(d)

None of the above.

 

 

 

 

Q.1.9

Wha t is the output of the following code segment?

Syst em.out.println((5+20) * 3 + 1);

(1)

 

(a)

29

 

 

(b)

400

 

 

(c)

76

 

 

(d)

99

 

       

Q.1.10

Methods that set or change field values are called …?

(1)

 

(a)

Accessor methods.

 

 

(b)

Private methods.

 

 

(c)

Mutator methods.

 

 

(d)

Public methods.

 

       

 

Question 2                                                                                                                                                        (Marks: 10)

Match-the-columns question: Match the description in Column B with the correct term from Column A. In your answer booklet, write down only the question number and, next to it, the letter of the correct answer. 

 

 

Column A

Column B

 

Q.2.1

Sentinel

a.

When the compiler cannot determine which method to use.

Q.2.2

Flag

b.

Arguments in a method call.

Q.2.3

Char Datatype

c.

Value that stops a loop.

Q.2.4

Parameters

d.

Programs embedded in a Web Page.

Q.2.5

Dead Code

e.

Virtual Machine.

Q.2.6

Applets

f.

Value that holds any single character.

Q.2.7

Ambiguous

g.

A variable that holds an indicator of whether some condition has been met.

Q.2.8

Buffer

h.

Retrieve values.

Q.2.9

Accessor

i.

Set values.

Q.2.10

Mutator

j.

Indicates one of the array’s elements.

 

 

k.

Block of memory.

 

 

l.

Set of statements that are logically unreachable.

 

 

 

 

 

 

       

Question 3                                                                                                                                                        (Marks: 20)

Write the answers to the following questions. 

 

Q.3.1

Explain why an out of bounds error message may be generated when using arrays.

(2)

 

 

 

Q.3.2

Distinguish in your own words between a sequence structure and a decision structure.

(4)

 

 

 

Q.3.3

In programming terms, what is a token?

(2)

 

 

 

Q.3.4

What are the four keywords used in a Switch Statement?

(4)

 

 

 

Q.3.5

Explain what a Run-Time Error is.

(2)

 

 

 

Q.3.6

What does the following code output?

 

int x = 8; int y = 2;

while(x > 8) {

            x--;             y+=2;

}

System.out.println(y);

(2)

 

 

 

Q.3.7

What does the following code output?

 

System.out.println((2 + 3 - 5) * (3 / 3) + (5+5));

 

(2)

 

 

 

Q.3.8

What does the following code output?

 

if((2 == 2) && (3 != 3) && ((5 + 1)==6)){

     System.out.println(true);

}

else {

      System.out.println(false);

}

(2)

 

Question 4                                                                                                                                                        (Marks: 20)

Debug the section of code that follows. Check the code carefully for all errors and list the line numbers, the errors and write the corrections to the errors as well.

 

Line 1

public class Watches {

Line 2

   private  WatchMake;

Line 3

   private string SalesPerson;

Line 4

   private double WatchPrice;

Line 5

   

Line 6

   public Watches(String make String salesPerson, double price) { 

Line 7

           WatchMake = make;

Line 8

           SalesPerson = salesPerson ;

Line 9

           WatchPrice = price

Line 10

    }

Line 11

    public String getWatch {

Line 12

            return WatchMake;

Line 13

    } 

Line 14

    public double getWatchPrice() {

Line 15

             send WatchPrice;

Line 16

    }

Line 17

    public double getCommission() {

Line 18

             double pay_out >> 0.0;

Line 19

             pay_out = WatchPrice *= 0.10;

Line 20

             return pay_out;

Line 21

    

Line 22

}

 

       

Question 5                                                                                                                                                              (Marks: 60)

Write the answers to the following questions.  

 

Q.5.1

Write short Java code to display the following screen (no need to do it practically using a compiler, just basic coding to display the screen): 

Sample screenshot

 

 

 

 

 

(5)

 

 

 

Q.5.2

Explain the two parts that every method in Java must consist of.

(5)

 

 

 

Q.5.3

Write code to declare an array that will hold calendar months (.e. January to December). 

 

Take note: no need to do it practically using a compiler, just basic coding to declare an array and load calendar months as per question. 

(4)

 

 

 

Q.5.4

Briefly explain what actual parameters are.

(2)

 

 

 

Q.5.5

__________ consists of programming statements that have been compiled into binary format.

(2)

 

 

 

Q.5.6

__________ is the programming feature that allows you to use a method name to encapsulate a series of statements.

(2)

 

 

 

Q.5.7

Write a method that calculates and returns an average as depicted in the following figure. 

(10)

 

 

 

 

 

Take note: no need to do it practically using a compiler, just basic coding for a method that calculates the average as depicted in the figure above. 

 

 

 

Q.5.8

Write short Java code to display the following screen (no need to do it practically using a compiler, just basic coding to display the screen):  Sample screenshot

 

 

(5)

 

 

 

Q.5.9

Write a short Java code to display the following screen (no need to do it practically using a compiler, just basic coding to display the screen): 

Sample screenshot

(5)

 

 

 

 

 

 

 

Q.5.10

Discuss the difference between a PRETEST and POSTTEST loop.

(4)

 

 

 

Q.5.11

Briefly explain parallel arrays.

(2)

 

 

 

Q.5.12

What does immutable refer to?

(2)

 

 

 

Q.5.13

Given the following coding. 

 

private String GenerateStars(int x)

    {

        String stars = "";         if (SALES[x]>=100){             stars = "*****";

        }         else{

            stars = "**";

        }

        return stars;

    }

 

Explain the if statement.  

(3)

 

 

 

Q.5.14

Discuss any two ways in which you could improve a loop performance.

(4)

 

 

 

Q.5.15

Given the screenshot below: 

 

(5)

 

 

 

 

Write a method (only the method -

no need to do it practically using a

compiler

)

 that can calculate and return the transfer cost. Transfer cost is

calculated by (

price

 x

2.5

%

)

 if the price is greater than or equal to R500

000

 

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE