Guest User

Untitled

a guest
Dec 7th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class MainProgram
  5. {
  6.  
  7. public static void main(String[] args)
  8. {
  9. ArrayList<Dog> doglist = new ArrayList<Dog>();
  10. Scanner myscan = new Scanner(System.in);
  11. boolean running = true;
  12. while(running)
  13. {
  14. System.out.println("n************************************");
  15. System.out.println("nVälkommen till Kennelklubben!");
  16. System.out.println("n************************************");
  17. System.out.println("n[1] Register new dog");
  18. System.out.println("[2] Print out list");
  19. System.out.println("[3] Increase age");
  20. System.out.println("[4] Remove dog");
  21. System.out.println("[5] Quit program");
  22. System.out.println("n************************************");
  23. System.out.println("nChoose: ");
  24.  
  25. int option = myscan.nextInt();
  26.  
  27. switch (option)
  28. {
  29. case 1:
  30. System.out.println("Write name:");
  31. String name = myscan.next();
  32. System.out.println("Write race:");
  33. String race = myscan.next();
  34. System.out.println("Age:");
  35. int age = myscan.nextInt();
  36. System.out.println("Weight:");
  37. double weight = myscan.nextDouble();
  38.  
  39.  
  40. doglist.add(new Dog(name, race, age, weight));
  41.  
  42. break;
  43.  
  44.  
  45.  
  46.  
  47. case 2:
  48.  
  49. System.out.println("Write minimum length of tail:");
  50. double tail = myscan.nextDouble();
  51.  
  52. for (Dog name1 : doglist)
  53. {
  54. System.out.println(name1.toString());
  55.  
  56. }
  57.  
  58.  
  59.  
  60.  
  61. break;
  62.  
  63.  
  64.  
  65. public class Dog
  66. {
  67. private String name;
  68. private String race;
  69. private int age;
  70. private double weight;
  71. private double tailLength;
  72.  
  73. public Dog (String name, String race, int age, double weight)
  74. {
  75. this.name = name;
  76. this.race = race;
  77. this.age = age;
  78. this.weight = weight;
  79.  
  80. }
  81.  
  82.  
  83. public double tailLength()
  84. {
  85. if (race=="tax")
  86. tailLength = 3.7;
  87. else
  88. tailLength=(age-weight)/10;
  89.  
  90. return tailLength;
  91. }
  92.  
  93. public String toString()
  94. {
  95. return name + " " + race +
  96. " " + age + " " + "år" + " " + weight + " " + "kg" + " " + tailLength;
  97. }
Add Comment
Please, Sign In to add comment