File: person.js.semantic

package info (click to toggle)
libnb-platform18-java 12.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 729,800 kB
  • sloc: java: 5,059,097; xml: 574,432; php: 78,788; javascript: 29,039; ansic: 10,278; sh: 6,386; cpp: 4,612; jsp: 3,643; sql: 1,097; makefile: 540; objc: 288; perl: 277; haskell: 93
file content (111 lines) | stat: -rw-r--r-- 5,203 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function |>METHOD:Person<|(n,race){ 
	this.constructor.population++;

	// ************************************************************************ 
	// PRIVATE VARIABLES AND FUNCTIONS 
	// ONLY PRIVELEGED METHODS MAY VIEW/EDIT/INVOKE 
	// *********************************************************************** 
	var alive=true, age=1;
	var maxAge=70+|>GLOBAL:Math<|.round(|>GLOBAL:Math<|.random()*15)+|>GLOBAL:Math<|.round(|>GLOBAL:Math<|.random()*15);
	function |>METHOD:makeOlder<|(){ return alive = (++age <= maxAge) } 

	var myName=n?n:"John Doe";
	var weight=1;
 
	// ************************************************************************ 
	// PRIVILEGED METHODS 
	// MAY BE INVOKED PUBLICLY AND MAY ACCESS PRIVATE ITEMS 
	// MAY NOT BE CHANGED; MAY BE REPLACED WITH PUBLIC FLAVORS 
	// ************************************************************************ 
	this.|>METHOD:toString<|=this.|>METHOD:getName<|=function(){ return myName } 

	this.|>METHOD:eat<|=function(){ 
		if (makeOlder()){ 
			this.dirtFactor++;
			return weight*=3;
		} else |>GLOBAL:formatter<|.println(myName+" can't eat, he's dead!");
	} 
	this.|>METHOD:exercise<|=function(){ 
		if (makeOlder()){ 
			this.dirtFactor++;
			return weight/=2;
		} else |>GLOBAL:formatter<|.println(myName+" can't exercise, he's dead!");
	} 
	this.|>METHOD:weigh<|=function(){ return weight } 
	this.|>METHOD:getRace<|=function(){ return race } 
	this.|>METHOD:getAge<|=function(){ return age } 
	this.|>METHOD:muchTimePasses<|=function(){ age+=50; this.dirtFactor=10; } 


	// ************************************************************************ 
	// PUBLIC PROPERTIES -- ANYONE MAY READ/WRITE 
	// ************************************************************************ 
	this.|>FIELD:clothing<|="nothing/naked";
	this.dirtFactor=0;
} 


// ************************************************************************ 
// PUBLIC METHODS -- ANYONE MAY READ/WRITE 
// ************************************************************************ 
Person.prototype.|>METHOD:beCool<| = function(){ this.|>FIELD:clothing<|="khakis and black shirt" } 
Person.prototype.|>METHOD:shower<| = function(){ this.|>FIELD:dirtFactor<|=2 } 
Person.prototype.|>METHOD:showLegs<| = function(){ |>GLOBAL:formatter<|.println(this+" has "+this.legs+" legs") } 
Person.prototype.|>METHOD:amputate<| = function(){ this.legs-- } 


// ************************************************************************ 
// PROTOTYOPE PROERTIES -- ANYONE MAY READ/WRITE (but may be overridden) 
// ************************************************************************ 
Person.prototype.legs=2;


// ************************************************************************ 
// STATIC PROPERTIES -- ANYONE MAY READ/WRITE 
// ************************************************************************ 
Person.population = 0;



// Here is the code that uses the Person class 
function |>METHOD:RunGavinsLife<|(){ 
        |>GLOBAL:formatter<|.println("Start")
	var |>CLASS:gk<|=new Person("Gavin","caucasian");       //New instance of the Person object created. 
	var lk=new Person("Lisa","caucasian");        //New instance of the Person object created. 
	|>GLOBAL:formatter<|.println("There are now "+Person.population+" people");

	gk.showLegs(); lk.showLegs();                 //Both share the common 'Person.prototype.legs' variable when looking at 'this.legs' 

	gk.race = "hispanic";                         //Sets a public variable, but does not overwrite private 'race' variable. 
	|>GLOBAL:formatter<|.println(gk+"'s real race is "+gk.getRace());    //Returns 'caucasian' from private 'race' variable set at create time. 
	gk.eat(); gk.eat(); gk.eat();                 //weight is 3...then 9...then 27 
	|>GLOBAL:formatter<|.println(gk+" weighs "+gk.weigh()+" pounds and has a dirt factor of "+gk.dirtFactor);

	gk.exercise();                                //weight is now 13.5 
	gk.beCool();                                  //clothing has been update to current fashionable levels 
	gk.clothing="Pimp Outfit";                    //clothing is a public variable that can be updated to any funky value 
	gk.shower();
	|>GLOBAL:formatter<|.println("Existing shower technology has gotten "+gk+" to a dirt factor of "+gk.dirtFactor);

	gk.muchTimePasses();                          //50 Years Pass 
	Person.|>CLASS:prototype<|.shower=function(){           //Shower technology improves for everyone 
		this.dirtFactor=0;
	} 
	gk.|>METHOD:beCool<|=function(){                         //Gavin alone gets new fashion ideas 
		this.|>FIELD:clothing<|="tinfoil";
	};

	gk.beCool(); gk.shower();
	|>GLOBAL:formatter<|.println("Fashionable "+gk+" at " 
		+gk.getAge()+" years old is now wearing " 
		+gk.clothing+" with dirt factor " 
		+gk.dirtFactor);

	gk.amputate();                                //Uses the prototype property and makes a public property 
	gk.showLegs(); lk.showLegs();                 //Lisa still has the prototype property 

	gk.muchTimePasses();                          //50 Years Pass...Gavin is now over 100 years old. 
	gk.eat();                                     //Complains about extreme age, death, and inability to eat. 
}

RunGavinsLife();