Spring 2017 Exam 1
When finished, please send me the four java files for questions 1 and 2 along with a document containing the answers to questions 3-5. They may be sent in a zip or as individual files. And just FYI if I see lots of people turning in the same files or if I can google your answer and get an exact copy your grade will be bad.
#1 (35%): Per the UML diagram below, create a class called Person that has the following instance variables: firstName, lastName, and idSSN. All three are private Strings. Create set & get methods to allow access to these attributes, create a constructor that will fill in all values, and create a getFullName() method that will return the full name as “John Doe” and a toString method that will return the full name and the SSN.
Extend the Person class above with a class called Student. Student includes three additional attributes: school, gpa and totalHours as shown below. Create a constructor along with set and get methods for the Student class (make sure to validate the initial gpa and hours,i.e., they cannot be negative and the gpa cannot be above 4.0). In addition create a computeGpa method that updates the gpa and totalHours attributes with current semester data. Given the variable names in the diagram below (gpa & totalHours are the current overall count while hours and average are the arguments in the computeGpa method for the current semester), the formula to calculate a new overall gpa would be ((gpa * totalHours) + (average * hours)) / (totalHours + hours) Again remember to validate the hours and average arguments before updating. If the class attributes were updated, return TRUE; if not, return FALSE. Also, create a toString method that overrides the toString method in the parent class. This method should return the full name. SSN, school, gpa and totalHours (neatly formatted :).
Write a test application named StudentTest that demonstrates the Student class capabilities. Create an array of two Student objects, initialize each slot in the array appropriately, and attempt to update the gpa of each. Setup the students and the gpa updates so that one will go through and one will fail. Before the update, use the Student toString method to print information to System.out. After the update, print the same information to System.out along with whether the update went through or not.
#2 (10%) Write me a very simple servlet. All I want is for the servlet doGet method to print Hello DrJohn back to the browser. Send me only the single java file.
#3 (10%) What are the Model, the View, and the Controller and how are they implemented in Struts?
#4 (10%) What is the purpose of the web.xml and struts-config.xml files in a java web application?
#5 (10%) How would you implement language translations (i18n) or generic headers in struts?