nafis nibir 6 years ago
parent
commit
38cde5b744
2 changed files with 22 additions and 9 deletions
  1. 21
    9
      MainApplication.java
  2. 1
    0
      Pet.java

+ 21
- 9
MainApplication.java View File

3
 import java.util.Arrays;
3
 import java.util.Arrays;
4
 public class MainApplication {
4
 public class MainApplication {
5
     
5
     
6
+    private Pet pet;
7
+    private Pet[] petList;
6
     
8
     
9
+    public MainApplication(){
10
+        pet = new Pet();
11
+    }
12
+   
7
     public static void main(String[] args){
13
     public static void main(String[] args){
14
+              
15
+    }  
16
+    
17
+    public void process(){
8
         int pets;
18
         int pets;
9
         System.out.println("How many pets do you have?");
19
         System.out.println("How many pets do you have?");
10
         pets = getNumberPets();
20
         pets = getNumberPets();
14
             System.out.println("These are all your pets: ");
24
             System.out.println("These are all your pets: ");
15
             System.out.println(Arrays.toString(listOfPets));
25
             System.out.println(Arrays.toString(listOfPets));
16
         }
26
         }
27
+    }
28
+    
17
 
29
 
18
-    }    
19
-
20
-    public static int getNumberPets(){
30
+    public int getNumberPets(){
21
         int numberPets = 0;
31
         int numberPets = 0;
22
         Scanner input = new Scanner(System.in);
32
         Scanner input = new Scanner(System.in);
23
         boolean error = true;
33
         boolean error = true;
29
                 input.next();
39
                 input.next();
30
                 System.out.println("Error! Please type a number");
40
                 System.out.println("Error! Please type a number");
31
             } 
41
             } 
32
-        } while (error); 
33
-        return numberPets;
42
+        } while (error);
43
+        
44
+        pet.setPetNums(numberPets);
45
+        return pet.getPetNums();
34
     }
46
     }
35
 
47
 
36
-    public static String setPetName(){
48
+    public  String setPetName(){
37
         Scanner input = new Scanner(System.in);
49
         Scanner input = new Scanner(System.in);
38
         String petName = input.nextLine();
50
         String petName = input.nextLine();
39
         return petName;
51
         return petName;
40
     }
52
     }
41
 
53
 
42
-    public static String[] makePetList(int numberOfPets){        
43
-        String[] petList = new String[numberOfPets];       
54
+    public  Pet[] makePetList(int numberOfPets){        
55
+        petList = new Pet[numberOfPets];       
44
         for (int i = 0; i < petList.length; i++){
56
         for (int i = 0; i < petList.length; i++){
45
             System.out.println("What is the name of pet number " + (i+1) + "?");
57
             System.out.println("What is the name of pet number " + (i+1) + "?");
46
-            petList[i] = setPetName();
58
+            petList[i] = pet.setName(setPetName());
47
         }
59
         }
48
 
60
 
49
         return petList;
61
         return petList;

+ 1
- 0
Pet.java View File

11
     public Pet(){
11
     public Pet(){
12
 
12
 
13
     }
13
     }
14
+    
14
 
15
 
15
     public void setName(String petName){
16
     public void setName(String petName){
16
         name = petName;
17
         name = petName;