我的代码由以下方面和目标组成:1)获取三个设备的用户输入 2)将这些输入存储在列表中 3)将列表存储在数组中 4)根据更大的 ROI 值对数组中的列表进行排序(索引 3数组中的每个列表) 5)按最大 ROI 的顺序返回数组中的列表
为此,我创建了三个类文件:Main、Equipment 和 Sort
我的问题:1)我的 set() 方法返回类型 2 的未定义错误)我的比较工具按升序返回值,但我需要降序(从大到小)
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.*;
public class Main {
public static void main(String[] args) {
Equipment equ1 = new Equipment("Name", 1.00, 2.00, 3.00);
Equipment equ2 = new Equipment("Name", 1.00, 2.00, 3.00);
Equipment equ3 = new Equipment("Name", 1.00, 2.00, 3.00);
//Equipment Set 1 from User Input
System.out.println("Enter Equipment Set 1 Name: ");
Scanner input = new Scanner (System.in);
String equName1 = input.nextLine();
equ1.set(0, equName1);
System.out.println("Enter Equipment Set 1 Gain: ");
Double equGain1 = input.nextDouble();
equ1.set(1, equGain1);
System.out.println("Enter Equipment Set 1 Cost: ");
Double equCost1 = input.nextDouble();
equ1.set(2, equCost1);
double roi1 = (equGain1 - equCost1) / equCost1;
equ1.set(3, roi1); //Place ROI at index 3
//Equipment Set 2 from User Input
System.out.println("Enter Equipment Set 2 Name: ");
String equName2 = input.nextLine();
equ2.set(0, equName2);
System.out.println("Enter Equipment Set 2 Gain: ");
Double equGain2 = input.nextDouble();
equ2.set(1, equGain2);
System.out.println("Enter Equipment Set 2 Cost: ");
Double equCost2 = input.nextDouble();
equ2.set(2, equCost2);
double roi2 = (equGain1 - equCost1) / equCost1;
equ2.set(3, roi2);
繁星点点滴滴
相关分类