akosiraff

Grade Book JAVA

May 26th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/grade-book-java/
  3. Ex 7.10 (To modify Gradebook class in Fig 7.4)
  4. a) Include a String instance variable that represents the name of the course’s instructor.
  5. b) Provide a set method to change the instructor’s name and get a method to retrieve it.
  6. c) Modify the constructor to specify two parameters-one for the course name and one for the instructor’s name.
  7. d) Modify method displayMessage to output the welcome message and course name, followed by “This course is presented by: “ and the instructor’s name.
  8. Use your modified class in a test application that demonstrates the class’s new capabilities.
  9. This Java program uses existing class in example Fig 7.4. So you may first copy it to your Textpad and work on it by adding your new Java code and logic. You may copy an existing Java program example like Fig 7.4 below:
  10. Sample Java Code can be used for your program from Fig 7.4
  11. // Fig. 7.4: GradeBook.java
  12. // Class declaration with a method that has a parameter.
  13. public class GradeBook
  14. {
  15. // display a welcome message to the GradeBook user
  16. public void displayMessage( String courseName )
  17. {
  18. System.out.printf( “Welcome to the grade book for\n%s!\n”,
  19. courseName );
  20. } // end method displayMessage
  21. } // end class GradeBook
  22. This example is a foundation to your own solution of your individual Ex 7.10, but you need add new logic into it. In your new class you need to:
  23. 1. To add a new string instance variable for course instructor by changing
  24. public void displayMessage( String courseName )
  25. to
  26. public void displayMessage( String courseName, String courseInstructor )
  27. 2. To provide two new methods – get and set like set and get courseName in Fig 7.4 on page 309. An example is below
  28. 1) isPrime (to determine whether or not current number you are checking is a prime number or not.)
  29. // method to set the instructor name
  30. public void setInstructorName( String name )
  31. {
  32. instructorName = name; // store the instructor name
  33. } // end method setInstructorName
  34. 3. Modify constructor to specify two variables to include new variable courseInstructor.
  35. public GradeBook( String course, String instructor )
  36. {
  37. courseName = course; // initializes courseName
  38. instructorName = instructor; // initializes instructorName
  39. } // end constructor
  40. 4. Modify display message to include the new variable courseInstructor.
  41. public void displayMessage( String courseName )
  42. {
  43. System.out.printf( “Welcome to the grade book for\n%s!\n”,
  44. courseName );
  45. } // end method displayMessage
  46. you may create another method to display instructor name in the same way by modifying Java code above. Then you will be able to display instructor name in instructorName:
  47. public void displayInstructorMessage( String instructorName )
  48. {
  49. System.out.printf( “Welcome to the grade book for Instructor \n%s!\n”,
  50. instructorName );
  51. } // end method displayMessage
  52. 5. In main method certain changes or new additional logic are necessary to include new variable courseInstructor
  53. // Fig. 7.5: GradeBookTest.java
  54. // Create GradeBook object and pass a String to
  55. // its displayMessage method.
  56. import java.util.Scanner; // program uses Scanner
  57. public class GradeBookTest
  58. {
  59. // main method begins program execution
  60. public static void main( String[] args )
  61. {
  62. // create Scanner to obtain input from command window
  63. Scanner input = new Scanner( System.in );
  64. // create a GradeBook object and assign it to myGradeBook
  65. GradeBook myGradeBook = new GradeBook();
  66. // prompt for and input course name
  67. System.out.println( “Please enter the course name:” );
  68. String courseName = input.nextLine(); // read a line of text
  69. System.out.println(); // outputs a blank line
  70. // call myGradeBook’s displayMessage method
  71. // and pass courseName as an argument
  72. myGradeBook.displayMessage( courseName );
  73. } // end main
  74.  
  75. Download: http://solutionzip.com/downloads/grade-book-java/
Advertisement
Add Comment
Please, Sign In to add comment