Java 无法确定如何修复代码。。。超出我的理解
我有一个我一直试图创建的代码。到目前为止,它将无法编译和运行,数组已关闭,GUI将无法工作。我在修复这段代码的过程中迷失了方向。恐怕我将不得不重新开始,再次迷失方向。这是我的烂摊子如果有人能帮我Java 无法确定如何修复代码。。。超出我的理解,java,arrays,user-interface,Java,Arrays,User Interface,我有一个我一直试图创建的代码。到目前为止,它将无法编译和运行,数组已关闭,GUI将无法工作。我在修复这段代码的过程中迷失了方向。恐怕我将不得不重新开始,再次迷失方向。这是我的烂摊子如果有人能帮我 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mobile.phones; /** * * @author Parents */ impo
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mobile.phones;
/**
*
* @author Parents
*/
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MobilePhones {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
}
private String ItemNumber; //item # of product
private String ProductName; //product name
private String Department; //department name
private double UnitStock; //units in stock
private double ItemPrice; //Price per unit
private double InventoryValue; //The dollar value of the inventory in stock
private double CalculateInventory; //The total value of all of the inventory in stock
private double value;
private double UnitPrice;
int getValue;
private MobilePhones myPhone;
/**
*
*/
//constructor
public MobilePhones (String item, String product, String department, double units, double price) {
String unit = null;
ItemNumber = unit;
ProductName = product;
String dept = null;
Department = dept;
double stock = 0;
UnitStock = stock;
double Price = price;
} //end constructor
//getter and setter methods for MobilePhones
public void setItemNumber (String item) { String unit = null;
//setter for item number
this.ItemNumber = unit;
} //end setter item number
public String getItemNumber() { //getter for item number
return ItemNumber;
} //end getter item number
public void setProductName (String product) { //setter for product name
this.ProductName = product;
} //end setter product name
public String getProductName() { //getter for product name
return ProductName;
} //end getter product name
public void setDepartment (String department) { String dept = null;
//setter for department name
this.Department = dept;
} //end setter department name
public String getDepartment() { //getter for department name
return Department;
} //end getter department name
public void setUnitStock (double units) { double stock = 0;
//setter for units in stock
this.UnitStock = stock;
} //end setter units in stock
public double getUnitStock() { //getter for units in stock
return UnitStock;
} //end getter units in stock
public void setUnitPrice (double price) { //setter for unit price
this.UnitPrice = price;
} //end setter unit price
public double getUnitPrice() { //getter for unit price
return UnitPrice;
} //end getter for unit price
//calculate inventory value
public double getInventoryValue(){
return UnitStock * UnitPrice;
}//end calculate inventory value
public void setCalculateInventory (double value){
this.CalculateInventory = value;
}
public double getCalculateInventory(Phone[] myPhones){
double revenue = 0.0;
for(int i = 0; i < 5; i++){
revenue = getInventoryValue();
{
myPhones[0] = new Phone ("0001");
myPhones[1] = new Phone ("0002");
myPhones[2] = new Phone ("0003");
myPhones[3] = new Phone ("0004");
myPhones[4] = new Phone ("0005");
//output
System.out.println("Product Number: \t\t" + myPhones[i].getItemNumber());
System.out.println("Item Name: \t\t\t" + myPhones[i].getProductName());
System.out.println("Number of Items currently in Stock: \t" + myPhones[i].getUnitsStock());
System.out.println("Cost per Unit: \t\t$%.2f\n" + myPhones[i].getUnitPrice());
System.out.printf("Total Value of Inventory is: \t$%.2f\n", revenue);
System.out.println();
} // end output
return 0.0;
/**
*
* @author Parents
*/
}
return 0;
}
private static class Phone {
public Phone() {
}
private Phone(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private String getItemNumber() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private String getProductName() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private String getUnitsStock() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private String getUnitPrice() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class SmartPhone extends MobilePhones{
private String MobileOS;
private double restockingfee;
double rate = 0.05;
int getValue;
public SmartPhone( String item, String product, String department, double units, double price, String MobileOS )
{
super(item, product, department, units, price);
this.MobileOS = MobileOS;
}
public String getMobileOS() {
return MobileOS;
}
public void setMobileOS(String MobileOS) {
this.MobileOS = MobileOS;
}
public double getValue()
{
return getValue() * 0.05;
}
public double getRestockingFee()
{
return getValue() * 0.05;
}
@Override
public String toString()
{
String formatString = "MobilePhone: %s";
formatString += "Restocking Fee: $%.2f";
formatString = String.format( formatString, MobilePhones,
getValue() * 0.05 );
return( formatString + super.toString() );
}
}
import java.awt.GridLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
*/
@SuppressWarnings("serial")
public final class MobilePhonesGUI extends JFrame {
JTextField itemNumber = new JTextField();
JTextField name = new JTextField();
JTextField unitsInStock = new JTextField();
JTextField unitPrice = new JTextField();
JTextField valueOfInventory = new JTextField();
JTextField restockingFee = new JTextField();
JButton next = new JButton("Next Product");
JButton prior = new JButton("Prior Product");
JTextField valueOfEntireInventory = new JTextField();
private MobilePhones[] MobilePhones = new MobilePhones[] {};
private int productIndex = 0;
private void showNext() {
if (productIndex < products.length - 1) {
productIndex++;
updateGUI();
}
}
private void showPrior() {
if (productIndex > 0) {
productIndex--;
updateGUI();
}
}
public void updateGUI() {
Product currentProduct = products[productIndex];
itemNumber.setText(currentProduct.getItemNumber().toString());
name.setText(currentProduct.getName());
unitsInStock.setText(currentProduct.getUnitsInStock().toString());
unitPrice.setText(currentProduct.getUnitPrice().toString());
valueOfInventory.setText(currentProduct.getValueOfInventory()
.toString());
restockingFee.setText(currentProduct.getRestokingFee().toString());
valueOfEntireInventory.setText(calcValueOfEntireInventory().toString());
}
public Double calcValueOfEntireInventory() {
double value = 0;
for (Product p : products) {
value += p.getValueOfInventory();
}
return value;
}
public MobilePhonesGUI(Product[] products) {
super();
this.products = products;
setTitle("Inventory GUI");
setBounds(0, 0, 400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createGUI();
pack();
prior.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showPrior();
}
throw new ("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
});
}
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showNext();
}
return null;
});
MobilePhonesGUI();
}
private void createGUI(PopupMenu valueOfEntireInventory, PopupMenu next, PopupMenu prior, PopupMenu restockingFee, PopupMenu valueOfInventory, PopupMenu unitPrice, PopupMenu unitsInStock, PopupMenu name, PopupMenu itemNumber) {
JPanel productPanel = new JPanel(new GridLayout(0, 2, 5, 5));
Component add;
add = productPanel.add(new JLabel("Item Number:"));
productPanel.add(itemNumber);
productPanel.add(new JLabel("Product Name:"));
productPanel.add(name);
productPanel.add(new JLabel("Units In Stock:"));
productPanel.add(unitsInStock);
productPanel.add(new JLabel("Unit Price:"));
productPanel.add(unitPrice);
productPanel.add(new JLabel("Value of Inventory:"));
productPanel.add(valueOfInventory);
productPanel.add(new JLabel("Restocking Fee (5%):"));
productPanel.add(restockingFee);
productPanel.add(prior);
productPanel.add(next);
productPanel.add(new JLabel("Value of Entire Inventory:"));
productPanel.add(valueOfEntireInventory);
JPanel inventoryPanel = new JPanel();
inventoryPanel.add(productPanel);
setContentPane(inventoryPanel);
}
/**
*
* @param args
*/
public void main(String[] args) {
Product[] products;
products = new Product[] { new Product(1, "Mouse", 100, 5.0),
new Product(2, "Keyboard", 130, 15.9),
new Product(3, "Notebook", 10, 800.5),
new Product(4, "Memory Key", 20, 20.5) };
new InventoryGUI(products).setVisible(true);
}
}
/*
*要更改此模板,请选择工具|模板
*然后在编辑器中打开模板。
*/
手机包装;
/**
*
*@作者父母
*/
导入java.awt.Component;
导入java.awt.GridLayout;
导入java.awt.PopupMenu;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.util.*;
导入javax.swing.JFrame;
导入javax.swing.JLabel;
导入javax.swing.JPanel;
导入javax.swing.JTextField;
公共级手机{
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
}
私有字符串ItemNumber;//产品的item#
私有字符串ProductName;//产品名称
私有字符串Department;//部门名称
私人双单位股票;//单位股票
私人双项目价格;//每单位价格
private double InventoryValue;//库存存货的美元价值
private double CalculateInventory;//所有库存的总值
私人双重价值;
私人双单价;
int-getValue;
私人手机;
/**
*
*/
//建造师
公共移动电话(字符串项目、字符串产品、字符串部门、双单位、双价格){
字符串单位=null;
ItemNumber=单位;
产品名称=产品;
字符串dept=null;
部门=部门;
双股票=0;
单位股票=股票;
双倍价格=价格;
}//结束构造函数
//手机的getter和setter方法
public void setItemNumber(字符串项){String unit=null;
//项目编号设置器
此.ItemNumber=单位;
}//末端设置器项目编号
公共字符串getItemNumber(){//item number的getter
返回项目编号;
}//结束getter项目编号
public void setProductName(字符串产品){//setter用于产品名称
this.ProductName=产品;
}//末端设置器产品名称
公共字符串getProductName(){//getter用于产品名称
返回产品名称;
}//end getter产品名称
public void setDepartment(字符串部门){String dept=null;
//部门名称设置器
本部门=部门;
}//末端设置器部门名称
公共字符串getDepartment(){//部门名称的getter
退货部;
}//end getter部门名称
公开作废setUnitStock(双单位){double stock=0;
//库存单位设置器
this.UnitStock=股票;
}//端部安装装置库存
public double getUnitStock(){//getter用于库存单位
返回单位股票;
}//库存中的末端吸气剂装置
公共无效设置单价(双倍价格){//单价设置器
这个。单价=价格;
}//终端设置器单价
公共双getUnitPrice(){//UnitPrice的getter
退货单价;
}//单位价格的末端吸气剂
//计算存货价值
public双精度getInventoryValue(){
返回单位股票*单位价格;
}//结束计算存货价值
公共void setCalculateInventory(双值){
this.CalculateInventory=值;
}
公共双getCalculateInventory(电话[]我的电话){
双倍收入=0.0;
对于(int i=0;i<5;i++){
收入=getInventoryValue();
{
myPhones[0]=新手机(“0001”);
myPhones[1]=新手机(“0002”);
myPhones[2]=新手机(“0003”);
myPhones[3]=新手机(“0004”);
myPhones[4]=新手机(“0005”);
//输出
System.out.println(“产品编号:\t\t”+myPhones[i].getItemNumber());
System.out.println(“项目名称:\t\t\t”+myPhones[i].getProductName());
System.out.println(“当前库存商品数量:\t”+myPhones[i].getUnitsStock());
System.out.println(“单位成本:\t\t$%.2f\n”+myPhones[i].getUnitPrice());
System.out.printf(“存货总值为:\t$%.2f\n”,收入);
System.out.println();
}//结束输出
返回0.0;
/**
*
*@作者父母
*/
}
返回0;
}
专用静态类电话{
公用电话{
}
私人电话(字符串){
抛出新的UnsupportedOperationException(“尚未受支持”);//若要更改生成的方法体,请选择“工具”“模板”。
}
私有字符串getItemNumber(){
抛出新的UnsupportedOperationException(“尚未受支持”);//若要更改生成的方法体,请选择“工具”“模板”。
}
私有字符串getProductName(){
抛出新的UnsupportedOperationException(“尚未受支持”);//若要更改生成的方法体,请选择“工具”“模板”。
}
私有字符串getUnitsStock(){
抛出新的UnsupportedOperationException(“尚未受支持”);//若要更改生成的方法体,请选择“工具”“模板”。
}
私有字符串getUnitPrice(){
抛出新的UnsupportedOperationException(“尚未受支持”);//若要更改生成的方法体,请选择“工具”“模板”。
}
}
类智能手机扩展手机{
私人字符串MobileOS;
私人双重进货费;
倍率=0.05;
int getValue;
公共智能手机(字符串项目、字符串产品、字符串部门、双单位、双价格、字符串手机)
{
超级(项目、产品、部门、单位、价格);
this.MobileOS=MobileOS;
}
公共字符串getMobileOS(){
返回MobileOS;
}
公共void setMobileOS(字符串MobileOS){
this.MobileOS=MobileOS;
}
公共双getValue()
{
返回getValue()*0.05;
}
公共双进货费()
{
返回getValue()*0.05;
}
@凌驾
公共字符串toString()
{
String formatString=“手机:%s”;
formatString+=“重新进货费用:$%.2f”;
formatString=String.format(formatString、MobilePhone、,
getValue()*0.05);
return(formatString+super.toString());
}
}
导入java.awt.GridLayout
导入java.awt.event.action
public double getCalculateInventory(Phone[] myPhones){
double revenue = 0.0;
myPhones = new Phone[5];