Java 输出不正确或无法编译

Java 输出不正确或无法编译,java,Java,我有一个问题与几个程序-一个我要调试,另一个我需要写 我要做的第一件事是获取用户输入的行星名称,将其转换为大写,然后在枚举中运行它。我做错了什么? 导入java.util.* public class DebugNine4 { enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE }; public static void main(String[] args) { Planet

我有一个问题与几个程序-一个我要调试,另一个我需要写

我要做的第一件事是获取用户输入的行星名称,将其转换为大写,然后在枚举中运行它。我做错了什么? 导入java.util.*

public class DebugNine4 {
enum Planet {
    MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE
};

public static void main(String[] args) {
    Planet planet;
    String userEntry;
    int position;
    int comparison;
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a planet in our solar system >> ");
    planet = input.nextLine().toUpperCase();
    planet = Planet.valueOf(planet);
    System.out.println("You entered " + planet);
    position = planet.ordinal();
    System.out.println(planet + " is " + (position + 1)
            + " planet(s) from the sun");
}
}
第二个问题是输出没有像我想要的那样通过。它将带来:

Cut Shampoo
而不是与我需要它做的信息-是按服务名称排序,成本和时间。我在这个代码上哪里出错了

首先,您需要创建一个包含三个数据字段的服务对象。 接下来,您需要创建一个包含6个服务对象的数组,并使用本书第420页表9.6中的数据填充它们,如:

service[0] = new Service("Cut",8.00,15);
使用Scanner对象收集问题的响应:按服务、价格或时间对服务进行排序

根据输入,按正确顺序返回3个格式化列中的所有信息,如:

按时间排序:

Trim          $6.00    5 minutes
Shampoo        $4.00    10 minutes
代码:

第一个似乎是:

planet = Planet.valueOf(input.nextLine().toUpperCase());
删除此行,因为无法将字符串放入枚举类型变量:

    planet = input.nextLine().toUpperCase();
编辑:

以上代码有效,请注意您的输入

尝试过的组合,如:火星、火星、火星等。

用于第二项任务: 它精确地打印您的代码,以及阵列中的第一个和第二个服务。 要打印所有项目,请循环浏览这些项目并打印出所需的所有字段。
请考虑使用排序是否不是任务本身。请把我所有的问题都解决好。不,谢谢。我在这个密码上哪里出错了?当你没有进行可信的调试时,我做错了什么你只是不告诉我们问题是什么当我这么做的时候,我收到以下错误:线程main java.lang中出现异常。错误:未解决的编译问题:类型不匹配:无法从字符串转换为DebugNine4.Planet类型DebugNine4.Planet中的方法值String不适用于DebugNine4.maindugnine4.java:16
import java.util.Scanner;

public class DebugNine4 {
    enum Planet {MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE};

    public static void main(String[] args) {

              Planet planet;
              String userEntry;
              int position;
              int pos;
              int comparison;
              Scanner input = new Scanner(System.in);
              System.out.print("Enter a planet in our solar system >> ");
              userEntry = input.nextLine().toUpperCase();
              planet = Planet.valueOf(userEntry);
              System.out.println("You entered " + planet);
              pos =  planet.ordinal();
              System.out.println(planet + " is " + (pos + 1) + " planet(s) from the sun");
           }
        }
public class DebugNine4 {
enum Planet {
    MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE
};

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a planet in our solar system >> ");

    Planet planet = Planet.valueOf(input.nextLine().trim().toUpperCase());
    System.out.println("You entered " + planet);

    int position = planet.ordinal();
    System.out.println(planet + " is " + (position + 1)
            + " planet(s) from the sun");
}
}
import java.util.Scanner;

public class DebugNine4 {
    enum Planet {MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE};

    public static void main(String[] args) {

              Planet planet;
              String userEntry;
              int position;
              int pos;
              int comparison;
              Scanner input = new Scanner(System.in);
              System.out.print("Enter a planet in our solar system >> ");
              userEntry = input.nextLine().toUpperCase();
              planet = Planet.valueOf(userEntry);
              System.out.println("You entered " + planet);
              pos =  planet.ordinal();
              System.out.println(planet + " is " + (pos + 1) + " planet(s) from the sun");
           }
        }