gpt4 book ai didi

Java 类 "cannot be resolved to a type"

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:01:52 26 4
gpt4 key购买 nike

这是我遇到的错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:  
TeamLeader cannot be resolved to a type

at TeamLeadDemo.main(TeamLeadDemo.java:26)

这是我的代码:

import java.util.Scanner;

public class Employee {
public String empName, empNumber, hireDate;

public class TeamLeadDemo {}

public Employee(String empName, String empNumber, String hireDate) {
this.setEmpName(empName);
this.setEmpNumber(empNumber);
this.setHireDate(hireDate);
}

public void setEmpName(String empName) {
this.empName = empName;
}
public void setEmpNumber(String empNumber) {
this.empNumber = empNumber;
}
public void setHireDate(String hireDate) {
this.hireDate = hireDate;
}
public String getEmpName() {
return empName;
}
public String getEmpNumber() {
return empNumber;
}
public String getHireDate() {
return hireDate;
}

public class ShiftSupervisor extends Employee {
public double annualSalary, annualProduction;
//constructor
public ShiftSupervisor(String empName, String empNumber,
String hireDate, double annualSalary,
double annualProduction) {
super(empName,empNumber, hireDate);
this.setAnnualSalary(annualSalary);
this.setAnnualProduction(annualProduction);
}

public double getAnnualSalary() {
return annualSalary;
}
public double getAnnualProduction() {
return annualProduction;
}
public void setAnnualSalary(double annualSalary) {
this.annualSalary = annualSalary;
}
public void setAnnualProduction(double annualProduction) {
this.annualProduction = annualProduction;
}

public String toString() {
return "Name: "+ getEmpName() + "\nEmpID: "+ getEmpNumber()
+ "\nHire Date: "+ getHireDate() + "\nAnnual Salary: "
+ annualSalary + "\nProduction: "+ annualProduction;
}

public class employeeStart {
public void main(String[] args) {
String name, id, date;
double sal, prod;

//create scanner object
Scanner keyboard = new Scanner(System.in);

//inputting data
System.out.println("Enter Name: ");
name = keyboard.nextLine();
System.out.println("Enter id: ");
id = keyboard.nextLine();
System.out.println("Enter Hire Date: ");
date = keyboard.nextLine();
System.out.println("Enter Annual: ");
sal = keyboard.nextDouble();
System.out.println("Enter production: ");
prod = keyboard.nextDouble();

//instantiating object
ShiftSupervisor pw = new ShiftSupervisor(name, id, date, sal, prod);

//outputting data
System.out.println("Employee Details: \n" + pw);
}
}
public class TeamLeader {
public double monthlyBonus;
public int minTraining, trainingPresent;

public TeamLeader(double monthlyBonus, int minTraining, int trainingPresent) {
this.setMonthlyBonus(monthlyBonus);
this.setMinTraining(minTraining);
this.addtrainingPresent(trainingPresent);
}

public void setMonthlyBonus(double monthlyBonus) {
this.monthlyBonus = monthlyBonus;
}
public void setMinTraining(int minTraining) {
this.minTraining = minTraining;
}
public void setTrainingPresent(int t) {
trainingPresent = t;
}
public void addtrainingPresent(int hours) {
trainingPresent += hours;
}
public double getMonthlyBonus() {
return monthlyBonus;
}
public int getMinTraining() {
return minTraining;
}
public int getTrainingPresent() {
return trainingPresent;
}
public String toString() {
return "Bonus: "+ getMonthlyBonus() + "\nMinimum Training: "
+ getMinTraining() + "\nAttendence: "+ getTrainingPresent();
}
}
}
}

此外,我在一个单独的类中声明了这一点:

import java.util.Scanner;

public class TeamLeadDemo extends Employee {
public TeamLeadDemo(String empName, String empNumber, String hireDate) {
super(empName, empNumber, hireDate);
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
double sal;
int min, atten;

//create scanner object
Scanner keyboard = new Scanner(System.in);

//inputting data
System.out.println("Enter minimum training: ");
min = keyboard.nextInt();
System.out.println("Enter id: ");
atten = keyboard.nextInt();
System.out.println("Enter Bonus: ");
sal = keyboard.nextDouble();

//instantiating object
ShiftSupervisor pw = new TeamLeader(sal, min, atten);

//outputting data
System.out.println("Employee Details:\n" + pw);

}
}

是什么导致了这个错误,我该如何解决?

编辑:缩进、空格、命名约定和可读性问题已得到一定程度的解决。

最佳答案

如果这个问题与 maven 项目有关,那么右键单击 Maven > Update Project 应该可以解决问题

关于Java 类 "cannot be resolved to a type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5125107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com