创建制作约会服务的java程序
我有一个家庭作业,要求我创建一个约会服务。我已经完成了大约70%的计划,但我已经陷入了僵局。我非常确定我的方法和构造函数类是正确的(如果不是,请纠正我的错误),但我仍然停留在实现类上。我不知道我该如何使用主要方法来启动两个人。以下是给我的指示:创建制作约会服务的java程序,java,eclipse,methods,constructor,Java,Eclipse,Methods,Constructor,我有一个家庭作业,要求我创建一个约会服务。我已经完成了大约70%的计划,但我已经陷入了僵局。我非常确定我的方法和构造函数类是正确的(如果不是,请纠正我的错误),但我仍然停留在实现类上。我不知道我该如何使用主要方法来启动两个人。以下是给我的指示: 描述-标识特征的字符串 评分-1到10之间的整数,表示一个人对另一个人的这一特征的渴望 编写一个构造函数,将特性描述设置为给定字符串,并将额定值设置为零,以指示尚未确定 编写一个私有方法isValid(aRating),如果给定的评级有效,即介于1和1
- 描述-标识特征的字符串
- 评分-1到10之间的整数,表示一个人对另一个人的这一特征的渴望
- 编写一个构造函数,将特性描述设置为给定字符串,并将额定值设置为零,以指示尚未确定
- 编写一个私有方法isValid(aRating),如果给定的评级有效,即介于1和10之间,则返回true
- 编写一个方法setRating(aRating),如果该方法有效,则将rating设置为aRating 编写一个方法setRating(),从键盘读取评级,并坚持用户提供的评级有效
- getDescription-返回此特征的描述
- getRating-返回此特性的等级
- GetCompatibility(Characteristic otherRating)-返回两个匹配特征的兼容性度量值,如果描述不匹配,则返回零
- getCompatibilityMeasure(Characteristic otherRating)-一种私有方法,使用以下公式将兼容性度量值作为双精度值返回: [m=1-(r1-r2)*(r1-r2)/81]当两个评级均为非零时;如果任一评级为零,则m为零。(回想一下下面的练习5,构造函数将额定值设置为零,表示尚未确定。)
- isMatch(Characteristic otherRating)-如果描述匹配,则返回true的私有布尔方法
- 实现一个名为Dating Service的类,该类实例化两个人Chris和Pat,并使用您定义的所有方法测试他们的兼容性
import java.util.Scanner;
public class Characteristic {
public String description; //initialization of instance variables
public int rating;
public Characteristic(String description){ //this is the constructor with a String parameter. It sets the rating at zero as instructed.
this.description= description;
rating=0;
}
private boolean isValid( int aRating){ //this is the method that sets the rating to true when it stays within the limit
if(aRating >= 0 || aRating <= 10){
return true;
}
else{
return false;
}
}
public void setRating(int aRating){ //This sets arating and rating as one and the same when arating comes back as true
if(isValid(rating)==true)
rating=aRating;
}
public void setRating(){
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the rating for " +getDescription());
rating= keyboard.nextInt(); //this sets the rating based on user input
}
public int getRating(){
return rating;
}
public String getDescription(){
Scanner kb = new Scanner(System.in);
System.out.println("Please enter the description.");
String Description= kb.nextLine();
return Description; //this lets the user input a description which is only supposed to be a simple string word
}
public String getDescription1(){
return description;
}
private boolean isMatch(Characteristic otherRating){ //This boolean determines if the two are a match or not
if(getDescription().equals(otherRating.getDescription())){
return true;
}
else{
return false;
}}
private double getCompatabilityMeasure(Characteristic otherRating){ //This determines the numbered "compatability" of the two people
if(this.rating ==0 && otherRating.rating==0){
return 0;
}
else{
double m = 1-((otherRating.rating - this.rating)*(otherRating.rating- this.rating))/(81);
return m;
}}
public double getCompatability(Characteristic otherRating){
if(isMatch(otherRating) == false){
return 0;
}
else{
return getCompatabilityMeasure(otherRating);
}
}
import java.util.Scanner;
公共阶级特征{
公共字符串描述;//实例变量的初始化
公共评级;
公共特征(字符串描述){//这是带有字符串参数的构造函数。它按照说明将额定值设置为零。
这个。描述=描述;
评级=0;
}
private boolean isValid(int aRating){//这是一种方法,当额定值保持在限制范围内时,将其设置为true
如果(aRating>=0 | | aRating如果您想实例化上述特征
类的两个实例,您可以执行以下操作:
Characteristic c1=新特征(“Description”);//使用带一个字符串的构造函数。
对c2
变量执行相同的操作。然后可以调用如下方法:
c1.设定值(10)我不确定是否适合你做你的家庭作业,除了使用我将要考虑的作业的一部分以外,你的具体问题是什么?是的,只需要问一个具体的问题。或者两个不同的具体问题作为不同的问题。你的作业的细节大多是不相关的。mework作业从来都不是一个好主意。作业是为了让你思考,如果你把它外包给互联网,你就不会从中受益。我并没有要求任何人为我做作业。正如你所看到的,我已经完成了大部分工作。我想我的问题是:你看到我的代码有任何明显的错误吗?它似乎符合标准吗指导?我想我只是想请人检查一下我的作业。也谢谢你在下面帮助我将我的方法引入到主课堂。