创建 属性 检查分数清单

Creating a Property Inspection Score Checklist

每个问题都应该用0到3.0的分数来回答,并加上一个加权值,在每个答案被评分后计算并输出 使用 Java.

的总平均分

下面是完成的部分代码,但我要面对

Error:(41, 13) java: illegal start of expression

class entry {
        private String description;
        private double weight;
        private double score;

        public entry (String description,double weight, double score) {
            this.description = description;
            this.weight = weight;
            this.score = score;

        }
        public double getFinalScore() {
            return score * weight;

            public static void main ( String[] args) {
    entry en1 = new entry ("Free from debris/rubbish/or other items such as suitcases and laundry (score low for high amount of debris)",0.15d, 3.0d);
    entry en2 = new entry ("Reception exists, if no reception a viable alternative entry area in a building or approaching a unit", 0.09d, 2.5d);
    entry en3 = new entry ("Lighting sufficient ",0.09d, 1.2d);
    entry en4 = new entry ("Free from odor", 0.15d, 0.24d);
    entry en5 = new entry ("Overall welcoming feel", 0.24d, 2.6d);

如果我理解得很好,我认为您当前的代码与您想要执行的操作相去甚远。请参阅下面的一些最小示例,了解它的外观。

首先,您可以创建一个 class 来表示 属性 中的每个 field/area,例如:

public class Field {
    private String description;
    private double weight;  
    private double score;
     
    public Field(String description, double weight, double score) {
        this.description = description;
        this.weight = weight;
        this.score = score;
    }
    public double getFinalScore() {
        return score * weight;
    }
    // other getter/setters as needed
}

然后在主 class 中,我创建了 3 个 Field 实例(用于演示目的),每个实例都有相关的描述字符串、权重和样本分数(例如最高 3.0)一,然后打印出总分:

public static void main( String[] args)  { 
     Field f1 = new Field("Free from debris..." , 0.15d, 2.0d);
     Field f2 = new Field("Level of street noise..." , 0.09d, 3.0d);
     Field f3 = new Field("Overall safe..", 0.24d, 1.0d);  

     System.out.println("Total score for all fields : ");
     System.out.println(f1.getFinalScore() + f2.getFinalScore() + f3.getFinalScore());
}

以上代码打印出来:

Total score for all fields :

0.81