-
January 20th, 2014, 04:43 PM
#1
Don't know how to write a client class to test methods for an assignment
Write a class encapsualting the concept of a course grade, assuming a course grade
* has the following attributes: a course name and a letter grade. Include a constructor,
* the accessor and mutator, and methods toString and equals.Write a client class
* to test all the methods in your class.
Here is my code with all the methods except a client class to test all the methods in the class.
Not sure how to writes the code for it not many tutorials on the subject. Any help is apperiated.
package labmodule7num57;
import java.util.*;
public class LabModule7Num57 {
// Constructors//
private String name;
private String letterGrade;
public LabModule7Num57 (String name,String letterGrade) {
this.name = name;
this.name =letterGrade;
}
// Setting the name of course //
public void setName(String name) {
this.name = name;
}
//Setting the lettergrade of course//
public void setletterGrade(String letterGrade){
this.name=letterGrade;
}
// Getting the name of the course//
public String getName() {
return name;
}
// Getting the name of the letter grade//
public String getletterGrade() {
return letterGrade;
}
// Returning the name of the course and the letter grade//
public String toString() {
return name+":"+letterGrade;
}
public boolean equals(Object obj){
if (!(obj instanceof LabModule7Num57))
return false;
LabModule7Num57 entry = (LabModule7Num57)obj;
return this.name.equals(entry.name) &&
this.letterGrade.equals(entry.letterGrade);
}
public int hashCode(){
int hash = 37;
hash = hash*17 + this.name.hashCode();
hash = hash*17 + this.letterGrade.hashCode();
return hash;
}
public static void main(String[] args) {
}
}
-
January 22nd, 2014, 04:13 PM
#2
Re: Don't know how to write a client class to test methods for an assignment
In the testing class's main method, add code that creates an instance of the class whose methods are to be tested and then use the reference to that instance of the class to call its methods:
Code:
ClassToTest ctt = new ClassToTest(); // create instance of class / may require some args???
ctt.methodToTest(); // call a method to test it. may require args
<dataType> var = ctt.methodToTest2(); // call method that returns a value
// add code here to print the value of var
Norm
-
January 29th, 2014, 09:16 AM
#3
Re: Don't know how to write a client class to test methods for an assignment
Originally Posted by sdunn2
Here is my code with all the methods except a client class to test all the methods in the class.
Not sure how to writes the code for it not many tutorials on the subject. Any help is apperiated.
I believe you just need to create two objects with different attributes, test that they are not equal.
Then again create two objects with same attributes and test that they are equal.
Also use their setters with your parameters and prompt their getters to show that all your methods work as intended.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|