Question: I need this exercise 1, 2 , 3 and 4 all completed only in Java. Implementing and Testing Classes Exercise 1. Implement a class Address.

I need this exercise 1, 2 , 3 and 4 all completed only in Java.

 I need this exercise 1, 2 , 3 and 4 all

completed only in Java. Implementing and Testing Classes Exercise 1. Implement a

Implementing and Testing Classes Exercise 1. Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a ZIP code. Choose appropriate data types for the information and, for the sake of practice, keep each of those listed pieces as distinct instance variables (though reasonably for our purposes many of them could be combined into fewer). Supply two constructors: one with an apartment number and one without. Supply getter and setter methods for everything on the first address line: house number, street, and apartment number. addr . getApartmentNumber ( ) can return null if the address does not have an apartment number. Supply a public String toString( ) method that returns a String with the house \#, street, and apartment \# (if there is one) on one line and the city, state, and zip code on the next line, just like you'd write on an envelope or form. Do not print null if there is no apartment number. Supply a method public boolean comesBefore(Address other) that tests whether this address comes before another when the addresses are compared by postal code. Exercise 2. Write JUnit tests for these methods. In the future, we will ask you to write enough tests such that you demonstrate accuracy for the class's methods' behavior, but in this case you should practice by writing JUnit tests for all methods. Therefore, tests should include all of the following method calls, and you can group them as follows if you'd like: - Testing getters and setters - Constructor calls of each variation (no assertions) - Getters for instance variables - Setters for instance variables (no test assertions associated with them but...) - Getters again to make sure setters worked - Testing toString - Constructor calls of each variation (no tests) to String - Testing comesBefore - Constructor calls (no tests) - comesBefore for all different possible outcomes Exercise 3. Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an appropriate constructor and methods getName(), addQuiz(int score), getTotalScore(), and getAverageScore(). Notice that "total score" means the sum of scores across all quizzes. Assume at creation a student has taken no quizzes so their total score is 0 . Except, oops, to compute the average, you also need to store the number of quizzes that the student took. Being able to be flexible when requirements change in designing a system is important, because they will. Add an appropriate instance variable and getters for this. However, no setter should be provided - the number of quizzes taken should only change when they take a quiz. Exercise 4. Write JUnit tests for this class. We are trying to get you into the habit of recognizing how much testing is sufficient, so in the future we will not be so specific on how much testing we expect from you, but for this exercise we will give you the cues that you should thoroughly test these different categories. You need to decide what method calls go where and what assertions to use. - Basics: instantiating objects of Student, getters, adding quizzes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!