Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lippuvaraamo;
- import java.util.ArrayList;
- public class Matka {
- private String lahto;
- private String meno;
- private int paikkoja;
- private int index;
- private ArrayList<String> varatut = new ArrayList<>();
- public Matka(String lahto, String meno, int paikkoja, int indeksi) {
- this.lahto = lahto;
- this.meno = meno;
- this.paikkoja = paikkoja;
- this.index = indeksi;
- }
- public int getID() {
- return this.index;
- }
- public void lisaaMatka(String sposti) {
- if (this.paikkoja > 0) {
- varatut.add(sposti);
- this.paikkoja --;
- }
- }
- public void tulostaLiput() {
- for (String sposti: varatut) {
- System.out.println(sposti);
- }
- }
- @Override
- public String toString() {
- return this.index+": "+this.lahto+"-"+this.meno+", paikkoja jäljellä "+this.paikkoja;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment