Welcome! Log In Create A New Profile

Advanced

Memo of previous paper

Posted by Mac 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar
Mac
Memo of previous paper
May 11, 2010 03:34PM
Section A [30 marks]

1 4
2 3
3 3
4 2
5 1
6 1
7 2
8 2
9 3
10 3
11 4
12 2
13 4
14 2
15 2
avatar
Mac
Re: Memo of previous paper
May 11, 2010 03:34PM
Section B [45 marks]



Question 1

1.1
Language: Java
[22] public class Student{   enum Gender{MALE, FEMALE} //{ String firstName; String lastName; Gender gender; int noOfModulesRegistered; //} static double costOfModule = 756.90;   Student(String fn, String ln, Gender g, int nomr){ firstName = fn; lastName = ln; gender = g; noOfModulesRegistered = nomr; }   void addModules(int numberOfModules){ int newNoOfModules = noOfModulesRegistered + numberOfModules;   assert (newNoOfModules<=10) :"No more than 10 modules are allowed";   noOfModulesRegistered = newNoOfModules; }   int getNoOfModules(){ return this.noOfModulesRegistered; }   public String toString(){ return firstName + " " + lastName + "," + gender + "," + noOfModulesRegistered;   }   boolean checkStudent(Student st1){ if((this.firstName == st1.firstName) && (this.lastName == st1.lastName)) return true; else return false; }   double totalCostOfModules(){ return noOfModulesRegistered * costOfModule; }   double totalCostOfModules(double discount){   double totalCost = totalCostOfModules(); double discountAmt = totalCost * discount/100; return (noOfModulesRegistered * costOfModule) - discountAmt; }     }   1.2 [6]   public class PostGraduateStudent extends Student{   String researchGroup; PostGraduate(String fn, String ln, Gender g, int nomr, String rg){ super(fn,ln,g,nomr); researchGroup = rg; } public String toString(){ return super.toString() + "," + researchGroup; } }
avatar
Mac
Re: Memo of previous paper
May 11, 2010 03:36PM
1.3 Method overriding refers to an instance method in a subclass that has the same method signature and return type of a method in the superclass. The idea is to replace the implementation of the method in the superclass by the method defined in the subclass. The method toString() in PostGraduate is an overridden method of toString() in the Student class. [3]

1.4 It is only a good idea when it the class acts just as a template from which other classes inherit from and does not make any sense to create objects of Student – this arises when you have a specialised classes to represent every kind of student . [2]
Question 2 [12]

2.1 The assertion itemsInBin>0 is false and the program aborts and the last line never executes. [1]

2.2
Language: Java
public void removeFromBin() throws Exception { if (itemsInBin == 0) throw new Exception("Stock is Finished"); else{ --itemsInBin; } }
[4]
2.3
Language: Java
public static void main(String[] args) { try{ StockBin b = new StockBin(1); b.removeFromBin(); b.removeFromBin(); }     catch (Exception e) { System.out.println("Stock Finished"+e); }     System.out.println("Finished with Stock Control" ); }
[5]
2.4 Assertion should not be used to replace exception handling. Exception handling deals with unusual circumstances during program execution. Assertions are to assure the correctness of the program. Exception handling addresses robustness and assertion addresses correctness. Like exception handling, assertions are not used for normal tests, but for internal consistency and validity checks. Assertions are checked at runtime and can be turned on or off at start up time. [2]
Sorry, only registered users may post in this forum.

Click here to login