# Help on Homework due at 12!!

• 10-19-2013, 01:30 AM
Messi5454
Help on Homework due at 12!!
There is something wrong with my main. I cant call my getrating method without it showing an error

(Note that this is Problem 7 on p.467 of your textbook.) Complete and fully test the class Characteristic that Exercise 5 (see below) describes. You will have to do both Exercise 5 and Problem 7 to complete this assignment. Include the following methods:

getDescription — returns the description of this characteristic
getRating — returns the rating of this characteristic
getCompatability(Characteristic otherRating) — returns the compatibility measure of two matching characteristics, or zero if the descriptions do not match
getCompatibilityMeasure(Characteristic otherRating) — a private method that returns a compatibility measure as a double value using the formula:
[m = 1 – (r1 – r2)*(r1 - r2)/81]
when both ratings are nonzero; m is zero if either rating is zero. (Recall from Exercise 5 below that the constructor sets the rating to zero, indicating that it has not yet been determined.)
isMatch(Characteristic otherRating) — a private boolean method that returns true if the descriptions match
Exercise 5 is
Consider a class Characteristic that will be used in an online dating service to assess how compatible two people are. Its attributes are

description — a string that identifies the characteristic
rating - an integer between 1 and 10 that indicates a person's desire for this characteristic in another person
Write a constructor that sets the description of the characteristic to a given string and sets the rating to zero to indicate that it has not yet been determined
Write a private method isValid(aRating) that returns true if the given rating is valid, that is, is between 1 and 10
Write a method setRating(aRating) that sets the rating to aRating if it is valid
Write a method setRating() that reads a rating from the keyboard, insisting that the rating supplied by the user be valid
```import java.util.Scanner; /**  *  * @author Juan Villa  *  */ public class Characteristic { String description = null; int rating = 0; public Characteristic(String description) {         description = description;         rating = 0; } private boolean isValid(int sRating) {         if(sRating >= 0 && sRating <= 10)         {                 return true;         }         else                 return false; } public void setRating(int sRating) {         if(isValid(rating) == true)         {                 rating = sRating;                         } } public void setRating() {         @SuppressWarnings("resource")         Scanner kb = new Scanner(System.in);         System.out.print("Enter the rating for..."+getDescription());           rating = kb.nextInt(); }         public int getRating(){                 return rating;         }         public String getDescription() {         Scanner keyboard = new Scanner(System.in);         System.out.println("Please enter description.");         String Description = keyboard.nextLine();         return Description;         } public String getDescription1(){         return description; } private boolean isMatch(Characteristic otherRating) {         if(getDescription().equals(otherRating.getDescription()))         {                 return true;         }         else         {                 return false;         } }         private double getCompatibilityMeasure(Characteristic otherRating)         {                 if(this.rating == 0 && otherRating.rating == 0)                 {                         return 0;                 }                 else                 {                         double m = (double)(1 - (otherRating.rating - this.rating) * (otherRating.rating - this.rating) / 81) * 10;                         return m;                                //r2 equals this.rating                         //r1 equals otherRating.rating                 }                                 }         public double getCompatibility(Characteristic otherRating)                 {                         if(isMatch(otherRating) == false)                         {                                 return 0;                         }                         else                         {                                 return getCompatibilityMeasure(otherRating);                         }                 } }```
``` public class DatingService {         public static void main(String[] args) {                 Characteristic Pat = new Characteristic(null);                 Pat.description = Pat.getDescription();                 Pat.setRating(Pat.setRating()); //same with set rating                                 Characteristic Chris = new Characteristic(null);//same                 Chris.description = Chris.getDescription();//thing                 Chris.setRating(Chris.setRating());//here                                 Characteristic Compatibility  = new Characteristic(null);                 System.out.println(Compatibility.getCompatibility(Compatibility));                                         } }```