Schamppu

Matka

May 8th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package lippuvaraamo;
  7.  
  8. import java.util.ArrayList;
  9.  
  10. public class Matka {
  11.    
  12.     private String lahto;
  13.     private String meno;
  14.     private int paikkoja;
  15.     private int index;
  16.     private ArrayList<String> varatut = new ArrayList<>();
  17.    
  18.     public Matka(String lahto, String meno, int paikkoja, int indeksi) {
  19.         this.lahto = lahto;
  20.         this.meno = meno;
  21.         this.paikkoja = paikkoja;
  22.         this.index = indeksi;
  23.     }
  24.    
  25.     public int getID() {
  26.         return this.index;
  27.     }
  28.    
  29.     public void lisaaMatka(String sposti) {
  30.         if (this.paikkoja > 0) {
  31.             varatut.add(sposti);
  32.             this.paikkoja --;
  33.         }
  34.     }
  35.    
  36.     public void tulostaLiput() {
  37.        
  38.         for (String sposti: varatut) {
  39.             System.out.println(sposti);
  40.         }
  41.        
  42.     }
  43.    
  44.    
  45.     @Override
  46.     public String toString() {
  47.         return this.index+": "+this.lahto+"-"+this.meno+", paikkoja jäljellä "+this.paikkoja;
  48.     }
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment