CIS 182 – Java Programming
Assignment 04
Each program must include the following as comments at the beginning of your classes.
name
student number
assignment information
program documentation
Write (modify) the following 2 programs. When you have completed the programs, attach the Java source files ( GradeBook.java, GradeBookTest.java, Invoice.java, InvoiceTest.java ) in TalonNet to assignment A04.
Program 1 - GradeBook class modifications
Modify class GradeBook ( Fig 3.10 ) as follows: Here is a link to the source code for Figure 3-10 --> Figure_3.10 zip file
Include a second String instance variable (field) that represents the name of the instructor for the course.
Provide a set method to change the instructor's name and a get method to retrieve it.
Modify the constructor to specify two parameters - one for the course name and one for the course instructor.
Modify method displayMessage such that it first outputs the welcome message and course name, then outputs "This course is presented by: " followed by the instructor's name.
Modify the GradeBookTest class to demonstrate the use of ALL the methods in the class.
Program 2 - Invoice class
Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables (fields) - a part number (type String), a part description (type String), a quantity of the item being purchased (type int), and a price for the item (type double).
Your class should have a constructor that initializes the four instance variables. Provide set and a get methods for each instance variable. In addition, provide a method named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value.
Write a test application named InvoiceTest to demonstrate the use of ALL the methods in the class.
Instruction: Here is my code
public
class GradeBook
{
private String professorSurname;
private String courseName;
public GradeBook( String name )
{
courseName = name;
professorSurname = surname;
}
public void setCourseName( String name )
{
courseName = name;
}
public void setProfessorSurname ( String surname )
{
professorSurname = surname;
}
public String getCourseName()
{
return courseName;
}
public String getProfessorSurname()
{
return professorSurname;
}
public void displayMessage()
{
System.out.printf( "Welcome to the grade book for\n%s!\n",
getCourseName() );
}
}
/************************************************** ************************
* (C) Copyright 1992-2007 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
************************************************** ***********************/
public
class GradeBookTest
{
public static void main( String args[] )
{
GradeBook gradeBook1 = new GradeBook(
"CS101 Introduction to Java Programming" );
GradeBook gradeBook2 = new GradeBook(
"CS102 Data Structures in Java" );
System.out.printf( "gradeBook1 course name is: %s\n",
gradeBook1.getCourseName() );
System.out.printf( "gradeBook2 course name is: %s\n",
gradeBook2.getCourseName() );
System.out.printf("This gradeBook1 professor name is:y %s\n",
gradeBook1.getProfessorSurname () );
System.out.printf ("This gradeBook2 professor name is: %s\n",
gradeBook2.getProfessorSurname () );
}
}
Please help me: Thanks in advance