Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class Train{
  4.  
  5. private String name;
  6. private String fromPlace;
  7. private String toPlace;
  8. private int[] cars;
  9.  
  10. //Konstruktor
  11. public Train (String name, String fromPlace, String toPlace, int[] cars) {
  12. this.name = name;
  13. this.fromPlace = fromPlace;
  14. this.toPlace = toPlace;
  15. this.cars=cars;
  16. }
  17.  
  18.  
  19. //Konstruktor
  20. public Train (String name, String fromPlace) {
  21. this.name = name;
  22. this.fromPlace = fromPlace;
  23.  
  24. }
  25.  
  26.  
  27. public int getNumberOfSeats() {
  28. int sum=0;
  29. for(int i =0; i<this.cars.length;i++) {
  30. sum += this.cars[i];
  31. }
  32.  
  33. return sum;
  34. }
  35. public String getDeparture() {
  36. return this.fromPlace;
  37. }
  38. public String getDestination() {
  39. return this.toPlace;
  40. }
  41.  
  42.  
  43. public String toString() {
  44. return this.name + ": From " + this.fromPlace + ", To " + this.toPlace + ", Total seats: " + this.getNumberOfSeats()+ ", Reserved seats: " + 0;
  45. }
  46.  
  47. public boolean reserve (int travellers) {
  48. return false;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement