d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Not Sure What This Does?
Add Reply New Topic New Poll
Member
Posts: 34,549
Joined: Mar 25 2009
Gold: 12,633.00
Jun 9 2019 11:22pm
Code

public Theatre(String theatreName, int numRows, int seatsPerRow) {
this.theatreName = theatreName;

int lastRow = 'A' + (numRows -1);
for (char row = 'A'; row <= lastRow; row++) {
for(int seatNum = 1; seatNum <= seatsPerRow; seatNum++) {
Seat seat = new Seat(row + String.format(%02d, seatNum));
seats.add(seat);
}
}
}




In particular, this part:

int lastRow = 'A' + (numRows -1);






Member
Posts: 11,273
Joined: Apr 26 2008
Gold: 3,303.50
Jun 10 2019 03:36am
If you google for ascii table you will understand that piece of code better.
'A' has the code 65 and you can add 1 for instance to get 'B'.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll