#How to fix an error where the compiler cannot find the symbol which is the method within a println?
68 messages · Page 1 of 1 (latest)
Where did you define that method?
what does getHomeworkAverage() return?
Maybe you return a symbol thats not available in vanilla java? 😄
public void setHomeworkAverage(int homework)
{
this.homework = homework;
}
public int getHomeworkAverage()
{
return homework;
}
In the class
this.getHomeworkAverage()?
???
???
It doesn't work
Never mind, I can't solve it
ℹ️ @hazy beacon this post has been closed. Feel free to reopen it if you have any further questions.
um
@hollow gorgeAm I allowed to ask a different question for the same program here or do I have to create a new post?
Whatever works for you
well
right now, I am having trouble getting a method to print out correctly
It only prints as "0.0"
So I thought about converting int into double but nothing changed
public void setExamAverage(double examAverage)
{
double exam1Score = exam1;
double exam2Score = exam2;
double exam3Score = exam3;
examAverage = (exam1Score + exam2Score + exam3Score) / 3;
}
public double getExamAverage()
{
return examAverage;
}
public void setOverallAverage(double overallAverage)
{
double homeworkAverage = homework;
double quizAverage = quiz;
overallAverage = 015 * homeworkAverage + 0.15 * quizAverage + 0.70 * examAverage;
}
public double getOverallAverage()
{
return overallAverage;
}
Primitives like int, double, boolean, etc. get passed by value. Setting it when used as a parameter will make no difference to the original object's value.
homie gotta yoink the this.examAverage
Oh
Remove it?
try to explain what this function is doing
Nothing changed
Method, right?
same thing
setExamAverage() gets 3 exam scores from user input and then it gets the average
getExamAverage() returns it
setOverallAverage() takes the homework and quiz averages from the user and the exam average then gets the overall average
getOverallAverage() returns it
setExamAverage
then it gets the average
wher set
Where set?
In setExamAverage()? There other previous methods that gets the homework average, quiz average, and 3 exam scores and they all should work
public int getExamScore1()
{
System.out.println("Enter your grade on the first exam: ");
int getExamScore1 = scanner.nextInt();
System.out.println(getExamScore1);
return exam1;
}
What do you mean "reassign it"?
what
I don't know
This language is too confusing for me
C# is not going to confuse me too if I am having trouble with Java, right?
They're the same language for the most part
C# is Microsoft Java
you can take a Java dev and have them write C# in like a few days
From this I'm guessing you have a field in your object called examAverage, which gets read with getExamAverage.
Save yourself some confusion and just use this.examAverage when referencing the field, even if it's not required. That's going to be a lot better than using some weird naming scheme for parameters like pExamAverage just to avoid this.
In setExamAverage you assign to the parameter (examAverage) rather than the field (this.examAverage), which is going to do nothing.
I removed all parameters and nothing has changed
Then open a debugger and see where the problem lies because it's not in assigning that value.
Most debuggers will give you a breakdown of all fields and their values.
I don't have a debugger
TextPad
😒
So why does it keep printing 0.0?
How are this.exam1, this.exam2, and this.exam3 assigned?
Because this isn't doing it.
this.homework = homework;
this.quiz = quiz;
this.exam1 = exam1;
this.exam2 = exam2;
this.exam3 = exam3;
this.examAverage = examAverage;
this.overallAverage = overallAverage;
But where. Would be easier to get a whole class rather than just fragments.
Scanner scanner = new Scanner(System.in);
private int homework, quiz, exam1, exam2, exam3;
double examAverage, overallAverage;
public Class()
{
this.homework = homework;
this.quiz = quiz;
this.exam1 = exam1;
this.exam2 = exam2;
this.exam3 = exam3;
this.examAverage = examAverage;
this.overallAverage = overallAverage;
}
Without user input, the method still prints 0.0