Fundamentals of Software Design and Development

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

SOUTHERN UNIVERSITY COLLEGE

SEMESTER C

YEAR 2020 / 2021

FINAL EXAM

PROG1003 FUNDAMENTALS OF SOFTWARE DESIGN AND DEVELOPMENT

DATE: 21 January 2021 DURATION: 2.5 Hours

DIPLOMA IN INFORMATION TECHNOLOGY

YEAR ONE

Instruction to Candidates :

1. Answer ALL questions. Every question contributes 25 marks.


2. Question 1 and question 2 are close book questions. Students must write down the answer
in answer booklet.
3. Question 3 and question 4 are open book questions. Before doing question 3 and question
4, students must submit their question 1 and question 2.
4. Students must upload their answers to Microsoft Teams.

This question paper consists of 4 questions on 5 printed pages.


2

PROG1003 FUNDAMENTALS OF SOFTWARE DESIGN AND DEVELOPMENT

Q1. (a) Show the output of the following programs.

(i) public class ShowTheOutput22 {


public static void main (String[] args){
int k = 5;
int count = 0;
int total = 0;

for (int i = 0; i < 6; i++){


while (i < k) {
count++;
total += i;
i++;
}
}
System.out.println("Count = " + count);
System.out.println("Total = " + total);
}
} (4 marks)

(ii) public class ShowTheOutput23 {


public static void main (String[] args) {
int balance = 16;
while (true){
if (balance < 4)
break;
balance = balance - 4;
System.out.println("Balance is "+ balance);
}
System.out.println("Balance is " + balance);
}
} (5 marks)

(iii) public class ShowTheOutput24 {


public static void main(String args[]) {
int array[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
int sum = 0;
int i = 0;
for (i =0; i < array.length; i++) {
if ((i == 2) || (i == 4)) continue;
else if (i == 6) break;
sum += array[i];
}
System.out.println("i is " + i);
System.out.println("Sum is " + sum);
}
} (4 marks)

This question paper consists of 4 questions on 5 printed pages.


3

PROG1003 FUNDAMENTALS OF SOFTWARE DESIGN AND DEVELOPMENT

Q1. (Continued)

(b) The following program lets the user enters two integer numbers and finds the
larger between two integers. You are required to identify and correct the
errors in the following code. There are six errors in the following code.

Import java.util.Scanner;

public class TestMaximum {


public static void main(String[] args) {
Scanner input = new Scanner(System);

System.out.println("Enter first integer: ");


int firstNumber = input.nextInt();

System.out.println("Enter second integer: ");


int secondNumber = input.nextint();

int largerNumber = max(firstNumber, secondNumber);


System.out.println("The larger number of " + firstNumber + " and " +
secondNumber + is + largerNumber);
}

public static double max(int num1, int num2) {


int result;

if (num1 < num2)


result = num1;
else
result = num2;

return result;
}
} (12 marks)
[Total: 25 marks]

Q2. Draw a flowchart for the following program statements.

Assume that a small shop only sells three famous types of items which are A Grade
Bag, Top Grade Bag and Famous Grade Bag. The unit price for the items are shown
as following table 1. Please write a program to help cashier to calculate the total sale
amount for customer. The cashier can continuously select the item and enter the
quantity of item. The program should check whether the item number is valid (item
number should be either 1, 2 or 3) or not after cashier selects item and enters the
quantity of item. If the item number is not valid, system should let cashier goes back
to select the item and enter the quantity of item. If the item number is valid, the

This question paper consists of 4 questions on 5 printed pages.


4

PROG1003 FUNDAMENTALS OF SOFTWARE DESIGN AND DEVELOPMENT

Q2. (Continued)

system will calculate the total sale amount based on the table 1. After that, cashier
can decide whether continue to select the item and enter the quantity of item or not.
After cashier decides to stop selecting item and entering the quantity of item, the
program should calculate and display total sale amount that had subtracted discount.
The discount will be given to customer based on the following table 2.

Item Number Item Name Unit Price (RM)


1 A Grade Bag 8000
2 Top Grade Bag 10000
3 Famous Grade Bag 12000
Table 1

Total Amount Discount Rate


Greater or equal to 20,000 10%
Greater or equal to 30,000 15%
Greater or equal to 40,000 20%
Table 2
(25 marks)
[Total: 25 marks]

Q3. Use arrays mechanism to write a program that reads an unspecified number of scores
and determines how many scores are above or equal to the average and how many
scores are below the average. Enter a negative number to signify the end of the input.
Assume that the minimum number of scores is 0 and maximum number of scores is
100.

Here is a sample run of the program:

Enter a new score: 44


Enter a new score: 55
Enter a new score: 110
The score 110.0 will not be counted.
Enter a new score: 66
Enter a new score: 120
The score 120.0 will not be counted.
Enter a new score: -1
The average of scores is: 55.0
Number of scores above or equal to the average: 2
Number of scores below the average: 1
(25 marks)
[Total: 25 marks]

This question paper consists of 4 questions on 5 printed pages.


5

PROG1003 FUNDAMENTALS OF SOFTWARE DESIGN AND DEVELOPMENT

Q4. Write a program that prompts the user to enter number of candidates and each
candidate name and votes. After that, the system will display the candidate with the
highest votes and the candidate with the second-highest votes. You cannot use arrays
to store the data and sorting method provided by java library to sort the data.

Here is a sample run of the program:

Enter the number of candidates: 4


Enter a candidate name: Stephen
Enter a candidate's vote: 457
Enter a candidate name: Ivy
Enter a candidate's vote: 988
Enter a candidate name: David
Enter a candidate's vote: 898
Enter a candidate name: Jolin
Enter a candidate's vote: 654

Top two candidates:


Ivy's vote is 988
David's vote is 898
(25 marks)
[Total: 25 marks]

_________________________________________

This question paper consists of 4 questions on 5 printed pages.

You might also like