【问题标题】:Problems with Modification of Inventory Program Part 4修改库存程序的问题第 4 部分
【发布时间】:2011-08-12 17:08:27
【问题描述】:

我尝试修改我的代码以添加 GUI,但不确定我是否正确执行此操作并收到 1 条错误消息,如下所示:

C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:40: invalid method declaration; return type required
public Television(String itemNumber, String televisionName, int unitsinStock, double unitPrice) {

^ 1 个错误

工具已完成,退出代码为 1

如果有人可以查看下面的代码,请告诉我是否已按照这些说明正确进行了修改。GUI 应显示库存中的所有物品,并包括物品编号、产品名称、编号库存单位,每个单位的价格,以及该产品的库存价值。此外,GUI 应显示整个库存的价值、附加属性和补货费用。所有美元值都应显示为货币(即 $D,DDD.CC)。 DOS 控制台中不应有任何输出。 我真的很努力地掌握这一切,但如果我做对了,我会感到非常困惑和沮丧。特别是因为我不确定如何修复错误。如果有人能在迟到一天后给我一些意见,并且还有 2 个即将到期的部分,我们将不胜感激。

enter code here

// 第 7 周库存计划第 4 部分 //在Television类中存储数据的库存程序 // 使用 GUI 返回数据 // 添加子类 Size

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
import javax.swing.JLabel;




@SuppressWarnings("serial")
public class Televisions extends JFrame { //class name and attributes

    //declare class variables
    private String itemNumber; //item # of product
    private String televisionName; //product name
    public int unitsinStock; //# of units in stock
    public double unitPrice; //Price per unit

       NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

   //class constructor

  public Television(String itemNumber, String televisionName, int unitsinStock, double unitPrice) {
      this.itemNumber = itemNumber;
      this.televisionName = televisionName;
      this.unitsinStock = unitsinStock;
      this.unitPrice = unitPrice;

}   //end constructor

   //define set and get methods for class variables
   //getter and setter methods for Television

   //item number
public String getItemNumber() { //getter for item number
    return itemNumber;
} //end getter item number

public void setItemNumber (String itemNumber) { //setter for item number
    this.itemNumber = itemNumber;
} //end setter item number

//television name
public String getTelevisionName() { //getter for product name
        return televisionName;
} //end getter television name

public void setTelevisionName (String product) { //setter for product name
    this.televisionName = televisionName;
} //end setter television name

 //available units
public double getUnitsInStock() { //getter for units in stock
        return unitsinStock;
} //end getter units in stock

public void setUnitsInStock (double units) { //setter for units in stock
    this.unitsinStock = unitsinStock;
} //end setter units in stock

 //price
public double getUnitPrice() { //getter for unit price
        return unitPrice;
} //end getter for unit price

public void setUnitPrice (double price) { //setter for unit price
    this.unitPrice = unitPrice;
} //end setter unit price


 //calculate the total inventory by returning the product of available units and price
public double calculateInventory(){
    return unitPrice * unitsinStock;
}

//toString method that outputs the class variables
public String toString () {
        return "Television Name:" + "\t" + televisionName + "\n" +
               "Item Number:" + "\t" + itemNumber + "\n" +
               "UnitsInStock:" + "\t \t" + unitsinStock + "\n" +
               "UnitPrice:" + "\t \t" + nf.format(unitPrice) + "\n" +
               "Item Total:" + "\t" + nf.format(calculateInventory());
               }

}

【问题讨论】:

  • 感谢您为我编辑此内容,非常感谢您的帮助。

标签: java programming-languages


【解决方案1】:

方式代码太多,任何人都无法阅读,但我可以告诉你,错误消息告诉你类的名称 Televisions 与你使用的名称不匹配对于构造函数,Television。这些显然必须匹配!

【讨论】:

  • “这方式代码太多了,任何人都无法阅读......” +1。如果可以的话,我会再给一个 +3 分,因为我完全专注于浏览大量代码,寻找错误。
  • 感谢您指出该错误,感谢您的帮助。我为代码道歉,但我对此并不陌生,并试图获得一些专家意见,以便我更好地掌握这个编程。我确实希望,如果有人向我寻求帮助,我的回答不会那么讽刺。我会确保不再寻求帮助。
  • 我是在讽刺吗?不是故意的。
  • 不,不是你。我只是在寻找一些急需的输入。你给我的我完全迷失了,不希望任何人为我做这项工作只是给我一个比我在课程中更好的方向。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-21
  • 1970-01-01
  • 2010-12-31
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多