• Post Reply Bookmark Topic Watch Topic
  • New Topic

taking an entry level java class online  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am taking an entry level java class online for this semester, and I have been fine up until now. The subjects are
Areas of Concentration:
 For Loop
 While Loop
 Do Loop
 Nested Loops

and

 Writing classes
 Constructors

Taking this class online for me was a mistake because I am not a very good book or video learner. I need to be able to interact with someone.
Each assignment is only a week long also, so this makes it rather difficult for me.
If someone is willing to teach me over a voice application, it would be highly appreciated. I am also willing to compensate for your time.
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't commit to voice lessons but I would be happy to tutor you via this forum.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, not entirely sure what I would ask if I were to post here.

This is the assignment here and I am kind of shaky with if statements and such.

For example last assignment was supposed to produce a different result based on someones age. And I was saying > 50 <30 for example and all of the stuff greater than 50 even if it was supposed to calculate differently would produce the wrong outcome.

CIT111 Introduction to Programming – Java - Chapter 8 Repetition
Read chapter 8 pages 152 to 166
Areas of Concentration:
 For Loop
 While Loop
 Do Loop
 Nested Loops
Files Provided:
 do…while (example program)
 for loop (example program)
 while (example program)
 Example Loops (example program)
Assignment:
 Create a new folder: lastnameChp08
 Create the GradeCalculator.java program.
In the GradeCalculator.java program the user clicks the Enter button.
The first input is a JOptionPane that asks the user, “Number of score to be entered?”
scoreAmount = JOptionPane.showInputDialog("Number of scores to be entered?");
numberOfScores = Integer.parseInt(scoreAmount);
When the OK button is clicked another JOptionPane opens asking the user to enter a score (integer) and the JOptionPane will be repeated depending in the value entered for the “Number of score to be entered” (for loop).
The values entered are stored in an accumulator:
accumulatorVariable += scoreVariable
The += adds the current value of the scoreVariable to the value already stored in the accumulatorVariable.
When the last number is entered (end of for loop) a method calls calculateAverage();
The calculateAverage method determines the letter score using the ‘if block’:
 averageScore > 89, letter score is A
 averageScore > 79, letter score is B
 averageScore > 69, letter score is C
 averageScore > 64, letter score is D
 when the averageScore values is below 64 the default letter score is an F
Specifications:
 All variable names use two or more words naming convention
 Method calls and methods MUST be used
 Window size is 400 x 400
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:
This is the assignment here and I am kind of shaky with if statements and such.


Well, have you started yet? The instructions seem to hand hold you, and there are no "if" statements in the beginning. So...

Doug Woodin wrote:
In the GradeCalculator.java program the user clicks the Enter button.
The first input is a JOptionPane that asks the user, “Number of score to be entered?”
scoreAmount = JOptionPane.showInputDialog("Number of scores to be entered?");
numberOfScores = Integer.parseInt(scoreAmount);


Have you created a GradeCalculator.java? The GradeCalculator class skeleton? The main method? And of course, step one ... get an enter button from the user?

Henry
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That seems reasonably straightforward, though option pane is a very old‑fashioned means of keyboard input. Please show us how far you have got.
There is a mistake in the instructions; it doesn't tell you what to do if the score is 64. I would mark 64 as an F there.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've gotten this far, but am getting an error:
GradeCalculator.java:150: error: cannot find symbol
gradeAverage();
^
  symbol:   method gradeAverage()
  location: class GradeCalculator
1 error
I don't quite know how to proceed from here to finish the assignment.


 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code's biggest problem right now is that it is not formatted properly.  The bug that's producing the error can be spotted more quickly with proper formatting.  Here is one way to format your code.

Here's the section you need to look at to find the bug:

Do you see the problem?
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you post any code, be sure to UseCodeTags (that's a link).  I did it for you this time. 
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is working. I do not understand how to do the pop up dialog box. It asks for inputs and then calculates median. Have no idea how to do that.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is what I have put for the "amount of homework assignmets" input. But it is giving me errors:
GradeCalculator.java:161: error: incompatible types: String cannot be converted to int
scoreAmount = JOptionPane.showInputDialog("Enter Number of Grades:");
                                         ^
GradeCalculator.java:162: error: incompatible types: int cannot be converted to String
scoreAmount = Integer.parseInt(scoreAmount);



I need to write the program to enter the total amount of grades, then for each amount of grades, you enter the number of the grade. I.E 3 grades, then you enter 1-100 as the grade. Then based on these two ideas, the program calculates whether you have A B C D F grade. I don't know how to continue.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:. . .
GradeCalculator.java:161: error: incompatible types: String cannot be converted to int
. . .
Pass the value returned from the option pane directly to parseInt without passing go passing through any other variables en route.
...parseInt(JOptionPane.show...)...
You will get a long line which you will have to break into multiple lines as described in the old Sun style guide.
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You're calling scoreAmount() in the declaration of scoreAmount().  This is called recursion and it can be a very useful technique, but in your situation it will lead to a runtime error.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize but I don't really understand or grasp what both of you have said.

Also, the book I have is largely useless.
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this line:

...scoreAmount is an int, but JOptionPane.showInputDialog() returns a String.  That's why you get the error.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did try to declare it as a double and it said a double cannot be a string also. And I haven't a clue how to make the dialog box incorporate additional inputs; the first is just the number of grades, then it is supposed to create a new input for the number of grades inputted.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:I did try to declare it as a double and it said a double cannot be a string also.


First, Campbell already showed you how to convert a string to an int, by using the parseInt() method of the Integer class.

If the target variable is now a double instead, then you can convert a string to a double, by using the parseDouble() method of the Double class. The usage is similar.

Henry
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:I did try to declare it as a double and it said a double cannot be a string also.

Why not declare another variable a String and set the input to that variable.  Then convert that variable into a int.
And I haven't a clue how to make the dialog box incorporate additional inputs; the first is just the number of grades, then it is supposed to create a new input for the number of grades inputted.

Do you need to make the dialog box incorporate multiple input, or just call the dialog box multiple times?
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dialog box when it pops up will say "enter amount of grades."
So if I enter 4 for example the dialog box will remain, and it will say: enter grade1, 2 3 4 5 6 etc.
Then it will produce a result:
A
B
C
D
F
based on a percentage.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and if saythe amount of grades is 4, the dialog box will call for each grade individually.
Enter grade 1:
2:
3:
4:

Result
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need a for-loop and an array.

for-loops often look like this:

This says initialize the variable i to 0, loop while i < numberOfGrades, and each loop, increment i by one.

An array is a group of values, all the same type.  If you are going to store grades "A", "B", etc. in an array, it should be an array of Strings.  You set an array of three Strings like this:

But since you want the array to be the number of grades, set it like this:

You access the grades by its index.  Indexes start at zero, so an array of three will have indexes 0, 1, and 2.  Notice that the last index is the array size - 1.

Now you use for-loops and arrays like this:

But you don't want grades[i] to be "A", you want to get the grade from the input dialog.  So you have two things to do: how do you get the numberOfGrades and set the array to that size, and how do you set grades[i] to a grade that the user enters?
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


To perform this, would it not be something like...
If grade[i] = "A"; //will be >89
if grade[i] = "B"; //will be >87 < 80 for example?
I'm understanding a little bit the premise, but I'm still a bit confused.

if grade[i] (which is the median of the grade totals; if i enter 5 grades to evaluate in the dialog, and all 5 grades are for example 89, so you have 89 89 89 89 89 with an average of 89, then [i] would produce a "A" result. )

Is [i] something I need to declare?

and numberOfGrades is just the first part of the whole.

Is what you described just for the amount of grades before the average is calculated?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to compile that sort of code? Have a look at the Java™ Tutorials about arrays and see what the square brackets mean.
 
Doug Woodin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Have you tried to compile that sort of code? Have a look at the Java™ Tutorials about arrays and see what the square brackets mean.


I appreciate the help, I really do. But my problem as described earlier is that I am not a book learner. I learn through human interaction. This is why I have been looking for someone to actually talk to me in real time about this, because I don't believe I'll be able to learn all of this through reading.

I did have someone who was helping me but I can't rely on them anymore because they are busy.

 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doug Woodin wrote:

To perform this, would it not be something like...
If grade[i] = "A"; //will be >89
if grade[i] = "B"; //will be >87 < 80 for example?
I'm understanding a little bit the premise, but I'm still a bit confused.


Well, I was illustrating how to enter the grades, but when you get to the if statements, they might look like this:

or every better:


if grade[i] (which is the median of the grade totals; if i enter 5 grades to evaluate in the dialog, and all 5 grades are for example 89, so you have 89 89 89 89 89 with an average of 89, then [i] would produce a "A" result. )

No, [i] doesn't stand on its own, only with a variable name.

Is [i] something I need to declare?

and numberOfGrades is just the first part of the whole.

Is what you described just for the amount of grades before the average is calculated?

Okay, let's backup.  Arrays aren't directly involved with means at all.  Why don't you write another class that is just for playing around with the Java language, like:

Inside main(), write

"a" can be any variable name and "5" can be any positive integer.  This creates an array of five Strings, called elements.  You can set an element like this:

This says that the array a has "foo" as its first element.  (Elements start at 0).  You can print the first element to the screen like this:

Now you could set the other elements:

The whole array is just a and a[3] is "bunny".  Does this much make sense?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!