FIT1051 Lecture Notes - Lecture 9: Instance Variable, Return Period

121 views3 pages
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
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents