• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compile error

 
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry;
Actually I started out with JCreater then i found this site and began to follow advice of mentors and went to TextPad. I used the following configuration from it's wizard:
Default tab spacing = 4
Indent size = 4
Checked Convert new tabs to spaces
Checked Convert existing tabs to spaces when saving files

That is why I was so surprised to see the spaghetti that was display in the post. Wow!
doco
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I get my program to average each score entered? . I also would like to know how to write the code to check for redundacy. If the name has been entered then I wouldn't want another test score just the 1st one entered.
 
Donald R. Cossitt
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lisa;
There is an excellent book; Beginning Java Objects, From Concept to Code by Jacquie Barker; Wrox Press that covers Beginning Java using a Student Registration System as it's model. Go to Barker's book on Amazon to see a copy new or used. I think it would help you tremendously.
HTH
doco
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would also recommend The Objects First Book.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we are going to start recommanding books than Thinking In Java which is free on the web would be anyones first choice.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How can I get my program to average each score entered? I also would like to know how to write the code to check for redundacy. If the name has been entered then I wouldn't want another test score just the 1st one entered.


I lost track of where we were, what with people going on about tabs, can you please repost your code.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A copy of my code

I'm sorry it's so messy I cut and pasted it from a former reply.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this code has no main, so what does your driver class look like?
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Comment on your code: you still don't have a default constructor. You need to learn why that is important.
To go to the next step it sounds like you will need a data structure of some sort, an array maybe. So I would be included to tell you to start from scratch, instead of trying to change the code you already have.
So either start asking questions about how to use data structures, or write some code and let us know when you have problems with it.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's still got that too!
BTW I think Saint Willims sounds rather cool, don't you
[ February 28, 2003: Message edited by: Barry Gaunt ]
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I ADDED SOME CODE TO CHECK REDUNDANCY. IHOPE I'M ON THE RIGHT TRACK. WILL THIS WORK?
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know the requirements.
What this code is trying to do is compare two students, one whose name is entered when the object is created, and the other whose name is entered when the user is prompted. If that is the assignment than this looks like you are on the way.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WELL IT DIDN'T WORK, SO I DECIDED TO WORK WITH AVERAGING THE SCORE ENTERED. I DON'T KNOW WHAT IS WRONG WITH MY CODE. THIS IS MY OUT PUT
Exam Score= 100
Number of Students = 1
Number of Exam Scores = 1
The average is = 200

Student Name = ll kk
SSN = 444444444
Exam Score= 100
Number of Students = 2
Number of Exam Scores = 2
The average is = 100

Student Name = pp pl
SSN = 555555555
Exam Score= 100
Number of Students = 3
Number of Exam Scores = 3
The average is = 66

AS YOU CAN SEE IT IS INCORRECT, I KNOW THAT MY PROBLEM IS SIMPLE BUT I HAVE TRIED EVERTHING. CAN YOU TELL ME WHAT I AM DOING WRONG WITH THE AVERAGE METHOD?
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not going to comment until you format your code. Help us help you!
Eugene.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be a great help to us if:
1] In addition to using the *code* tags you indent your code. You can see your own post, you can see that the code is not indented. If is a bit disrespectful to ask people to help you and not go to the trouble of formatting your code for easy read-ability.
2] State the specific requirements which you are working towards (what is the problem you are trying to sove).
3] Post the code which calls this class. The code with the "main" in it. Not knowing what that code does makes it more difficult also.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WELL I AM SORRY! REMEMBER BEGINNER! THIS IS MY DRIVER CODE.

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lisa Smith:
WELL I AM SORRY! REMEMBER BEGINNER!



Are you sorry? Are you willing to learn? Even a beginner can use a space bar, especially when that beginner has been asked to extend this courtesy by at least three or four people.

