java - 奇怪的JAVA编译错误?

标签 java

我需要预先说明我不允许在类里面使用 IDE,我必须使用 TextPad 来编译和运行。任何帮助将不胜感激。

一共有三个文件,一个驱动文件和另外两个类文件。 Lab4文件是驱动文件,类文件是“ITEM”和“NAME”。

编译驱动程序“Lab4”文件时出现以下错误。

     F:\Java\Lab 4A\Lab4.java:86: error: cannot find symbol
        System.out.println ("Manufacturer's Name: " + item.manName());
                                                      ^
      symbol:   method manName()
      location: variable item of type Item

“Lab4” 文件的代码在这里:

    import java.util.Scanner;

    public class Lab4
    {
     public static void main (String[] args)
    {
          String firstName = "";
          String lastName = "";
          String manName = "";
          float cost = 0.00f;
          int itemNum = 0;


        // Instantiate class files
        // Variables are declared because variables are expected in name.java file
        Name name = new Name("Bob", "Jones");
        Item item = new Item(985534, 9.99f, "Lewis Mfg");


        // Create a scanner
        Scanner input = new Scanner(System.in);


        // Recieve user input for variables
        System.out.println ("Please enter the customer's first name: ");
        firstName = input.next();
        while (firstName.length() < 1)
            {
            System.out.println ("Enter a valid first name");
            firstName = input.next();
            }
            name.setfirstName(firstName);
            firstName = "";

        System.out.println ("Please enter the customer's last name: ");
        lastName = input.next();
        while (lastName.length() < 1)
            {
            System.out.println ("Enter a valid last name: ");
            lastName = input.next();
            }
            name.setlastName(lastName);
            lastName = "";

        System.out.println ("Please enter the item number: ");
        itemNum = input.nextInt();
        while (itemNum < 1)
            {
            System.out.println ("Enter a valid item number: ");
            itemNum = input.nextInt();
            }
            item.setitemNum(itemNum);
            itemNum = 0;

        System.out.println ("Please enter the item's cost (including decimal): ");
        cost = input.nextFloat();
        while (cost < 1)
            {
            System.out.println ("Enter a valid cost amount: ");
            cost = input.nextFloat();
            }
        item.setcost(cost);
            cost = 0;

        System.out.println ("Please enter the manufacturer's name: ");
        manName = input.next();
        while (manName.length() < 1)
            {
            System.out.println ("Enter a valid manufacturer's name");
            manName = input.next();
            }
            item.setmanName(manName);
            manName = "";


        // Outputs the data entered by the user and stored in the other classes,               Name and Item
           System.out.println ("First Name: " + name.getfirstName() + "\n");
           System.out.println ("Last Name: " + name.getlastName() + "\n");
           System.out.println ("Item Number: " + item.getitemNum() + "\n");
       System.out.println ("Item Cost: " + item.getcost() + "\n");
       System.out.println ("Manufacturer's Name: " + item.manName());

        System.out.println ("\n\nThe customer and item information have been          entered.\n");

     }
     }

错误中引用的“ITEM”文件的代码在这里:

     public class Item
{
    // Create private variables that cannot be accessed directly
     private int itemNum;
     private float cost;
     private String manName;

     // Create instances of the private variables that can be set by the methods
     public Item (int itemNum, float cost, String manName)
            {
            this.itemNum = itemNum;
            this.cost = cost;
        this.manName = manName;
        }

    // Gets the variable values from the user via the driver class
    public int getitemNum()
        {
        return itemNum;
        }

    public float getcost()
        {
        return cost;
        }

    public String getmanName()
        {
        return manName;
        }


    // Sets the variable amounts into the private variables after validating the input     form
    public boolean setitemNum(int itemNum)
        {
        if (itemNum < 0)
        return false;
        else
        this.itemNum = itemNum;
        return true;
        }

    public boolean setcost(float cost)
        {
        if (cost < 0)
        return false;
        else
        this.cost = cost;
        return true;
        }

    public boolean setmanName(String manName)
        {
        if (manName.length() < 0)
        return false;
        else
            this.manName = manName;
        return true;
        }
    }

任何帮助都会很棒!

最佳答案

您将方法命名为 getmanName(),但在错误行上调用了 manName()

关于java - 奇怪的JAVA编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9489925/

相关文章:

java - jtable 中整行的删除线

java - Lucene_36 - 无法解析或不是字段

java - HAProxy SSL终止+客户端证书验证+ curl/Java客户端

Java - 获取接口(interface)中方法的签名,其代理实现也是如此

java - indexOfMaxInRange 返回错误的数字?

Java JEditorPane 超链接不会退出标签

java - 在 JEditorPane 中显示带有样式表的 XML

java - 无法弄清楚 Java 字符串?

java - 从java中的子包类访问父包类?

java - jpl 库不适用于 java maven 项目