I got a message says error: cannot find symbol regarding on c1.certificateAwarded(grade); statement. I have no idea what is the problem. Really need all the help I can get.
Here's the code:
ExamDetails.java
package Exams;
import javax.swing.JOptionPane;
public class ExamDetails {
public static void main(String[] args) {
StudentResults sr = new StudentResults();
sr.inputStudentName();
sr.inputExamName();
sr.inputScore();
sr.inputGrade();
sr.DisplayDetails();
Certificates c1 = new Certificates();
c1.certificateAwarded(grade);
}
}
StudentResults.java
package Exams;
import javax.swing.JOptionPane;
public class StudentResults {
private String fullname;
private String examName;
private int examScore;
private int examGrade;
public String getStudentName()
{
return fullname;
}
public void setStudentName(String name)
{
fullname = name;
}
public String getExamName()
{
return examName;
}
public void setExamName(String exam)
{
examName = exam;
}
public int getExamScore()
{
return examScore;
}
public void setExamScore(int score)
{
examScore = score;
}
public int getExamGrade()
{
return examGrade;
}
public void setExamGrade(int grade)
{
examGrade = grade;
}
public void inputStudentName()
{
fullname = JOptionPane.showInputDialog("Enter the student's name");
}
public void inputExamName()
{
examName = JOptionPane.showInputDialog("Enter the subject's name");
}
public void inputScore()
{
String scoreString = new String();
JOptionPane.showInputDialog("Enter the student's score");
examScore = Integer.parseInt(scoreString);
}
public void inputGrade()
{
String gradeString = new String();
JOptionPane.showInputDialog("Enter the student's grade");
examGrade = Integer.parseInt(gradeString);
}
public String DisplayDetails()
{
String d;
d = "Student Name : " + fullname + "Exam Name : " + examName + "Score : " + examScore + "Grade : " + examGrade;
return d;
}
}
Certificates.java
package Exams;
public class Certificates extends StudentResults {
private String certificate;
public String Grade;
Certificates()
{
super();
certificate = "No Certificate Awarded";
}
String certificateAwarded(/*int grade*/) {
//StudentResults g = new StudentResults();
//Grade = g.inputGrade();
//Grade = inputGrade(examGrade);
if(Grade.equals("Grade : A"))
{
this.certificate = "Certificate of Excellence";
}
else
if(Grade.equals("Grade : B"))
{
this.certificate = "Certificate of Achievement";
}
else
if(Grade.equals("Grade : C"))
{
this.certificate = "Certificate of Achievement";
}
else
this.certificate = "No Certificate Awardedt";
return this.certificate;
}
}
In the ExamDetails.java class, you don't declare or instantiate the grade variable that you're passing to the certificateAwarded method.
Also, you have parameters commented out in your Certificates.java class. You should uncomment the parameter.
For your code to compile, grade would have to be either
a local variable declared within the main method
a field defined on the ExamDetails class
Neither of these declarations are present so the compiler is telling you that it can't find the grade "symbol".
Try adding int grade = sr.getExamGrade(); above the problem line, or something similar.
As the comment suggested, you need to have "grade" declared. Without it, the compiler can't complete determining what the signature is for Certficates.certificateAwarded, since what goes in the argument list is part of the signature. More importantly, you have this in your code:
String certificateAwarded(/* int grade */)
The parameter, "int grade" is commented out. So the compiler sees this:
String certificateAwarded( )
So, what the compiler might be telling you is that it is looking for a method of Certificates named certificateAwarded that takes 1 argument of type {whatever type "grade" is}. It doesn't find that.
I said "might be" because you are missing two symbols on the line in question: grade and a method with a matching signature.
I can think of two things you can try to fix it:
Change " c1.certificateAwarded(grade);" to "c1.certificateAwarded();"
Declare "grade" to be an int somewhere in main (or in a place that is visible within main) and change "String certificateAwarded(/int grade/)" to "String certificateAwarded(int grade)".
I would start by trying the first option. If it is necessary to try the second, you will need to add additional code in both main (or place where grade is visible to main) and in the certificateAwarded method.
Related
Hi I'm working on an android studio project using global arrays,
I can read from the global arrays fine, and have no problem writing
to the global integers ,But i cannot figure out how to set the global
array from code, this is the important parts of the project:
added this under application tag in the android manifest xml:
android:name=".Globals"
java class Globals:
import android.app.Application;
public class Globals extends Application {
public int empnum=13;
public int getData3() {
return empnum;
}
public void setData3(int empnum) {
this.empnum = empnum;
}
public String[] passw = {"0123","0123","0123","0123","0123","0123","0123","0123","0123","0123","0123","0123","0123"};
public String[] getData4() {
return passw;
}
public void setData4(String[] passw) {
this.passw = passw;
}
public int login=0;
public int getData5() {
return login;
}
public void setData5(int login) {
this.login = login;
}
public String[] empname = {"Name1","Name2","Name3","Name4","Name5","Name6","Name7","Name8","Name9","Name10","Name11","Name12","Name13","Not logged in"};
public String[] getData6() {
return empname;
}
public void setData6(String[] empname) {
this.empname = empname;
}
Here is the block of code I'm having trouble with
inner class of java class TimeIn:
final Globals g = (Globals) getApplication();
final String[] empname = g.getData6();
final String[] passw = g.getData4();
public void onClick(View v) {
i = 0;
String empname = edit2.getText().toString();
int getemn = Integer.parseInt(edit.getText().toString());
if (i == 0 && h == 0) {
g.setData3(getemn);
g.setData6(String[getemn], empname); // This one line right here won't compile, I have tried different combinations but have had 0 luck
i = 1;
h = 1;
}
}
I have no problems getting and using a String array, this is how it works to get
an array value and compare it to a string:
public void onClick(View v) {
i = 0;
String getemp = edit2.getText().toString();
int getemn = Integer.parseInt(edit.getText().toString());
if (i == 0 && getemp.equals(passw[getemn])) { // All of this works perfectly
g.setData3(getemn);
g.setData5(0);
tfone.setText("Empoyee " + getemn);
tftwo.setText("Logged in");
i = 1;
}
if (i == 0 && getemp != (passw[getemn])) {
tfone.setText("No matches found");
edit2.setText("Not logged in");
i = 1;
}
}
So I know this line of code is wrong:
g.setData6(String[getemn], empname);
but for
the life of me I can't figure out how it should be written, the only error hint is I
get from hovering over the line-
array type expected; found 'java.lang.String'
Anyone know what I'm doing wrong?
In Global class, you declare the method with one parameter
public void setData6(String[] empname) {
this.empname = empname;
}
but when you call, you put 2 parameters g.setData6(String[getemn], empname);
You should remove one parameter
or add another method with 2 parameters in Globals class
Also
You are wrong in here
...
String empname = edit2.getText().toString();
int getemn = Integer.parseInt(edit.getText().toString());
...
g.setData6(String[getemn], empname); // This one line right here won't compile, I have tried different combinations but have had 0 luck
The setData6 function now require 2 parameters, one is String array and the other is String
but the way you put the String array to the function is wrong
Here is a simple example that show how to pass the String array to function
public class Test {
public static void setData6(String[] empnameList, String empname) { // with the `String array` you should declare the variable name like `empnameList` or `arrEmpname` NOT `empname` because `empname` make confusing when you read code
this.empnameList = empnameList;
this.empname = empname;
}
public static void main(String[] args) {
String[] strArray = new String[]{"Name1","Name2","Name2"};
String empName = "Na";
setData6(strArray,empName); // call method with 2 parameters here
}
}
Hope this help
Solved!! it turns out I had to modify my setter part of my Globals class, so this first part (the getter method) in the Globals class is correct:
public String[] compname = {"Manager's company", "Company2", "Company3", "Company4", "Company5", "Company6", "Company7", "Company8", "Company9", "Company10", "Company11", "Company12", "Company13", "Not punched in"};
public String[] getData7() {
return compname;
}
I had to change the getter part of my Globals class to this:
public int setcmpn = 0; // <-- Edited, this should equal some integer value
public void setData7(int setcmpn, String compname) { // removed [] from 2nd argument
this.setcmpn = setcmpn;
this.compname[setcmpn] = compname; // added in [] after array's name and fill it with the first argument from setData7 method
}
And to set the value of the desired index from any class just use:
Globals g = (Globals) getApplication();
g.setData7(getemn, getemp);
where getemn is an integer and getemp is a string.
This question already has answers here:
Collections.sort with multiple fields
(15 answers)
Closed 7 years ago.
so i'm having issues making this work for me. what this code needs to do is have 3 different (string) fields that then sort them into alphabetical order i've had help before but it wont run on my netbeans. i am currently up to date with all updates as well.
heres the code i have so far
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
public class test {
private Scanner scan = new Scanner(System.in);
private List<LayoutOfScientist> scientistsNames = new ArrayList<LayoutOfScientist>();
private String name, field, idea;
private boolean continueLoop = true;
private int countTo3 = 0;
private void run() {
while(countTo3<3&&continueLoop) {
if(countTo3>0) {
System.out.println("Would you like to add another scientist? (Y/N)");
}
if(countTo3 == 0 || scan.nextLine().equalsIgnoreCase("y")) {
System.out.println("Please enter the scientist's name:");
name = scan.nextLine();
System.out.println("Please enter the scientist's field:");
field = scan.nextLine();
System.out.println("Please enter the scientist's idea:");
idea = scan.nextLine();
scientistsNames.add(new LayoutOfScientist(name, field, idea));
} else {
continueLoop = false;
}
countTo3++;
}
scientistsNames.sort(Comparator.comparing(LayoutOfScientist::getScientistName));
for(LayoutOfScientist lOS : scientistsNames) {
System.out.println(lOS.getScientistName() + ", " + lOS.getScientistField() + ", " + lOS.getScientistIdea());
}
}
private class LayoutOfScientist {
private String scientistName, scientistField, scientistIdea;
private LayoutOfScientist(String scientistName, String scientistField, String scientistIdea) {
this.scientistName = scientistName;
this.scientistField = scientistField;
this.scientistIdea = scientistIdea;
}
public String getScientistName() {
return scientistName;
}
public String getScientistField() {
return scientistField;
}
public String getScientistIdea() {
return scientistIdea;
}
}
public static void main(String[] args) {
new Test().run();
}
}
Your class name is test (lowercase t) and in your main method, you are calling Test().run().
You need to rename your class to be Test and that should work. Or if your file is test you need to change Test().run() to test().run() instead of public class test to public class test. However, it is good programming practice to name a ClassLikeThis.
If your error is something else entirely, tell us what the error is.
I am learning Java and so, I want easy and understandable answer.
You will know what I mean when you see the code below:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Playeri user = new Playeri();
Enemyu enem = new Enemyu();
Scanner input = new Scanner(System.in);
user.name = input.nextLine();
user.showName();
enem.showUserName();
}
}
class Playeri {
String name;
void showName() {
System.out.println("Your name is " + name + ".");
}
}
class Enemyu {
Playeri enemUser = new Playeri();
void showUserName() {
System.out.println("Hey, bro! Are you " + enemUser.name + "?");
}
}
Suppose input is: John.
Then, output will be:
Your name is John.
Hey, bro! Are you null?
Here, I want John instead of null in output(line 2).
But I can't.
How can I access the same input to other classes (for e.g: Enemyu) other then the class having the declararion of the variable in which input is set (for e.g: Playeri)?
In Other Words:
How can multiple classes access the same value of variable that is set in a class through main method?
Please answer my question!
Thank you very much!
EDIT: Sorry for incorrect indentation in the code.
You are not setting value to the object's name variable.
public static void main (String[] args) {
Playeri user = new Playeri();
Enemyu enem = new Enemyu();
Scanner input = new Scanner(System.in);
user.name = input.nextLine();
user.showName();
enem.showUserName();
}
}
class Playeri {
String name;
void showName() {
System.out.println("Your name is " + name + ".");
Enemyu.enemUser.name=name; // Set it like this
}
}
class Enemyu {
static Playeri enemUser = new Playeri(); // make it static
void showUserName() {
System.out.println("Hey, bro! Are you " + enemUser.name + "?");
}
}
Output -
John
Your name is John.
Hey, bro! Are you John?
This solves your problem, but It is recommended you use setter-getter method.
You can pass it as a parameter to that method.
void showName(String myName) {
System.out.println("Your name is " + myName + ".");
}
and
enem.showUserName(user.name);
or, you could set it the way you did with the user class.
or, you could use mutators (setters/getters) in this case, a set-method, or pass it as a parameter to the constructor of the class.
Here is a fixed version of your code. The problem that you had was that you created two separate instances of Playeri and only set the name on one of the instances. This solution only creates a single instance of Playeri, thus bypassing the problem.
import java.util.Scanner;
public class Foo {
public static void main (String[] args) {
Playeri user = new Playeri();
Enemyu enem = new Enemyu(user);
Scanner input = new Scanner(System.in);
user.name = input.nextLine();
user.showName();
enem.showUserName();
}
}
class Playeri {
String name;
void showName() {
System.out.println("Your name is " + name + ".");
}
}
class Enemyu {
Playeri enemUser;
public Enemyu( Playeri p ) {
this.enemUser = p;
}
void showUserName() {
System.out.println("Hey, bro! Are you " + enemUser.name + "?");
}
}
In your Enemyu class create getters and setters for your field variables.
Inside Enemeyu...
private String name;
...
public void setName(String newName) {
this.name = newName;
}
public String getName() {
return this.name;
}
...
Then inside your main method...
...
Enemyu enem = new Enemyu();
enem.setName("John");
Granted you might also want to provide your class with an overidden toString() method (which in your case is your showName). However, in your case; I don't think that will be necessary.
Your problem was that you were never setting the name field in the object.
The goal is to produce this:
Picture of the task summary here
These are the errors I get when I try to compile:
screen shot
I have changed and fixed most of the more obvious errors I think which was mainly just stupid of me. Sorry.
I have this code
public class Ex5Program {
public void start() {
Tutor[] tutors = createTutorsArray();
printTutors(tutors);
printOnLeaveList(tutors);
updateTutorDetails(tutors[1]);
printNewTutorDetails(tutors[1]);
Tutor tutorWithMostPapers = getTutorWithMostPapers(tutors);
printTutorWithMostPapers(tutorWithMostPapers);
}
private Tutor[] createTutorsArray() {
String[] noPapers = {};
String[] introductoryPapers = {"CompSci101", "CompSci111"};
String[] coreStage1Papers = {"CompSci101", "CompSci105"};
String[] allStageOnePapers = {"CompSci111", "CompSci101", "CompSci105"};
String[] stageTwoPapers = {"CompSci210", "CompSci220", "CompSci225", "CompSci230"};
Tutor[] tutors = new Tutor[7];
tutors[5] = new Tutor("Sad Sack", 86302, introductoryPapers, false);
tutors[4] = new Tutor("Crystal Ball", 49123, introductoryPapers, false);
tutors[2] = new Tutor("Earl Lee Riser", 40879, allStageOnePapers, true);
tutors[3] = new Tutor("Tom Katt", 50876, stageTwoPapers, false);
tutors[1] = new Tutor("Candy Kane", 30869, noPapers, false);
tutors[0] = new Tutor("Carrie Oakey", 30987, coreStage1Papers, true);
tutors[6] = new Tutor("Sonny Day", 49586, stageTwoPapers, true);
return tutors;
}
private void printTutors(Tutor[] tutors) {
System.out.println("Current Tutors");
System.out.println("==============");
for (int i = 0; i < tutors.length; i++) {
System.out.print(i + 1 + ". ");
System.out.println(tutors[i].toString());
}
}
private void printOnLeaveList(Tutor[] tutors) {
System.out.println();
System.out.println("Tutors Currently on Leave");
System.out.println("=========================");
for (int i = 0; i < tutors.length; i++) {
if (tutors[i].isOnLeave()) {
System.out.println(tutors[i].getName());
}
}
}
private void updateTutorDetails(Tutor tutor) {
tutor.setName("Ali Katt");
tutor.setStaffId(23456);
String[] stage1Papers = {"CompSci101", "CompSci105", "CompSci111"};
tutor.setPapers(stage1Papers);
tutor.setOnLeave(true);
}
private void printNewTutorDetails(Tutor tutor) {
System.out.println();
System.out.println("Updated details");
System.out.println("===============");
System.out.println("Name: " + tutor.getName());
System.out.println("Id: " + tutor.getStaffId());
String[] papers = tutor.getPapers();
System.out.print("Papers: ");
if (papers.length > 0) {
for (int i = 0; i < papers.length; i++) {
System.out.print(papers[i] + " ");
}
} else {
System.out.print("None");
}
System.out.println();
if (tutor.isOnLeave()) {
System.out.println("Currently on leave");
}
}
private Tutor getTutorWithMostPapers(Tutor[] tutors) {
Tutor tutorWithMostPapersSoFar = tutors[0];
for (int i = 0; i < tutors.length; i++) {
if (tutors[i].teachesMorePapersThan(tutorWithMostPapersSoFar)) {
tutorWithMostPapersSoFar = tutors[i];
}
}
return tutorWithMostPapersSoFar;
}
private void printTutorWithMostPapers(Tutor tutorWithMostPapers) {
System.out.println();
System.out.println("Most papers");
System.out.println("===========");
System.out.println(tutorWithMostPapers.getName() + " teaches more papers than any other tutor.");
}
}
and I created this code here(It has been changed):
public class Tutor {
// instance variables
private String name;
private int staffId;
private String[] papers;
private boolean onLeave;
public Tutor(String name, int staffId, String[] papers, boolean onLeave) {
// Complete this constructor method
this.name = name;
this.staffId = staffId;
this.papers = papers;
this.onLeave = onLeave;
}
// Insert getName() method here
public String getName(){
return name;
}
// Insert setName() method here
public void setName(String name){
this.name = name;
}
// Insert getStaffId() method here
public int getStaff(){
return staffId;
}
// Insert setStaffId() method here
public void setStaffId(int StaffId){
this.staffId = staffId;
}
// Insert getPapers() method here;
public String[] getPapers(){
return papers;
}
// Insert setPapers() method here
public void setPapers(String[] papers){
this.papers = papers;
}
// Insert isOnLeave() method here
public boolean isOnLeave(){
return onLeave;
}
// Insert setOnLeave() method here
public void setOnLeave(boolean OnLeave){
this.onLeave = onLeave;
}
// Insert toString() method here
public String toString(){
return name + "(Staff id:"+staffId+")";
}
// Insert teachesMorePapersThan() method here
public Tutor teachesMorePapersThan(Tutor other){
return(papers.length>other.papers.length);
}
}
Typo: toString() not tostring(), which results in Object.toString() is being invoked and the intended formatted string is not being returned. Change to:
#Override public String toString()
Using the #Override annotation would have produced a compiler error in the case of tostring() being the method name and alerted you to the error, because no method of that name exists in a superclass.
Several of the setter methods have missing parameters:
// Insert setPapers() method here
public void setPapers(){
this.papers = papers;
}
// Insert setOnLeave() method here
public void setOnLeave(){
this.OnLeave = OnLeave;
}
First error: setStaffID()
You are calling it using an int, but on your method you say it doesn't have any parameter.
Take a look that you have some others errors caused by the same mistake. Correct them first...
You need to look at the error text to find the problems. While a newbie may instinctively just dismiss the error messages as uselesss (as a result of years of clicking the x or cancel or whatever on windows dialogues), The error text is actually the most useful resource for figuring out what the error is, 90% of the time.
For instance, the first error reads
File: F:\course related stuff\101\Lab06\Ex5\Ex5Program.java [line: 54]
Error: method setStaffId in class Tutor cannot be applied to given types;
required: no arguments
found: int
reason: actual and formal argument lists differ in length
If you read it carefully, you can see it tells you the name of the file, the line number, the method call name, the class name containing the method, and some additional information about the exact type of error. It is even telling you what you did wrong in calling the method, by putting an "int" where "no arguments" were required, that the "actual and formal argument lists differ in length".
Read the other error messages, and you will see that they actually tell you what the problem is.
This code also needs newlines inserted to group blocks of stuff, comments added to explain exactly how it works, and a few java style violations fixed - some teachers grade for style and clarity as well as just functionality.
Also, if the reason you are failing your class is because you don't understand how to program, it may be because of excessive use of stack overflow to solve the problems. In the real world, if you can just use somebody else's code, that's great, but the point of a programming class is is to teach you how to come up with your own code, not how to use somebody else's.
Well it's not easy to help, because i think you don't know what you are doing. But first thing when you create a set method like this:
public void setPapers(){
this.papers = papers;
}
you should declare the arguments like this:
public void setPapers(String[] papers){
this.papers = papers;
}
and you should know that variables names is caseSensitive so :
private boolean onLeave;
public boolean isOnLeave(){
//return OnLeave; this variable is not declared
return onLeave;
}
I think you need to study a little more, because you can't read the compilation errors.
This is the error I'm getting:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
TeamLeader cannot be resolved to a type
at TeamLeadDemo.main(TeamLeadDemo.java:26)
This is my code:
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();
}
}
}
}
In addition, I declared this in a separate class:
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);
}
}
What is causing this error and how might I resolve it?
EDIT: Indentation, whitespace, naming conventions and readability issues have been somewhat addressed.
If this problem is with maven project then right-click Maven > Update Project should solve the problem
The problem is that TeamLeader appears to be an inner class (hard to tell, your indentation is bad), and since it's not static, you can't instantiate it by itself.
You either need to make TeamLeader its own class, or make it a static class and instantiate it as Employee.TeamLeader (or whatever the parent class is, your indentation is really not helpful here).
Your exception message says this
Exception in thread "main" java.lang.Error: Unresolved compilation problem: TeamLeader cannot be resolved to a type
This means that you have tried to run a program that used some class that has not compiled correctly.
Go back and fix the compilation error(s).
It is not clear what the fix for the compilation error should be, but the error is saying that it cannot find a class called TeamLeader. Perhaps it doesn't exist. Perhaps it is in a different package. Perhaps you haven't compiled it. Perhaps something else.
Looking at the code, I think the problem is that you have defined two distinct classes called TeamLeadDemo, one as a nested class of Employee and the second as a top-level class. Furthermore the second of these is attempting to use TeamLeader ... but the TeamLeader class that you have actually declared is nested 2 levels down in Employee; i.e. its real name is Employee.ShiftSupervisor.TeamLeader.
This is all a bit nonsensical.
By the look of it, you defined a whole bunch of classes in the same file ("Employee.java") without much understanding of what it means to put one class inside another. Most likely, each of those classes should be declared in its own file. And most likely you should just delete the nested TeamLeadDemo class.
That error can appear also if you create the inner class by moving it from somewhere, and with reorganization, you put the import line for that inner class in its outer class file. After that the inner class cannot be resolved to a type anywhere. Automatic insert of import won't help.
You have not published the import section of the outer class and we cannot check that variant. Check for it, and if the excessive import is there, remove it.
And if you work in Eclipse, it is very probable you need to clean the project after that.