Also, there is no need to SHOUT! Some people have been trying to help you. :roll:
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still don't know the exact problem you are trying to solve. But if you want to do things like find the average you need to move that code out of the Student class.
Here is an example framework which may help you start thinking about how to solve this problem in a different way.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a copy of my requirements. I am so frustrated with this problem. My instructor is out of town and I am a distance learning student and I have been working night and day trying to solve this. I'm not looking for the answer just guidance on solving the problem. I am sorry to be such a pest but I am trying to learn.
Requirements:
1. Implement a class named Student representing information about a student enrolled in a course and that student's performance on an exam. The class should have the following private instance variables:
Strings name and ssNumber, to store the student�s name and Social Security number.
An integer examScore representing the student�s score on the exam.
A boolean scoreAlreadyEntered that will indicate whether or not the student�s exam score has already been entered.
The class should have the following public instance methods:
Student(), a constructor that prompts the user for the student�s name and Social Security number, and reprompts for just the Social Security number until it receives a string of exactly nine characters. (To simplify matters, we won't do any kind of error checking on the name.) Once the name and Social Security number have been entered, examScore should be initialized to zero and scoreAlreadyEntered should be initialized to false (since no exam score has been entered for that student).
void enterScore(), which prompts for the student�s score on the exam, reprompting until it is in the range 0-100. The value 100 should be defined as an additional private (final) instance variable in the class declaration, and the user should be informed of the legal range of scores when prompted to enter the exam score. Once a legal value is entered, it is assigned to the examScore instance variable. If scoreAlreadyEntered is false, it is set to true after the assignment to the instance variable is done (since now an exam score has been entered for that student). We are keeping track of scoreAlreadyEntered so that when enterScore is called, we will know whether it is the first time we are entering that student's score, or if we have entered a score previously for that student and we are now entering a new, corrected score.
2. Write a simple driver class to test this class so that you are confident that it works correctly. I do not want you to turn in the assignment as it stands now -- this checkpoint is just for your benefit to be sure that your basic class is right before we start adding static (i.e., class) variables and methods.
3. Add the following private static (class) variables, both integers that you should initialize to zero, to the class:
examTotal, representing the total of all of the exam scores for those students whose scores have been entered. (Note that if more than one score has been entered for a particular student, examTotal should only include the most recent score entered for that student.)
numberEntered, which represents the total number of students whose scores have been entered and included in the total.
Of course, just declaring these class variables does not mean that they will store the correct values. One or both of these values may have to be updated when enterScores is run. In particular:
The first time that enterScores is run by a particular student (i.e., when scoreAlreadyEntered for the student is false), you should increment numberEntered, and increase examTotal by whatever exam score is entered for the student.
When enterScores is re-run by a student who has already run it before (i.e., when scoreAlreadyEntered for the student is true), then you should not increment numberEntered (as that student has already been included in the count), and you should subtract that student's previous exam score from examTotal before adding in the new score that is entered.
This will guarantee that the class variables maintain the correct totals throughout the computation.
4. Add the following public static (class) method to the class:
void reportAverage(), which computes and displays (using System.out.println) both the number of students whose scores have been entered and the average exam score of all students who have had their exam scores entered. Note that the average should only be computed if the number of students with scores entered is greater than zero -- otherwise an error message should be displayed (again, using System.out.println).
5. Extend your driver class so that it declares a few Student objects and demonstrates that all of your methods work correctly. It is your job to be sure that the driver thoroughly tests your class, but in particular you should be sure to enter at least three students� scores, display at least two different averages, and run enterScores more than once for at least one of the students. The finished Student class and the final driver class that you have at this point are what I want you to turn in.
Remarks:
1. Turn in .java files for both your Student class and the driver class. In addition, this week you should also turn in a printout of the output of your program (just the screen output -- don't worry about the input dialog boxes). Programs turned in without a sample output will be penalized -- you will not be allowed to submit them later.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we should make it rule number one to get students to post the problem specification/requirements before helping. Let's try that in future, it will enable helpers to guide the student through the problem much more efficiently.
This would be a nice problem for "Test Driven Development" and a nice problem to solve in the BlueJ environment if anybody knows it.
Notice that Lisa has made a mistake right at the beginning. The requirements state

Strings name and ssNumber, to store the student�s name and Social Security number.


And the Student class has
The identifiers to be used are clearly stated in the requirements. Some points lost immediately and needlessly.
However, it is not a very good requirment to have the constructor prompting for user input, what happens if the user wants to abandon the program?
Ok I'll let the original helpers, and very patient fellows at that (I admire that), continue. (Too many cooks principle...)
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like Barry says, you need to follow the assignments guidelines. If the teacher asks for "name" and you give him/her "firstname" & "lastname" that isn't what they are looking for.
Another example is the constructor. The assignment specifically states what goes in the ctor. Since you already have the code that does that rewrite your class so that it does that.
As I see it you already have step 1 (if you rewrite your code a little). Step 2 you also already have.
Step 3 is a bit tricky. You need to follow the instructions exactly. You are told to add "private static (class) variables". This type of variable will be shared for every Student class which is instantiated. When you change the value of these variables you should print it out, each time, (as a learning thing) so that you see what is happening.
Work on that (or ask questions) before moving onto the rest of the assignment.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, I really appreciate your patients also. I will do what you have suggested and try to move forward.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I started over and I don't know how to begin checking for re-run. I think the best place to put this code is in the setname method after prompting for name. I just don't know how to begin. I know a if-else is the way. If name = name then write message already entered and set examentered to true. I don't quit know the sytax for this. What would I compare it it name == name.What should I do?

Code formatted (last time)
[ March 03, 2003: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the requirements:

The class should have the following private instance variables:
Strings name and ssNumber, to store the student�s name and Social Security number.
An integer examScore representing the student�s score on the exam.
A boolean scoreAlreadyEntered that will indicate whether or not the student�s exam score has already been entered.


And:

The value 100 should be defined as an additional private (final) instance variable in the class declaration, and the user should be informed of the legal range of scores when prompted to enter the exam score.


[ March 03, 2003: Message edited by: Barry Gaunt ]
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To determine if a name has already been entered I would do something like this:

See my post in which I get an example framework. This method would not be in the Student class.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Barry is trying to point out you need to explicity follow the assignment whenever humanly possible. So it may make sense to have a method called setname() in which you prompt the user for their name. But the teacher has told you to put that code into the constructor. So you need to realize that he/she can take points off of your code, even if it sovles the problem, for not following the directions. (I promise not to go on about this anymore.)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lisa, this is what you must have for part 1:

Carefully compare the above with the assignment.
Fill in the gaps, then we'll take you to step 2.
You can add a String toString() method that prints out the values of name, ssNumber, examScore, and scoreAlreadyEntered.
Stick all this in a file Student.java and compile it.
[ March 03, 2003: Message edited by: Barry Gaunt ]
[ March 03, 2003: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the outline for a test driver, stick it in Driver.java:
Compile and run it and convince youself that
your Student class is behaving according to the assignment step 1.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lisa, I have just had a closer look at this assignment. If you follow each step very closely and sequentially, then you are, in fact, told how to do everything. Really, no fancy stuff at all required.
Step 4. leaves a little room for fantasy but is just a matter of creating some students, calling enterScore(), and calling reportAverage() all sprinkled with prints of the students' states.
[ March 03, 2003: Message edited by: Barry Gaunt ]
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote the code over and I have some errors. For some reason with average it is not summing the grades entered. And what I tried with re-run is not working. THis is my code


This is my output:
Student Name = ho
SSN = 666666666
Number of Students = 1
Exam Score= 50
Total number of exams entered 1
The Average Score is 50

Student Name = ho
SSN = 666666666
Number of Students = 2
Exam Score= 52
Total number of exams entered 2
The Average Score is 26

Student Name = jj
SSN = 666666666
Number of Students = 3
Exam Score= 100
Total number of exams entered 3
The Average Score is 33
This is my driver:
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out average so now the only problem I have is re-run.
I tried this and it isn't working either any suggestions
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know my 2nd if is set to true; and i'm suppose to subtract from total but how do i set the most current inputed score to examScore and add it to the examTotal
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All I know is that Im gunna change my display name to a chick, then I'll get 71 replies.
you go girl
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This tells you exactly what has to be done:
The above if is constructed from the quoted requirements.
[ March 05, 2003: Message edited by: Barry Gaunt ]
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did that and I my output is still wrong. Take a look
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because it's my birthday you can have this:

Please be aware that it uses the identifiers as requested by the assignment. You will have to change some things to make it fit into your version.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry I got into this late. But I do not like the mix of model and GUI elements in your Student class. It may be too late now but in the future try to keep GUI elements and data elements separate. MVC
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul, I think if you take a look at the exact asignment details a few posts back, you will see what is required. I agree with you about the MVC but I assure you that would complicate the current issues enormously Doing the input in the constructor is a no-no in itself - but the assignment requires it
Cheers
-Barry
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boy, that Barry sure is one nice guy.
 
Lisa Smith
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Happy Birthday Barry!! !
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic