fork download
  1. import java.util.*;
  2. import javax.swing.*;
  3. public class hundRegister {
  4. private Scanner keyboard = new Scanner(System.in);
  5. private static void installStartDogs(ArrayList<Dog> allDogs){
  6. String name = "Fido";
  7. String race = "Pudel";
  8. int age = 4;
  9. int weight = 22;
  10. Dog d = new Dog(name, race, age, weight);
  11. insertDogInSystem(d, allDogs);
  12. name = "Pluto";
  13. race = "Blodhund";
  14. age = 12;
  15. weight = 100;
  16. d = new Dog(name, race, age, weight);
  17. insertDogInSystem(d, allDogs);
  18. name = "Trixie";
  19. race = "Golden Retriver";
  20. age = 5;
  21. weight = 60;
  22. d = new Dog(name, race, age, weight);
  23. insertDogInSystem(d, allDogs);
  24. name = "Jocki";
  25. race = "Chiuaua";
  26. age = 20;
  27. weight = 30;
  28. d = new Dog(name, race, age, weight);
  29. insertDogInSystem(d, allDogs);
  30. name = "Felix";
  31. race = "Rottweiler";
  32. age = 3;
  33. weight = 260;
  34. d = new Dog(name, race, age, weight);
  35. insertDogInSystem(d, allDogs);
  36. name = "Fluffy";
  37. race = "Tax";
  38. age = 1;
  39. weight = 10;
  40. d = new Dog(name, race, age, weight);
  41. insertDogInSystem(d, allDogs);
  42. }
  43. private static ArrayList<Dog> createArrayList(){
  44. ArrayList<Dog> arrayList = new ArrayList<Dog>();
  45. return arrayList;
  46. }
  47. private static void insertDogInSystem(Dog dog, ArrayList<Dog> allDogs){
  48. allDogs.add(dog);
  49. }
  50. public static void showStartMenu(ArrayList<Dog> allDogs){
  51. int userInput = 0;
  52. do{
  53. String userInputString = JOptionPane.showInputDialog(null, "1. Registerera hund \n2. Lista hundar \n3. Ta bort Hundar \n4. Avsluta");
  54. if(userInputString != null){
  55. userInput = Integer.parseInt(userInputString);
  56. }
  57. }while(userInput < 0 || userInput > 4);
  58. selectMenuInput(userInput, allDogs);
  59. }
  60. private static void selectMenuInput(int userInput, ArrayList<Dog> allDogs){
  61. switch(userInput){
  62. case 1:
  63. showRegisterMenu(allDogs);
  64. break;
  65. case 2:
  66. showListMenu(allDogs);
  67. break;
  68. case 3:
  69. showDeleteMenu(allDogs);
  70. break;
  71. case 4:
  72. break;
  73. case 0:
  74. break;
  75. default:
  76. break;
  77. }
  78. }
  79. private static void showRegisterMenu(ArrayList<Dog> allDogs){
  80. String userNameInput = JOptionPane.showInputDialog(null, "Ange hundens namn:");
  81. String userRaceInput = JOptionPane.showInputDialog(null, "Ange hundens ras:");
  82. int userAgeInput = Integer.parseInt(JOptionPane.showInputDialog(null, "Ange hundens Œlder: (Œr)"));
  83. int userWeightInput = Integer.parseInt(JOptionPane.showInputDialog(null, "Ange hundens vikt: (kg)"));
  84. Dog dog = new Dog(userNameInput, userRaceInput, userAgeInput, userWeightInput);
  85. insertDogInSystem(dog, allDogs);
  86. JOptionPane.showMessageDialog(null, "Hunden finns nu i systemet");
  87. showStartMenu(allDogs);
  88. }
  89. private static void showListMenu(ArrayList<Dog> allDogs){
  90. Double userTailInput = Double.parseDouble(JOptionPane.showInputDialog(null, "Ange en svanslŠngd: (cm)"));
  91. printDogsBasedOnTailLength(allDogs, userTailInput);
  92. showStartMenu(allDogs);
  93. }
  94. private static void showDeleteMenu(ArrayList<Dog> allDogs){
  95. String userNameInput = JOptionPane.showInputDialog(null, "Ange namnet pΠhunden du vill ta bort: ");
  96. if(userNameInput != null){
  97. boolean removed = false;
  98. int deleteid = 0;
  99. for(Dog d : allDogs){
  100. if(d.getName().equalsIgnoreCase(userNameInput)){
  101. deleteid = allDogs.indexOf(d);
  102. removed = true;
  103. }
  104. }
  105. if(removed){
  106. deleteDog(allDogs, deleteid);
  107. JOptionPane.showMessageDialog(null, userNameInput + " Šr nu borttagen ur systemet.");
  108. }else{
  109. JOptionPane.showMessageDialog(null, "Ingen hund med det namnet kunde hittas.");
  110. }
  111. }
  112. showStartMenu(allDogs);
  113. }
  114. public static void deleteDog(ArrayList<Dog> allDogs, int deleteid){
  115. allDogs.remove(deleteid);
  116. }
  117. public static void printDogsBasedOnTailLength(ArrayList<Dog> allDogs, double userTailInput){
  118. String list = "Dessa hundar hittades:";
  119. boolean found = false;
  120. for(Dog d : allDogs){
  121. Double dTail = d.getTailLength();
  122. if(dTail >= userTailInput){
  123. list += "\n " + d.toString();
  124. found = true;
  125. }
  126. }
  127. if(!found){
  128. list += "\n Inga hundar hittades";
  129. }
  130. JOptionPane.showMessageDialog(null, list);
  131. showStartMenu(allDogs);
  132. }
  133. public static void main(String[] args){
  134. ArrayList<Dog> allDogs = createArrayList();
  135. installStartDogs(allDogs);
  136. showStartMenu(allDogs);
  137. }
  138. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
public class Dog {
private String name;
private String race;
private int age;
private int weight;
private double tailLength;

public Dog(String name, String race, int age, int weight){
this.name = name;
this.race = race;
this.age = age;
this.weight = weight;
setTailLength(race, age, weight);
}
private void setTailLength(String race, int age, int weight){
if(race.equalsIgnoreCase("Tax")){
this.tailLength = 3.7;
}else{
this.tailLength = (age * weight) / 10.0;
}
}
public void setName(String newName){
name = newName;
}
public String getName(){
return name;
}
public String getRace(){
return race;
}
public int getAge(){
return age;
}
public int getWeight(){
return weight;
}
public double getTailLength(){
return tailLength;
}
public String toString(){
return "Namn: " + name + " Ras: " + race + " �lder: " + age + " Vikt: " + weight + " SvanslŠngd: " + getTailLength();
}
}
compilation info
Main.java:3: error: class hundRegister is public, should be declared in a file named hundRegister.java
public class hundRegister {
       ^
Main.java:5: error: cannot find symbol
private static void installStartDogs(ArrayList<Dog> allDogs){
                                               ^
  symbol:   class Dog
  location: class hundRegister
Main.java:43: error: cannot find symbol
private static ArrayList<Dog> createArrayList(){
                         ^
  symbol:   class Dog
  location: class hundRegister
Main.java:47: error: cannot find symbol
private static void insertDogInSystem(Dog dog, ArrayList<Dog> allDogs){
                                      ^
  symbol:   class Dog
  location: class hundRegister
Main.java:47: error: cannot find symbol
private static void insertDogInSystem(Dog dog, ArrayList<Dog> allDogs){
                                                         ^
  symbol:   class Dog
  location: class hundRegister
Main.java:50: error: cannot find symbol
public static void showStartMenu(ArrayList<Dog> allDogs){
                                           ^
  symbol:   class Dog
  location: class hundRegister
Main.java:60: error: cannot find symbol
private static void selectMenuInput(int userInput, ArrayList<Dog> allDogs){
                                                             ^
  symbol:   class Dog
  location: class hundRegister
Main.java:79: error: cannot find symbol
private static void showRegisterMenu(ArrayList<Dog> allDogs){
                                               ^
  symbol:   class Dog
  location: class hundRegister
Main.java:89: error: cannot find symbol
private static void showListMenu(ArrayList<Dog> allDogs){
                                           ^
  symbol:   class Dog
  location: class hundRegister
Main.java:94: error: cannot find symbol
private static void showDeleteMenu(ArrayList<Dog> allDogs){
                                             ^
  symbol:   class Dog
  location: class hundRegister
Main.java:114: error: cannot find symbol
public static void deleteDog(ArrayList<Dog> allDogs, int deleteid){
                                       ^
  symbol:   class Dog
  location: class hundRegister
Main.java:117: error: cannot find symbol
public static void printDogsBasedOnTailLength(ArrayList<Dog> allDogs, double userTailInput){
                                                        ^
  symbol:   class Dog
  location: class hundRegister
Main.java:10: error: cannot find symbol
Dog d = new Dog(name, race, age, weight);
^
  symbol:   class Dog
  location: class hundRegister
Main.java:10: error: cannot find symbol
Dog d = new Dog(name, race, age, weight);
            ^
  symbol:   class Dog
  location: class hundRegister
Main.java:16: error: cannot find symbol
d = new Dog(name, race, age, weight);
        ^
  symbol:   class Dog
  location: class hundRegister
Main.java:22: error: cannot find symbol
d = new Dog(name, race, age, weight);
        ^
  symbol:   class Dog
  location: class hundRegister
Main.java:28: error: cannot find symbol
d = new Dog(name, race, age, weight);
        ^
  symbol:   class Dog
  location: class hundRegister
Main.java:34: error: cannot find symbol
d = new Dog(name, race, age, weight);
        ^
  symbol:   class Dog
  location: class hundRegister
Main.java:40: error: cannot find symbol
d = new Dog(name, race, age, weight);
        ^
  symbol:   class Dog
  location: class hundRegister
Main.java:44: error: cannot find symbol
ArrayList<Dog> arrayList = new ArrayList<Dog>();
          ^
  symbol:   class Dog
  location: class hundRegister
Main.java:44: error: cannot find symbol
ArrayList<Dog> arrayList = new ArrayList<Dog>();
                                         ^
  symbol:   class Dog
  location: class hundRegister
Main.java:84: error: cannot find symbol
Dog dog = new Dog(userNameInput, userRaceInput, userAgeInput, userWeightInput);
^
  symbol:   class Dog
  location: class hundRegister
Main.java:84: error: cannot find symbol
Dog dog = new Dog(userNameInput, userRaceInput, userAgeInput, userWeightInput);
              ^
  symbol:   class Dog
  location: class hundRegister
Main.java:99: error: cannot find symbol
for(Dog d : allDogs){
    ^
  symbol:   class Dog
  location: class hundRegister
Main.java:120: error: cannot find symbol
for(Dog d : allDogs){
    ^
  symbol:   class Dog
  location: class hundRegister
Main.java:134: error: cannot find symbol
ArrayList<Dog> allDogs = createArrayList();
          ^
  symbol:   class Dog
  location: class hundRegister
26 errors
stdout
Standard output is empty