Java Programming help! More about Objects and Methods Needed help with question
ID: 3551350 • Letter: J
Question
Java Programming help!
More about Objects and Methods
Needed help with question 5 and its subsequent question 7
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:
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
Implement a class named Dating Service that instantiates two people, Chris and Pat, and tests their compatibility by using all of the methods you have defined.
Explanation / Answer
package com.steves.chegg.java;
import java.util.Scanner;
class Characteristic {
String description;
int rating;
public Characteristic() {
}
public Characteristic(String description) {
this.description = description;
}
private boolean isValid(int aRating) {
boolean flag=false;
if(aRating>0 && aRating <11)
flag= true;
return flag;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public void setRating() {
Scanner s = new Scanner(System.in);
System.out.println("Enter rating :");
this.rating = s.nextInt();
}
public double getCompatability(Characteristic otherRating){
boolean flag = isMatch(otherRating);
if(flag){
return getCompatibilityMeasure(otherRating);
}else{
return 0;
}
}
// private method
private double getCompatibilityMeasure(Characteristic otherRating) {
int r1 = this.rating;
int r2 = otherRating.rating;
return 1 - (r1 - r2)*(r1 - r2)/81;
}
// private method
private boolean isMatch(Characteristic otherRating){
return this.description.equalsIgnoreCase(otherRating.description);
}
}
public class DatingService {
public static void main(String[] args){
Characteristic chris = new Characteristic("good");
Characteristic pat = new Characteristic("good");
chris.setRating(8);
pat.setRating();
System.out.println("Compatability : "+chris.getCompatability(pat));
}
}
Output :
Enter rating :
8
Compatability : 1.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.