Practice Midterm Exam Part A: 1. b 2. c 3. d 4. d 5. d 6. b 7. a 8. a 9. d 10. b Part B: String name = fields[0]; char gender = fields[1].charAt(0); String city = fields[2]; int salary = Integer.parseInt(fields[3]); if (gender == 'F' && city.equals("Chicago") { count++; sum += salary; } Part C: Corrected source code files: //------- Source code file: Pet.java package it313.finalexam.petsalon; public class Pet { private String _name; private String _owner; private int _age; public Pet(String theName, String theOwner, int theAge) { _name = theName; _owner = theOwner; _age = theAge; } public String getName( ) { return _name; } public String getOwner( ) { return _owner; } public int getAge( ) { return _age; } @Override public String toString( ) { return String.format("%s %s %d", _name, _owner, _age); } } //------- Source code file: Dog.java package it313.finalexam.petsalon; public class Dog extends Pet { private String _breed; public Dog(String theName, String theOwner, int theAge, String theBreed) { super(theName, theOwner, theAge); _breed = theBreed; } public String getBreed() { return _breed; } @Override public String toString( ) { return super.toString( ) + String.format(" %s", _breed); } } //------- Source code file: Test.java import java.util.ArrayList; import it313.finalexam.petsalon.Dog; public class Test { public static void main(String[ ] args) { ArrayList col = new ArrayList( ); col.add(new Dog("Vini", "Jack", 2, "Pomeranian")); col.add(new Dog("Klaus", "Nancy", 4, "German Shephard")); col.add(new Dog("Sparky", "Steve", 1, "Dachshund")); for(Dog d : col) { System.out.println(d); } System.out.println( ); System.out.println(col.get(2).toString( )); } } Part D: push pop peek empty search === Traditional tests ======================== import java.util.Stack; public class Test1 { public static void main(String[] args) { Stack s = new Stack( ); s.push("S"); s.push("T"); System.out.println(s.search("T")); System.out.println(s.pop( )); System.out.println(s.isEmpty( )); System.out.println(s.peek( )); System.out.println(s.isEmpty( )); System.out.println(s.pop( )); System.out.println(s.isEmpty( )); } } // Output: 1 T false S false S true === Junit tests ============================== import static org.junit.jupiter.api.Assertions.*; import java.util.Stack; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class Test2 { private Stack s; @BeforeEach void setUp() { s = new Stack( ); } @Test void test() { s.push("S"); s.push("T"); assertEquals(s.search("T"), 1); assertEquals(s.pop( ), "T"); assertEquals(s.isEmpty( ), false); assertEquals(s.peek( ), "S"); assertEquals(s.isEmpty( ), false); assertEquals(s.pop( ), "S"); assertEquals(s.isEmpty( ), true); } }