Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Train{
- private String name;
- private String fromPlace;
- private String toPlace;
- private int[] cars;
- //Konstruktor
- public Train (String name, String fromPlace, String toPlace, int[] cars) {
- this.name = name;
- this.fromPlace = fromPlace;
- this.toPlace = toPlace;
- this.cars=cars;
- }
- //Konstruktor
- public Train (String name, String fromPlace) {
- this.name = name;
- this.fromPlace = fromPlace;
- }
- public int getNumberOfSeats() {
- int sum=0;
- for(int i =0; i<this.cars.length;i++) {
- sum += this.cars[i];
- }
- return sum;
- }
- public String getDeparture() {
- return this.fromPlace;
- }
- public String getDestination() {
- return this.toPlace;
- }
- public String toString() {
- return this.name + ": From " + this.fromPlace + ", To " + this.toPlace + ", Total seats: " + this.getNumberOfSeats()+ ", Reserved seats: " + 0;
- }
- public boolean reserve (int travellers) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement