FIT1051 Lecture Notes - Lecture 9: Instance Variable, Return Period
Week 9
Monday, 30 April 2018
10:02 AM
Exam:
30/100 marks:
Coding a class.
Code the shell and the instance variables.
Constructor's are used outside of the class, hence they are public.
They are not void. They are nothing.
The name must be the same as the class.
public class PhonePlan2{
private static int noPlans;
private String name;
private int period; //4 0f the 30 marks
private int totalCost;
private boolean dataRollOver;
public PhonePlan2(){
setPeriod(12);
//must be coded through a mutator
setDataRollOver(true); //instance variable can only be touched through
a mutator
noPlans++
}
public PhonePlan2(String initName, int initPeriod, boolean initDataRollOver){
setName(initName);
setPeriod(initPeriod);
setTotalCost(10000);
setDataRollOver(true);
noPlans++
}
//2 parameter constructor - name, totalCost
public PhonePlan2 (String initName, int initTotalCost){
setName(initName);
setTotalCost(initTotalCost);
setPeriod(12);
setDataRollOver(false);
}
//ACCESSORS
public String getName(){ return name; } //outside world uses accessors
//data going out
find more resources at oneclass.com
find more resources at oneclass.com