库存程序修改问题第4部分

发布于 2024-11-03 11:07:24 字数 3484 浏览 1 评论 0原文

我尝试修改我的代码以添加 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返回数据 // 添加子类大小

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());
               }

}

I tried to modify my code to add GUI, not sure if I did this correctly and recieved 1 error message as follows:

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 error

Tool completed with exit code 1

If someone could look at my code below, tell me if I have done the modification correctly per these instructions.The GUI should display all of the items in the inventory and include the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee. All dollar values should be displayed as currency (i.e. $D,DDD.CC). There should not be any output in the DOS console.
I am really trying hard to grasp all of this but I am throughly confused, frustrated if I have done this right. Especially since I am not sure with how to fix the error. It would be greatly appreciated if someone could give me some input already a day late turning this in and still have 2 more parts that will be due soon.

enter code here

// Week 7 Inventory Program Part 4
//Inventory Program that stores data in Television class
// Uses GUI to return data
// With added subclass 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());
               }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2024-11-10 11:07:24

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

That is way too much code for anyone to read, but I can tell you that the error message is telling you that the name of the class Televisions doesn't match the name you used for the constructor, Television. These obviously have to match!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文