Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java构造函数在UserInterface类中未定义_Java - Fatal编程技术网

Java构造函数在UserInterface类中未定义

Java构造函数在UserInterface类中未定义,java,Java,代码的其余部分很好,由于某种原因,我在UserInterface类中遇到了一个错误。我是java新手,所以如果这是一个可以在几秒钟内修复的简单错误,我会提前道歉,我正在问这个问题。我正在使用java Eclipse。请你提供你的答案,并解释你是如何做到的,这样我也可以在这个过程中学习,而不仅仅是有解决方案 错误是: 构造函数Bbat(String,String,int,Store,String,String,int)未定义-UserInterface.java 下面是Bbat类和用户界面类的代码

代码的其余部分很好,由于某种原因,我在
UserInterface
类中遇到了一个错误。我是java新手,所以如果这是一个可以在几秒钟内修复的简单错误,我会提前道歉,我正在问这个问题。我正在使用java Eclipse。请你提供你的答案,并解释你是如何做到的,这样我也可以在这个过程中学习,而不仅仅是有解决方案

错误是: 构造函数
Bbat(String,String,int,Store,String,String,int)
未定义-UserInterface.java

下面是Bbat类和用户界面类的代码

package stage02;

public class Bbat extends SportsGoods {

    private boolean fullTime;
    private String studentType;
    private double currentFees;


    public Bbat () {
        super (null,null,0,null);
        fullTime = true;
        studentType = null;
        currentFees = 0.0;
    }
    public Bbat (String gN, String fN, int age, Store ei, boolean fT, String sT, double cF) {
        super (gN, fN, age, ei);
        fullTime = fT;
        studentType = sT;
        currentFees = cF;
    }

    public boolean getFullTime() {
        return fullTime;
    }
    public String getStudentType() {
        return studentType;
    }
    public double getCurrentFees() {
        return currentFees;
    }
    public void setFullTime (boolean fT) {
        fullTime = fT;
    }
    public void setStudentType (String sT) {
        studentType = sT;
    }
    public void setCurrentFees (double cF) {
        currentFees = cF;
    }

    public String toString () {
        return super.toString() + "\nFull Time: " + (getFullTime()?"Yes":"No") +
                    "\nStudent Type: " + getStudentType() +
                    "\nCurrent Fees: $" + getCurrentFees() + " per hour\n";
    }
}
用户界面:

package stage02;
import java.util.*;
import javax.swing.JOptionPane;

public class UserInterface {

 public void begin() {

  ArrayList < SportsGoods > people = new ArrayList < SportsGoods > ();

  boolean finished = false;
  while (!finished) {
   int selection = showMenu();
   switch (selection) {
    case 1:
     people.add(addCbat());
     break;
    case 2:
     people.add(addBbat());
     break;
    case 3:
     JOptionPane.showMessageDialog(null, "Displaying the stock information ...", "Stock List", JOptionPane.PLAIN_MESSAGE);
     for (int i = 0; i < people.size(); i++) {
      JOptionPane.showMessageDialog(null, people.get(i), "Product Information", JOptionPane.PLAIN_MESSAGE);
     }
     JOptionPane.showMessageDialog(null, "There are " + people.size() + " record(s) in the list", "Total records", JOptionPane.PLAIN_MESSAGE);
     break;
    case 4:
     finished = true;
     JOptionPane.showMessageDialog(null, "*** Program Ended ***\n" +
      "*** Thank you for using this program ***");
     break;
    default:
     JOptionPane.showMessageDialog(null, "\n** Invalid Selection **\n", "ERROR", JOptionPane.ERROR_MESSAGE);
   }
  }
 }

 public int showMenu() {
  int selection = 0;
  String stringSelection = JOptionPane.showInputDialog(
   "******* MENU *******\n\n" +
   "1. Add a new Cricket Bat\n" +
   "2. Add a new BaseBall Bat\n" +
   "3. Display all Details\n" +
   "4. Exit Program\n\n" +
   "Type the number of your selection, and click OK: ");
  selection = Integer.parseInt(stringSelection.trim());
  return selection;
 }

