没有合适的contstructors发现java错误..?

时间:2015-02-11 00:37:07

标签: java

public class CustomerTest
{
    private static Object CustomerType;
  public static void main(String args[])
    {
        String msg = "";
        ArrayList(Customer) cList;

        ArrayList<Customer> customerList = new ArrayList<Customer>();

        Customer c1 = new Customer ("Jones", new Address("Cooper","Arlington", "Texas", 76019), 12345);
        Customer c2 = new Customer ("Smith", new Address("Bowen","Arlington", "Texas", 76006), 65489);
        Customer c3 = new Customer ("willis", new Address("Bowen","Arlington", "Texas",75550), 27589);

        customerList.add(c1);
        customerList.add(c2);
        customerList.add(c3);
        ArrayList<Course> courseList = new ArrayList<Course>();

                Course co1 = new Course ("OnlineCourse",("Java 1","PROGRAMMING", "Davis", 125.00, new Date(1,1,2015), new Date(1,15,2015), "Uta" 2015);
                Course co2 = new Course ("OnlineCourse","Java 2","Jones", 125.00, new Date(1,1,2015), new Date(1,15,2015));
        Course co3 = new Course ("InClassCourse","CanonPictures", "Long", 75.00, new Date(2,5,2015), new Date(3,2,2015));

        courseList.add(co1);
        courseList.add(co2);
        courseList.add(co3);

        c1.setCType(Customer.customerType.STUDENT);
        c2.setCType(Customer.customerType.FACULTY);
        c3.setCType(Customer.customerType.GOVERNMENT);


         for (Customer c: customerList)
         {
          cList = c.getCustomerList();
          for (Customer c: cList)
          {
            msg += c.calculateCharge();
          }
         }
            JOptionPane.showMessageDialog(null, msg);
    } 
}

获取“找不到合适的构造函数”在课程c01,co2中。

它也没有让我设置学生,教学等等。它给了我一个“找不到符号”我有6个班级,这是主要班级。我宣布所有的变量,集合,在其他类中获取,现在我正在尝试执行主类(这一个)好的我添加了类的主要用途。

public class Course
{

    private String title;
    private String instructor;
    private double price;
    public enum CourseType{PROGRAMMING, MATHEMATICS, PHOTOGRAPHY, MUSIC, PAINTING, MISC};
    private CourseType cType;
    private Date startDate;
    private Date endDate;

    public Course()

    {
                setTitle("");
            setInstructor("");
        setPrice(0.0);
        setCType(CourseType.PROGRAMMING);
        setStartDate(new Date());
        setEndDate(new Date());
        }
    public Course(String title, String instructor, double price, Date startDate, Date endDate)

    {
                setTitle(title);
                setInstructor(instructor);
                setPrice(price);
                setStartDate(startDate);
                setEndDate(endDate);         

    }
    public void setTitle(String title)

    {
        this.title = title;

    }
    public void setInstructor(String instructor)

    {

        this.instructor = instructor;

    }
    public void setPrice(double price)

    {
        this.price = price;

    }
    public void setCType(CourseType cType)

    {
        this.cType = cType;

    }
    public void setStartDate(Date startDate)

    {
        this.startDate = startDate;

    }
    public void setEndDate(Date endDate)

    {
        this.endDate = endDate;

    }
    public String getTitle()

    {
        return title;

    }
    public String getInstructor()

    {
        return instructor;

    }
    public double getPrice()

    {
        return price;

    }
    public CourseType getCType()

    {
        return cType;

    }
    public Date getStartDate()

    {
        return startDate;

    }
    public Date getEndDate()

    {
        return endDate;

    }
    public double calculateCharge(Customer.CustomerType c)

    {
        return 0.0;

    }

    public String toString()

    {
        return("title" + title + "instructor" + instructor + "price" + price + "cType" + cType);

    }
} 

public class Customer
{

    private String name;
    private Address address;
    private int accountNumber;
    public enum CustomerType{STUDENT, FACULTY, GOVERNMENT};
    private CustomerType cType;
    private ArrayList<Course> courseList = new ArrayList<Course>();

    public Customer()

    {

        setName("");
        setAddress(new Address());
        setAccountNumber(0);
    }
    public Customer(String name, Address address, int accountNumber)

    {
        setName(name);
        setAddress(address);
        setAccountNumber(accountNumber);
    }
    public void setName(String name)

    {
        this.name = name;

    }
    public void setAddress(Address address)

    {
        this.address = address;

    }
    public void setAccountNumber(int accountNumber)

    {
        this.accountNumber = accountNumber;

    }
    public void setCType(CustomerType cType)
    {
        this.cType = cType;

    }
    public void addCourse(Course course)

    {
        courseList.add(course);

    }
    public String getName()

    {
        return name;

    }
    public Address getAddress()

    {
        return address;

    }
    public CustomerType getCType()

    {
        return cType;

    }
    public String getCourseList()

    {
        return courseList.toString();

    }
    public String toString()

    {
        return("name" + name + "Address" + address + "accountnumber" + accountNumber + "CustomerType" + cType + "courseList" + courseList);

        }

}

1 个答案:

答案 0 :(得分:0)

这些是您提供的构造函数。

public Course(String title, String instructor, double price, Date startDate, Date endDate)

public Course()

根据课程c01对象,您看起来有几个问题。首先,错误的括号(和“Uta”2015,对构造函数也无效。

Course co1 = new Course ("OnlineCourse",("Java 1","PROGRAMMING", "Davis", 125.00, new Date(1,1,2015), new Date(1,15,2015), "Uta" 2015);

我不确定它是否只是一个拼写错误,但没有合适的构造函数,正如错误所述。

尝试用此替换它,看看你得到了什么。

Course co1 = new Course ("Java 1","Davis", 125.00, new Date(1,1,2015), new Date(1,15,2015));

对于找不到符号错误,看起来您可能没有正确引用枚举。

c1.setCType(Customer.customerType.STUDENT);

看起来应该是,

c1.setCType(Customer.CustomerType.STUDENT);