Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4.  
  5.  
  6.  
  7. ArrayList<TelevisioOhjelma> ohjelmat = new ArrayList<>();
  8. Scanner lukija = new Scanner(System.in);
  9.  
  10.  
  11.  
  12. while (true) {
  13.  
  14. System.out.println("Nimi:");
  15. String nimi = lukija.nextLine();
  16.  
  17. if (nimi.isEmpty()) {
  18. break;
  19. }
  20. System.out.println("Pituus:");
  21. int pituus = Integer.valueOf(lukija.nextLine());
  22.  
  23. ohjelmat.add(new TelevisioOhjelma(nimi, pituus));
  24. }
  25.  
  26. System.out.println("Ohjelman maksimipituus?");
  27. int maksimi = Integer.valueOf(lukija.nextLine());
  28.  
  29. for (TelevisioOhjelma TelevisioOhjelma: ohjelmat) {
  30. if (TelevisioOhjelma.getPituus() <= maksimi) {
  31. System.out.println(TelevisioOhjelma.toString());
  32. }
  33. }
  34.  
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement