Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Xbox Lve Generator v3
Better way to get content via jQuery $.get()
Free CarTown Blue Points Generator and CarTown Templates
Steam Wallet Hack 2012
Diablo 3 error 37 & error 3006 fix
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
PAYPAL REMOVE ACCESS LIMITED ACCOUNT 100% Working
Pastable version of
Firts time refactoring
<pre class='prettyprint' language='cs'>using System; using System.Collections.Generic; using System.Text; namespace Assignment1MH_Base { class Customer { public const int NonMember = 0; public const int Bronze = 1; public const int Silver = 2; public const int Gold = 3; private int memberType; private String lastName; private String firstName; private String creditNumber; private String creditType; private String expiry; public Customer(int memberType, String lastName, String firstName, String creditNumber, String creditType, String expiry) { this.memberType = memberType; this.lastName = lastName; this.firstName = firstName; this.creditNumber = creditNumber; this.creditType = creditType; this.expiry = expiry; } public Customer(String lastName, String firstName, String creditNumber, String creditType, String expiry) { this.lastName = lastName; this.firstName = firstName; this.creditNumber = creditNumber; this.creditType = creditType; this.expiry = expiry; } public String getCreditNumber() { return creditNumber; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public String getCreditType() { return creditType; } public String getExpiry() { return expiry; } public int getMemberType() { return memberType; } public void setCreditNumber(String creditNumber) { this.creditNumber = creditNumber; } public void setCreditType(String creditType) { this.creditType = creditType; } public void setLastName(String lastName) { this.lastName = lastName; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setExpiry(String expiry) { this.expiry = expiry; } public void setMemberType(int memberType) { this.memberType = memberType; } } } ------------------------------------------ using System; using System.Collections.Generic; using System.Collections; using System.Text; namespace Assignment1MH_Base { class Happening { private Hashtable custBooks = new Hashtable(); private const double StallCharge = 37.25; private const double DressCircleCharge = 48.80; private const double BalconyCharge = 89.00; private const double BronzeDiscount = 0.90; private const double SilverDiscount = 0.80; private const double GoldDiscount = 0.75; private Theatre theTheatre; public Happening(Theatre theTheatre) { this.theTheatre = theTheatre; } public Boolean bookSeats(int priceCode, int number, Customer theCust) { if (priceCode == Row.Stalls) { ArrayList theStalls = theTheatre.getStalls(); IEnumerator theEnum = theStalls.GetEnumerator(); while (theEnum.MoveNext()) { Row theRow = (Row)theEnum.Current; if (theRow.bookSeats(number)) { Receipt newBooking = new Receipt(priceCode, theCust, theStalls.IndexOf(theRow) + 1, theRow.getLastBooked(), number); custBooks.Add(theCust, newBooking); return true; } } return false; } else if (priceCode == Row.DressCircle) { ArrayList theDC = theTheatre.getDressCircle(); IEnumerator theEnum = theDC.GetEnumerator(); while (theEnum.MoveNext()) { Row theRow = (Row)theEnum.Current; if (theRow.bookSeats(number)) { Receipt newBooking = new Receipt(priceCode, theCust, theDC.IndexOf(theRow) + 1, theRow.getLastBooked(), number); custBooks.Add(theCust, newBooking); return true; } } return false; } else if (priceCode == Row.Balcony) { ArrayList theBalcony = theTheatre.getBalcony(); IEnumerator theEnum = theBalcony.GetEnumerator(); while (theEnum.MoveNext()) { Row theRow = (Row)theEnum.Current; if (theRow.bookSeats(number)) { Receipt newBooking = new Receipt(priceCode, theCust, theBalcony.IndexOf(theRow) + 1, theRow.getLastBooked(), number); custBooks.Add(theCust, newBooking); return true; } } return false; } return false; } public double getCharge(Customer theCust) { Receipt theBooking = (Receipt)custBooks[theCust]; double theCharge = theTheatre.getDiscount(theCust.getMemberType()) * theTheatre.getCharge(theBooking.getPriceCode()) * theBooking.getNumberOfSeats(); return theCharge; } public Receipt getCustomerBooking(Customer cust) { return (Receipt)custBooks[cust]; } } } ------------------------------------------------------------------------ using System; using System.Collections.Generic; using System.Text; namespace Assignment1MH_Base { class Receipt { private int priceCode; private int numberOfSeats; private Customer theCust; private int rowNum; private int startSeatNum; public String toString () { return "Price Code =" + priceCode + ", seats booked =" + numberOfSeats + ", sitting at row " + rowNum; } public Receipt(int priceCode, Customer theCust, int rowNum, int startSeatNum, int seatsBooked) { this.priceCode = priceCode; this.theCust = theCust; this.rowNum = rowNum; this.startSeatNum = startSeatNum; this.numberOfSeats = seatsBooked; } public int getNumberOfSeats() { return numberOfSeats; } public int getPriceCode() { return priceCode; } public Customer getTheCust() { return theCust; } public int getStartSeatNum() { return startSeatNum; } public int getRowNum() { return rowNum; } public void setNumberOfSeats(int numberOfSeats) { this.numberOfSeats = numberOfSeats; } public void setPriceCode(int priceCode) { this.priceCode = priceCode; } public void setTheCust(Customer theCust) { this.theCust = theCust; } public void setRowNum(int rowNum) { this.rowNum = rowNum; } public void setStartSeatNum(int startSeatNum) { this.startSeatNum = startSeatNum; } } } ----------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; namespace Assignment1MH_Base { class Row { public const int Stalls = 0; public const int DressCircle = 1; public const int Balcony = 2; private const double StallCharge = 37.25; private const double DressCircleCharge = 48.80; private const double BalconyCharge = 89.00; private const double BronzeDiscount = 0.90; private const double SilverDiscount = 0.80; private const double GoldDiscount = 0.75; private int priceCode; private int numberAvailable; private int currentSeat; private int lastBooked; public Row(int numAvail, int code) { this.priceCode = code; this.numberAvailable = numAvail; currentSeat = 1; lastBooked = 1; } public Boolean bookSeats(int num) { if (numberAvailable >= num) { lastBooked = currentSeat; currentSeat += num; numberAvailable -= num; return true; } return false; } public int getPriceCode() { return priceCode; } public int getLastBooked () { return lastBooked; } public int getCurrentSeat() { return currentSeat; } } } ---------------------------------------------------------- using System; using System.Collections.Generic; using System.Collections; using System.Text; namespace Assignment1MH_Base { class Theatre { private const double StallCharge = 37.25; private const double DressCircleCharge = 48.80; private const double BalconyCharge = 89.00; private const double BronzeDiscount = 0.90; private const double SilverDiscount = 0.80; private const double GoldDiscount = 0.75; private ArrayList stalls = new ArrayList(); private ArrayList dressCircle = new ArrayList(); private ArrayList balcony = new ArrayList(); public double getDiscount(int memberCode) { if (memberCode == Customer.Bronze) return BronzeDiscount; if (memberCode == Customer.Silver) return SilverDiscount; if (memberCode == Customer.Gold) return GoldDiscount; return 1; } public double getCharge(int priceCode) { if (priceCode == Row.Stalls) return StallCharge; if (priceCode == Row.DressCircle) return DressCircleCharge; if (priceCode == Row.Balcony) return BalconyCharge; return -1; } public ArrayList getBalcony() { return balcony; } public ArrayList getDressCircle() { return dressCircle; } public ArrayList getStalls() { return stalls; } public void setStalls(ArrayList stalls) { this.stalls = stalls; } public void setBalcony(ArrayList balcony) { this.balcony = balcony; } public void setDressCircle(ArrayList dressCircle) { this.dressCircle = dressCircle; } } }</pre> <a href="http://www.refactormycode.com/codes/1282-firts-time-refactoring" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>