Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package trainstation;
  2.  
  3.  
  4. public class TrainTrip {
  5. String tripId;
  6. String destination;
  7. int numSeats;
  8. int seats[];
  9. float ticketPrice;
  10. TrainTrip()
  11. {
  12. tripId = "";
  13. destination ="";
  14. numSeats = 0;
  15. ticketPrice = 0;
  16.  
  17. }
  18. TrainTrip(String destination, String tripId, int numSeats, float ticketPrice)
  19. {
  20. this.destination = destination;
  21. this.tripId = tripId;
  22. this.numSeats = numSeats;
  23. this.ticketPrice = ticketPrice;
  24. int seats[] = new int [numSeats];
  25. }
  26. public int bookTicket()
  27. {
  28. for(int i =0; i< numSeats; i++)
  29. {
  30. if(seats[i] == 0)
  31. {
  32. seats[i] = 1;
  33. return i;
  34. }
  35.  
  36. }
  37. return -1;
  38.  
  39. }
  40. public void cancelTicket(int seatNum)
  41. {
  42. seats[seatNum] = 0;
  43. System.out.println("Please take your money!");
  44. }
  45.  
  46. @Override
  47. public String toString()
  48. {
  49. int NoSeats=0;
  50. System.out.println("The Destination is: "+destination);
  51. System.out.println("Total number of seats are: "+numSeats);
  52. for(int i =0; i< numSeats; i++)
  53. {
  54. if(seats[i] == 0)
  55. {
  56. NoSeats++;
  57. }
  58. }
  59. System.out.println("Number of Seats Booked are: "+NoSeats);
  60. return "";
  61. }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement