主线程异常-不确定我做错了什么吗?

时间:2019-02-25 01:10:31

标签: java netbeans

关于如何解决此问题的任何想法?不知道我做错了什么。谢谢!

我遇到以下错误:

  

“线程“主”中的异常” java.lang.RuntimeException:无法编译的源代码-找不到符号    符号:类Rectangle    位置:类TestRectangle     在TestRectangle.main(TestRectangle.java:25)“

这是我的代码:

import java.util.Scanner;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package week7assignment;

/**
 *
 * @author Casey
 */
public class TestRectangle {

    public static void displayMenu() {
        System.out.println("1. Set length");
        System.out.println("2. Set width");
        System.out.println("3. Calculate Area");
        System.out.println("4. Calculate Perimeter");
        System.out.println("5. Exit");
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Rectangle rect = new Rectangle();
        try {
            int choice = 0;
            while (choice != 5) {
                System.out.println("Enter your choice (1-5):");
                choice = input.nextInt();
                switch (choice) {
                    case 1:
                        System.out.print("Enter length: ");
                        double length = input.nextDouble();
                        rect.setLength(length);
                        break;
                    case 2:
                        System.out.print("Enter width: ");
                        double width = input.nextDouble();
                        rect.setWidth(width);
                        break;
                    case 3:
                        System.out.println("Length = " + rect.getLength());
                        System.out.println("Width = " + rect.getWidth());
                        System.out.println("Area = " + rect.area());
                        break;
                    case 4:
                        System.out.println("Length = " + rect.getLength());
                        System.out.println("Width = " + rect.getWidth());
                        System.out.println("Perimeter = " + rect.perimeter());
                        break;
                    case 5:
                        System.exit(0);
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

0 个答案:

没有答案