 public Cbat addCbat() {
      String aName = JOptionPane.showInputDialog(null, "\nWhat is the Bat's model? ").trim();
      String bName = JOptionPane.showInputDialog(null, "What is " + aName + "'s grip? ").trim();
      int age = 0;
      do {
       String stringValidAge = JOptionPane.showInputDialog(null, "What is " + aName + "'s price? (no decimal places) ");
       double doubleAge = Double.parseDouble(stringValidAge);
       age = (int) doubleAge;
       if (age <= 1 && age > 200) {
        JOptionPane.showMessageDialog(null, "Error - cost must be greater than 1 to be sold by this store", "ERROR", JOptionPane.ERROR_MESSAGE);
       }
      } while (age <= 1 && age > 200);

      String eType = null;
      do {
       eType = JOptionPane.showInputDialog(null, "What is " + bName + "'s colour? ".trim());
       if (!eType.equals("Red") && !eType.equals("Blue") && !eType.equals("Yellow") && !eType.equals("Black") && !eType.equals("Green")) {
        JOptionPane.showMessageDialog(null, "\n** Invalid Selection **\nBat grip colour must be Red, Blue, Yellow, Black, or Green",
         "ERROR",
         JOptionPane.ERROR_MESSAGE);
       }
      } while (!eType.equals("Red") && !eType.equals("Blue") && !eType.equals("Yellow") && !eType.equals("Black") && !eType.equalsIgnoreCase("Green"));

      String eNum = JOptionPane.showInputDialog(null, "What is " + aName + "'s Product Code? ");
      double nYE;
      do {
       String stringNYE = JOptionPane.showInputDialog(null, "How many " + aName + " are in stock?");
       nYE = (int) Double.parseDouble(stringNYE);
       if (nYE < 0) {
        JOptionPane.showMessageDialog(null, "\n** Value must be zero or more **\n", "ERROR", JOptionPane.ERROR_MESSAGE);
       }
      } while (nYE < 0);
      String or = null;
      or = JOptionPane.showInputDialog(null, "Name of store involved ? ");
      String city = JOptionPane.showInputDialog(null, "City where " + or + " is ? ");
      Store org = new Store(or, city);
      Cbat s = new Cbat(aName, bName, age, org, eType, eNum, (int) nYE);
      JOptionPane.showMessageDialog(null, "Thank you - bat added to the list", "Bat added", JOptionPane.PLAIN_MESSAGE);
  return s;
 }

 public Bbat addBbat() {
  String gName = JOptionPane.showInputDialog(null, "\nWhat is the Bat's model? ").trim();
  String fName = JOptionPane.showInputDialog(null, "What is " + gName + "'s grip? ").trim();
  int age = 0;
  do {
   String stringValidAge = JOptionPane.showInputDialog(null, "What is " + gName + "'s price? (no decimal places) ");
   double doubleAge = Double.parseDouble(stringValidAge);
   age = (int) doubleAge;
   if (age <= 1 && age > 200) {
    JOptionPane.showMessageDialog(null, "Error - cost must be greater than 1 to be sold by this store", "ERROR", JOptionPane.ERROR_MESSAGE);
   }
  } while (age <= 1 && age > 200);

  String eType = null;
  do {
   eType = JOptionPane.showInputDialog(null, "What is " + fName + "'s colour? ".trim());
   if (!eType.equals("Red") && !eType.equals("Blue") && !eType.equals("Yellow") && !eType.equals("Black") && !eType.equals("Green")) {
    JOptionPane.showMessageDialog(null, "\n** Invalid Selection **\nBat grip colour must be Red, Blue, Yellow, Black, or Green",
     "ERROR",
     JOptionPane.ERROR_MESSAGE);
   }
  } while (!eType.equals("Red") && !eType.equals("Blue") && !eType.equals("Yellow") && !eType.equals("Black") && !eType.equalsIgnoreCase("Green"));

  String eNum = JOptionPane.showInputDialog(null, "What is " + gName + "'s Product Code? ");
  double nYE;
  do {
   String stringNYE = JOptionPane.showInputDialog(null, "How many " + gName + " are in stock?");
   nYE = (int) Double.parseDouble(stringNYE);
   if (nYE < 0) {
    JOptionPane.showMessageDialog(null, "\n** Value must be zero or more **\n", "ERROR", JOptionPane.ERROR_MESSAGE);
   }
  } while (nYE < 0);
  String or = null;
  or = JOptionPane.showInputDialog(null, "Name of store involved ? ");
  String city = JOptionPane.showInputDialog(null, "City where " + or + " is ? ");
  Store org = new Store(or, city);
  Bbat e = new Bbat(gName, fName, age, org, eType, eNum, (int) nYE);
  JOptionPane.showMessageDialog(null, "Thank you - bat added to the list", "Bat added", JOptionPane.PLAIN_MESSAGE);
  return e;

 }
}
包装阶段02;
导入java.util.*;
导入javax.swing.JOptionPane;
公共类用户接口{
公共空间开始(){
ArrayList人物=新ArrayList();
布尔完成=假;
当(!完成){
int selection=showMenu();
开关(选择){
案例1:
people.add(addCbat());
打破
案例2:
添加(addBbat());
打破
案例3:
showMessageDialog(null,“显示股票信息…”,“股票列表”,JOptionPane.PLAIN_消息);
for(inti=0;ipublic Bbat (String gN, String fN, int age, Store ei, String fT, String sT, double cF)