More Related Content Similar to Refactoring in AS3 Similar to Refactoring in AS3(20) Refactoring in AS3
4. AS3 OOP Design Pattern
29. // Customer.as // Customer.as
public function checkout ():String public function checkout():String
{ {
... while(rentals.length > 0)
while(rentals.length > 0) {
{ ...
...
... this_amount = amount_for(the_rental);
...
switch(the_rental.get_movie().get_price_code()) }
{ ..
case Movie.REGULAR: // }
this_amount += 2;
if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number
{ {
this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0;
} switch (the_rental.get_movie().get_price_code())
break; {
case Movie.REGULAR ://
case Movie.NEW_RELEASE: // result += 2;
this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2)
break; {
result += (the_rental.get_days_rented() - 2) * 1.5;
case Movie.CHILDRENS: // }
this_amount += 1.5; break;
if (the_rental.get_days_rented() > 3)
{ case Movie.NEW_RELEASE ://
this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3;
} break;
break;
} case Movie.CHILDRENS ://
... result += 1.5;
} if (the_rental.get_days_rented() > 3)
{
result += (the_rental.get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
30. // Customer.as // Customer.as
public function checkout ():String public function checkout():String
{ {
... while(rentals.length > 0)
while(rentals.length > 0) {
{ ...
...
... this_amount = amount_for(the_rental);
...
switch(the_rental.get_movie().get_price_code()) }
{ ..
case Movie.REGULAR: // }
this_amount += 2;
if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number
{ {
this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0;
} switch (the_rental.get_movie().get_price_code())
break; {
case Movie.REGULAR ://
case Movie.NEW_RELEASE: // result += 2;
this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2)
break; {
result += (the_rental.get_days_rented() - 2) * 1.5;
case Movie.CHILDRENS: // }
this_amount += 1.5; break;
if (the_rental.get_days_rented() > 3)
{ case Movie.NEW_RELEASE ://
this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3;
} break;
break;
} case Movie.CHILDRENS ://
... result += 1.5;
} if (the_rental.get_days_rented() > 3)
{
result += (the_rental.get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
31. // Customer.as // Customer.as
public function checkout ():String public function checkout():String
{ {
... while(rentals.length > 0)
while(rentals.length > 0) {
{ ...
...
... this_amount = amount_for(the_rental);
...
switch(the_rental.get_movie().get_price_code()) }
{ ..
case Movie.REGULAR: // }
this_amount += 2;
if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number
{ {
this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0;
} switch (the_rental.get_movie().get_price_code())
break; {
case Movie.REGULAR ://
case Movie.NEW_RELEASE: // result += 2;
this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2)
break; {
result += (the_rental.get_days_rented() - 2) * 1.5;
case Movie.CHILDRENS: // }
this_amount += 1.5; break;
if (the_rental.get_days_rented() > 3)
{ case Movie.NEW_RELEASE ://
this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3;
} break;
break;
} case Movie.CHILDRENS ://
... result += 1.5;
} if (the_rental.get_days_rented() > 3)
{
result += (the_rental.get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
32. // Customer.as // Customer.as
public function checkout ():String public function checkout():String
{ {
... while(rentals.length > 0)
while(rentals.length > 0) {
{ ...
...
... this_amount = amount_for(the_rental);
...
switch(the_rental.get_movie().get_price_code()) }
{ ..
case Movie.REGULAR: // }
this_amount += 2;
if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number
{ {
this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0;
} switch (the_rental.get_movie().get_price_code())
break; {
case Movie.REGULAR ://
case Movie.NEW_RELEASE: // result += 2;
this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2)
break; {
result += (the_rental.get_days_rented() - 2) * 1.5;
case Movie.CHILDRENS: // }
this_amount += 1.5; break;
if (the_rental.get_days_rented() > 3)
{ case Movie.NEW_RELEASE ://
this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3;
} break;
break;
} case Movie.CHILDRENS ://
... result += 1.5;
} if (the_rental.get_days_rented() > 3)
{
result += (the_rental.get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
34. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. private function amount_for (the_rental:Rental):Number
private function amount_for (the_rental:Rental):Number {
{ return the_rental.get_charge();
var result:int = 0; }
switch (the_rental.get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Rental.as
result += 2; public class Rental
if (the_rental.get_days_rented() > 2) {
{ ...
result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number
} {
break; var result:int = 0;
switch (get_movie().get_price_code())
case Movie.NEW_RELEASE :// {
result += the_rental.get_days_rented() * 3; case Movie.REGULAR ://
break; result += 2;
if (get_days_rented() > 2)
case Movie.CHILDRENS :// {
result += 1.5; result += (get_days_rented() - 2) * 1.5;
if (the_rental.get_days_rented() > 3) }
{ break;
result += (the_rental.get_days_rented() - 3) * 1.5;
} case Movie.NEW_RELEASE ://
break; result += get_days_rented() * 3;
} break;
return result; case Movie.CHILDRENS ://
} result += 1.5;
.. if (get_days_rented() > 3)
} {
result += (get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
...
}
35. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. private function amount_for (the_rental:Rental):Number
private function amount_for (the_rental:Rental):Number {
{ return the_rental.get_charge();
var result:int = 0; }
switch (the_rental.get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Rental.as
result += 2; public class Rental
if (the_rental.get_days_rented() > 2) {
{ ...
result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number
} {
break; var result:int = 0;
switch (get_movie().get_price_code())
case Movie.NEW_RELEASE :// {
result += the_rental.get_days_rented() * 3; case Movie.REGULAR ://
break; result += 2;
if (get_days_rented() > 2)
case Movie.CHILDRENS :// {
result += 1.5; result += (get_days_rented() - 2) * 1.5;
if (the_rental.get_days_rented() > 3) }
{ break;
result += (the_rental.get_days_rented() - 3) * 1.5;
} case Movie.NEW_RELEASE ://
break; result += get_days_rented() * 3;
} break;
return result; case Movie.CHILDRENS ://
} result += 1.5;
.. if (get_days_rented() > 3)
} {
result += (get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
...
}
36. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. private function amount_for (the_rental:Rental):Number
private function amount_for (the_rental:Rental):Number {
{ return the_rental.get_charge();
var result:int = 0; }
switch (the_rental.get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Rental.as
result += 2; public class Rental
if (the_rental.get_days_rented() > 2) {
{ ...
result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number
} {
break; var result:int = 0;
switch (get_movie().get_price_code())
case Movie.NEW_RELEASE :// {
result += the_rental.get_days_rented() * 3; case Movie.REGULAR ://
break; result += 2;
if (get_days_rented() > 2)
case Movie.CHILDRENS :// {
result += 1.5; result += (get_days_rented() - 2) * 1.5;
if (the_rental.get_days_rented() > 3) }
{ break;
result += (the_rental.get_days_rented() - 3) * 1.5;
} case Movie.NEW_RELEASE ://
break; result += get_days_rented() * 3;
} break;
return result; case Movie.CHILDRENS ://
} result += 1.5;
.. if (get_days_rented() > 3)
} {
result += (get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
...
}
37. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. private function amount_for (the_rental:Rental):Number
private function amount_for (the_rental:Rental):Number {
{ return the_rental.get_charge();
var result:int = 0; }
switch (the_rental.get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Rental.as
result += 2; public class Rental
if (the_rental.get_days_rented() > 2) {
{ ...
result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number
} {
break; var result:int = 0;
switch (get_movie().get_price_code())
case Movie.NEW_RELEASE :// {
result += the_rental.get_days_rented() * 3; case Movie.REGULAR ://
break; result += 2;
if (get_days_rented() > 2)
case Movie.CHILDRENS :// {
result += 1.5; result += (get_days_rented() - 2) * 1.5;
if (the_rental.get_days_rented() > 3) }
{ break;
result += (the_rental.get_days_rented() - 3) * 1.5;
} case Movie.NEW_RELEASE ://
break; result += get_days_rented() * 3;
} break;
return result; case Movie.CHILDRENS ://
} result += 1.5;
.. if (get_days_rented() > 3)
} {
result += (get_days_rented() - 3) * 1.5;
}
break;
}
return result;
}
...
}
38. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals; var rentals:Array = _rentals;
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var this_amount:Number = 0; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental); this_amount = the_rental.get_charge();
// //
bonus_points += 1; bonus_points += 1;
... ...
} }
result += "n " + total_amount + "n"; result += "n " + total_amount + "n";
result += " " + bonus_points + " "; result += " " + bonus_points + " ";
return result; return result;
} }
.. ..
} }
39. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals; var rentals:Array = _rentals;
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var this_amount:Number = 0; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental); this_amount = the_rental.get_charge();
// //
bonus_points += 1; bonus_points += 1;
... ...
} }
result += "n " + total_amount + "n"; result += "n " + total_amount + "n";
result += " " + bonus_points + " "; result += " " + bonus_points + " ";
return result; return result;
} }
.. ..
} }
40. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals; var rentals:Array = _rentals;
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var this_amount:Number = 0; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental); this_amount = the_rental.get_charge();
// //
bonus_points += 1; bonus_points += 1;
... ...
} }
result += "n " + total_amount + "n"; result += "n " + total_amount + "n";
result += " " + bonus_points + " "; result += " " + bonus_points + " ";
return result; return result;
} }
.. ..
} }
42. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals; var rentals:Array = _rentals;
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
this_amount = amount_for(the_rental); bonus_points += 1;
// // 2 1
bonus_points += 1; if ((the_rental.get_movie().get_price_code() ==
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))
// 2 1 {
if ((the_rental.get_movie().get_price_code() == bonus_points += 1;
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) }
{ result += "-" + the_rental.get_movie().get_title() + " " +
bonus_points += 1; the_rental.get_charge() +" n";
} total_amount += the_rental.get_charge();
result += "-" + the_rental.get_movie().get_title() + " " + }
this_amount +" n";
total_amount += this_amount; result += "n " + total_amount + "n";
} result += " " + bonus_points + " ";
result += "n " + total_amount + "n"; return result;
result += " " + bonus_points + " "; }
return result;
}
43. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals; var rentals:Array = _rentals;
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
this_amount = amount_for(the_rental); bonus_points += 1;
// // 2 1
bonus_points += 1; if ((the_rental.get_movie().get_price_code() ==
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))
// 2 1 {
if ((the_rental.get_movie().get_price_code() == bonus_points += 1;
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) }
{ result += "-" + the_rental.get_movie().get_title() + " " +
bonus_points += 1; the_rental.get_charge() +" n";
} total_amount += the_rental.get_charge();
result += "-" + the_rental.get_movie().get_title() + " " + }
this_amount +" n";
total_amount += this_amount; result += "n " + total_amount + "n";
} result += " " + bonus_points + " ";
result += "n " + total_amount + "n"; return result;
result += " " + bonus_points + " "; }
return result;
}
44. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals; var rentals:Array = _rentals;
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
this_amount = amount_for(the_rental); bonus_points += 1;
// // 2 1
bonus_points += 1; if ((the_rental.get_movie().get_price_code() ==
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))
// 2 1 {
if ((the_rental.get_movie().get_price_code() == bonus_points += 1;
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) }
{ result += "-" + the_rental.get_movie().get_title() + " " +
bonus_points += 1; the_rental.get_charge() +" n";
} total_amount += the_rental.get_charge();
result += "-" + the_rental.get_movie().get_title() + " " + }
this_amount +" n";
total_amount += this_amount; result += "n " + total_amount + "n";
} result += " " + bonus_points + " ";
result += "n " + total_amount + "n"; return result;
result += " " + bonus_points + " "; }
return result;
}
46. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
... while (rentals.length > 0) ...
{ while (rentals.length > 0)
var this_amount:Number = 0; {
var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental);
this_amount = amount_for(the_rental);
//
bonus_points += 1; //
bonus_points += the_rental.get_bonus_points();
// 2 1
if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n";
{ total_amount += this_amount;
bonus_points += 1; }
} ...
}
result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n"; // Rental.as
total_amount += this_amount; public class Rental
} {
... ..
} public function get_bonus_points():int
{
// 2 1
if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
(get_days_rented() > 1))
{
return 2;
}
else
{
return 1;
}
}
..
}
47. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
... while (rentals.length > 0) ...
{ while (rentals.length > 0)
var this_amount:Number = 0; {
var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental);
this_amount = amount_for(the_rental);
//
bonus_points += 1; //
bonus_points += the_rental.get_bonus_points();
// 2 1
if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n";
{ total_amount += this_amount;
bonus_points += 1; }
} ...
}
result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n"; // Rental.as
total_amount += this_amount; public class Rental
} {
... ..
} public function get_bonus_points():int
{
// 2 1
if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
(get_days_rented() > 1))
{
return 2;
}
else
{
return 1;
}
}
..
}
48. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
... while (rentals.length > 0) ...
{ while (rentals.length > 0)
var this_amount:Number = 0; {
var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental);
this_amount = amount_for(the_rental);
//
bonus_points += 1; //
bonus_points += the_rental.get_bonus_points();
// 2 1
if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n";
{ total_amount += this_amount;
bonus_points += 1; }
} ...
}
result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n"; // Rental.as
total_amount += this_amount; public class Rental
} {
... ..
} public function get_bonus_points():int
{
// 2 1
if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
(get_days_rented() > 1))
{
return 2;
}
else
{
return 1;
}
}
..
}
49. // Customer.as // Customer.as
public function checkout ():String public function checkout ():String
{ {
... while (rentals.length > 0) ...
{ while (rentals.length > 0)
var this_amount:Number = 0; {
var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0;
var the_rental:Rental = rentals.shift() as Rental;
this_amount = amount_for(the_rental);
this_amount = amount_for(the_rental);
//
bonus_points += 1; //
bonus_points += the_rental.get_bonus_points();
// 2 1
if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n";
{ total_amount += this_amount;
bonus_points += 1; }
} ...
}
result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n"; // Rental.as
total_amount += this_amount; public class Rental
} {
... ..
} public function get_bonus_points():int
{
// 2 1
if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
(get_days_rented() > 1))
{
return 2;
}
else
{
return 1;
}
}
..
}
51. // Customer.as // Customer.as
public class Customer public class Customer
{ {
... public function checkout ():String
public function checkout ():String {
{ var total_amount:Number = 0;//
var total_amount:Number = 0;// var bonus_points:int = 0;//
var bonus_points:int = 0;// var rentals:Array = _rentals.concat();
var rentals:Array = _rentals.concat(); var result:String = get_name() +" n";
var result:String = get_name() +" n";
while (rentals.length > 0)
while (rentals.length > 0) {
{ var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
// bonus_points += the_rental.get_bonus_points();
bonus_points += the_rental.get_bonus_points();
result += "-" + the_rental.get_movie().get_title() + " "
result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n"; }
total_amount += the_rental.get_charge();
} result += "n " + get_total_charge() + "n";
result += " " + bonus_points + " ";
result += "n " + total_amount + "n";
result += " " + bonus_points + " "; return result;
}
return result;
} private function get_total_charge():Number
... {
} var rentals:Array = _rentals.concat();
var result:Number = 0;
while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_charge();
}
return result;
}
}
52. // Customer.as // Customer.as
public class Customer public class Customer
{ {
... public function checkout ():String
public function checkout ():String {
{ var total_amount:Number = 0;//
var total_amount:Number = 0;// var bonus_points:int = 0;//
var bonus_points:int = 0;// var rentals:Array = _rentals.concat();
var rentals:Array = _rentals.concat(); var result:String = get_name() +" n";
var result:String = get_name() +" n";
while (rentals.length > 0)
while (rentals.length > 0) {
{ var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
// bonus_points += the_rental.get_bonus_points();
bonus_points += the_rental.get_bonus_points();
result += "-" + the_rental.get_movie().get_title() + " "
result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n"; }
total_amount += the_rental.get_charge();
} result += "n " + get_total_charge() + "n";
result += " " + bonus_points + " ";
result += "n " + total_amount + "n";
result += " " + bonus_points + " "; return result;
}
return result;
} private function get_total_charge():Number
... {
} var rentals:Array = _rentals.concat();
var result:Number = 0;
while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_charge();
}
return result;
}
}
53. // Customer.as // Customer.as
public class Customer public class Customer
{ {
... public function checkout ():String
public function checkout ():String {
{ var total_amount:Number = 0;//
var total_amount:Number = 0;// var bonus_points:int = 0;//
var bonus_points:int = 0;// var rentals:Array = _rentals.concat();
var rentals:Array = _rentals.concat(); var result:String = get_name() +" n";
var result:String = get_name() +" n";
while (rentals.length > 0)
while (rentals.length > 0) {
{ var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
// bonus_points += the_rental.get_bonus_points();
bonus_points += the_rental.get_bonus_points();
result += "-" + the_rental.get_movie().get_title() + " "
result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n"; }
total_amount += the_rental.get_charge();
} result += "n " + get_total_charge() + "n";
result += " " + bonus_points + " ";
result += "n " + total_amount + "n";
result += " " + bonus_points + " "; return result;
}
return result;
} private function get_total_charge():Number
... {
} var rentals:Array = _rentals.concat();
var result:Number = 0;
while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_charge();
}
return result;
}
}
54. // Customer.as // Customer.as
public class Customer public class Customer
{ {
... public function checkout ():String
public function checkout ():String {
{ var total_amount:Number = 0;//
var total_amount:Number = 0;// var bonus_points:int = 0;//
var bonus_points:int = 0;// var rentals:Array = _rentals.concat();
var rentals:Array = _rentals.concat(); var result:String = get_name() +" n";
var result:String = get_name() +" n";
while (rentals.length > 0)
while (rentals.length > 0) {
{ var the_rental:Rental = rentals.shift() as Rental;
var the_rental:Rental = rentals.shift() as Rental;
//
// bonus_points += the_rental.get_bonus_points();
bonus_points += the_rental.get_bonus_points();
result += "-" + the_rental.get_movie().get_title() + " "
result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n"; }
total_amount += the_rental.get_charge();
} result += "n " + get_total_charge() + "n";
result += " " + bonus_points + " ";
result += "n " + total_amount + "n";
result += " " + bonus_points + " "; return result;
}
return result;
} private function get_total_charge():Number
... {
} var rentals:Array = _rentals.concat();
var result:Number = 0;
while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_charge();
}
return result;
}
}
55. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat();
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
// result += "-" + the_rental.get_movie().get_title() + " "
bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n";
}
result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n";
total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " ";
}
return result;
result += "n " + total_amount + "n"; }
result += " " + bonus_points + " ";
private function get_total_bonus_points():int
return result; {
} var rentals:Array = _rentals.concat();
.. var result:int = 0;
} while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_bonus_points();
}
return result;
}
..
}
56. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat();
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
// result += "-" + the_rental.get_movie().get_title() + " "
bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n";
}
result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n";
total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " ";
}
return result;
result += "n " + total_amount + "n"; }
result += " " + bonus_points + " ";
private function get_total_bonus_points():int
return result; {
} var rentals:Array = _rentals.concat();
.. var result:int = 0;
} while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_bonus_points();
}
return result;
}
..
}
57. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat();
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
// result += "-" + the_rental.get_movie().get_title() + " "
bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n";
}
result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n";
total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " ";
}
return result;
result += "n " + total_amount + "n"; }
result += " " + bonus_points + " ";
private function get_total_bonus_points():int
return result; {
} var rentals:Array = _rentals.concat();
.. var result:int = 0;
} while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_bonus_points();
}
return result;
}
..
}
58. // Customer.as // Customer.as
public class Customer public class Customer
{ {
.. ..
public function checkout ():String public function checkout ():String
{ {
var total_amount:Number = 0;// var total_amount:Number = 0;//
var bonus_points:int = 0;// var bonus_points:int = 0;//
var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat();
var result:String = get_name() +" n"; var result:String = get_name() +" n";
while (rentals.length > 0) while (rentals.length > 0)
{ {
var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental;
// result += "-" + the_rental.get_movie().get_title() + " "
bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n";
}
result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n";
total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " ";
}
return result;
result += "n " + total_amount + "n"; }
result += " " + bonus_points + " ";
private function get_total_bonus_points():int
return result; {
} var rentals:Array = _rentals.concat();
.. var result:int = 0;
} while (rentals.length > 0)
{
var the_rental:Rental = rentals.shift() as Rental;
result += the_rental.get_bonus_points();
}
return result;
}
..
}
60. // Rental.as // Rental.as
public class Rental public class Rental
{ {
... public function get_charge():Number
public function get_charge():Number {
{ return _movie.get_charge(_days_rented);
var result:int = 0; }
switch (get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Movie.as
result += 2; public class Movie
if (get_days_rented() > 2) {
{ public function get_charge(days_rented:int):Number
result += (get_days_rented() - 2) * 1.5; {
} var result:int = 0;
break; switch (get_price_code())
{
case Movie.NEW_RELEASE :// case Movie.REGULAR ://
result += get_days_rented() * 3; result += 2;
break; if (days_rented > 2)
{
case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5;
result += 1.5; }
if (get_days_rented() > 3) break;
{
result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE ://
} result += days_rented * 3;
break; break;
}
case Movie.CHILDRENS ://
return result; result += 1.5;
} if (days_rented > 3)
.. {
} result += (days_rented - 3) * 1.5;
}
break;
}
return result;
}
}
61. // Rental.as // Rental.as
public class Rental public class Rental
{ {
... public function get_charge():Number
public function get_charge():Number {
{ return _movie.get_charge(_days_rented);
var result:int = 0; }
switch (get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Movie.as
result += 2; public class Movie
if (get_days_rented() > 2) {
{ public function get_charge(days_rented:int):Number
result += (get_days_rented() - 2) * 1.5; {
} var result:int = 0;
break; switch (get_price_code())
{
case Movie.NEW_RELEASE :// case Movie.REGULAR ://
result += get_days_rented() * 3; result += 2;
break; if (days_rented > 2)
{
case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5;
result += 1.5; }
if (get_days_rented() > 3) break;
{
result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE ://
} result += days_rented * 3;
break; break;
}
case Movie.CHILDRENS ://
return result; result += 1.5;
} if (days_rented > 3)
.. {
} result += (days_rented - 3) * 1.5;
}
break;
}
return result;
}
}
62. // Rental.as // Rental.as
public class Rental public class Rental
{ {
... public function get_charge():Number
public function get_charge():Number {
{ return _movie.get_charge(_days_rented);
var result:int = 0; }
switch (get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Movie.as
result += 2; public class Movie
if (get_days_rented() > 2) {
{ public function get_charge(days_rented:int):Number
result += (get_days_rented() - 2) * 1.5; {
} var result:int = 0;
break; switch (get_price_code())
{
case Movie.NEW_RELEASE :// case Movie.REGULAR ://
result += get_days_rented() * 3; result += 2;
break; if (days_rented > 2)
{
case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5;
result += 1.5; }
if (get_days_rented() > 3) break;
{
result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE ://
} result += days_rented * 3;
break; break;
}
case Movie.CHILDRENS ://
return result; result += 1.5;
} if (days_rented > 3)
.. {
} result += (days_rented - 3) * 1.5;
}
break;
}
return result;
}
}
63. // Rental.as // Rental.as
public class Rental public class Rental
{ {
... public function get_charge():Number
public function get_charge():Number {
{ return _movie.get_charge(_days_rented);
var result:int = 0; }
switch (get_movie().get_price_code()) }
{
case Movie.REGULAR :// // Movie.as
result += 2; public class Movie
if (get_days_rented() > 2) {
{ public function get_charge(days_rented:int):Number
result += (get_days_rented() - 2) * 1.5; {
} var result:int = 0;
break; switch (get_price_code())
{
case Movie.NEW_RELEASE :// case Movie.REGULAR ://
result += get_days_rented() * 3; result += 2;
break; if (days_rented > 2)
{
case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5;
result += 1.5; }
if (get_days_rented() > 3) break;
{
result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE ://
} result += days_rented * 3;
break; break;
}
case Movie.CHILDRENS ://
return result; result += 1.5;
} if (days_rented > 3)
.. {
} result += (days_rented - 3) * 1.5;
}
break;
}
return result;
}
}
64. // Rental.as // Rental.as
public class Rental public class Rental
{ {
... ..
public function get_bonus_points():int public function get_charge():Number
{ {
// 2 1 return _movie.get_bonus_points(_days_rented);
if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && }
(get_days_rented() > 1)) ..
{ }
return 2;
} // Movie.as
else public class Movie
{ {
return 1; ..
} public function get_bonus_points(days_rented:int):int
} {
.. // 2 1
} if ((get_price_code() == Movie.NEW_RELEASE) && (days_rented
> 1))
{
return 2;
}
else
{
return 1;
}
}
..
}