• 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Get Methods & Issues With Collecting Input for Multiple Users

 
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.  I've been working on this for a few hours now.  I had to rewrite my original grade program and write methods for this next project.  I have all the methods written, and they all pretty much functional and return what I need.  My problem now is that my getUserInput() method takes in input for as many people as I want it to, but doesn't report back for each of them, only the last entered.  The counter updates just fine because my output always shows *the last input divided by the proper counter #*.  Any input on what I am missing would be appreciated.  Not asking for the solution, just some guidance.


 
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here I added opportunity to gather all student together

 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!  I am working on it now.  I forgot about arrays.  I haven't had to use them.
 
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. @Vasyl: Please don't provide solutions. In this case, the solution provided isn't even a good one. This is a learning site and if you provide solutions that are not good, that could possibly impede someone else from learning good practices. On the other hand, you will hopefully learn from corrections given to your offered solution. Still, we prefer that you don't give out solutions to OP because it's better that they try to work out a solution themselves. We can guide and give hints.

2. @OP: The problem is that you're storing the new values in the same variables that you had used before. That's why you're seeing only the last values entered. The solution offered,  which you probably gave the thumbs-up to, is certainly one way to resolve that. However, it reminds me of a sign I saw at the shop where I last went for an oil change: "If it's still broken, you didn't use enough duct tape."  You shouldn't use duct tape in a program. If you get into that habit, you'll just keep writing uglier and uglier programs.

3. A more proper solution is to create another class whose instances will encapsulate the scores entered. Who do these scores belong to?  If each set of scores belongs to a Student, then the scores should be in a Student class. So, instead of creating a new array called new_student, you would create a new object by doing this:

Each student will have their own set of score variables. In contrast, the code offered was this:

The problem with that is you are going to be limited to 4 scores, the data is floating around not attached to any object and you have to write separate code/logic to interpret what that String[] means. This is the kind of problem that object-oriented programming is meant to solve in the first place. So, in effect, you are writing code in an object-oriented language that creates the kind of problems object-oriented programming languages like Java are meant to address.

That's like buying a car but instead of driving it, you're hooking a harness up to it and dragging it behind you.

One positive thing to note: Vasil did seem to have the right idea, since he used the name new_student.  At least it hints at what you should be doing. Notice how similar the name new_student is to the ideal code of instantiating a new Student object.

 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate any sort of guidance.  Just a nudge in the right direction.  I'm in an accelerated class which is almost done.  I've been working on this since 8AM.  I've never asked for help before, but I was so happy that I had it written in less than an hour but have been staring at this issue for hours and finally reached out.  
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Object-orientation is about keeping related ideas/behavior together with the data/information that they work on.  Your class is called RevisedGrades.  What does that even mean, conceptually?  What does a thing called RevisedGrades have to do with all that data you have declared from lines 5 to 20?

If you have a drawer in your kitchen (and everybody I know has one) where you just dump all the stuff that doesn't really go with any other stuff that's organized in the other drawers, things like paper clips, stamps, pens/pencils,... basically, your junk drawer, then this class kind of looks like that. It has anything and everything dumped in it.

What is the main purpose of this class?  To report on the grades of a class? Then why not call it something ClassGrades or ClassScores or ClassRecord? Choose a name that suggests or describes a thing's purpose. That way you won't confuse yourself and others reading your code.

As I said before, those scores that you're entering, one set of scores that you enter belong to one Student, right? Then put those scores into a Student object, with one Student object holding all the scores for a particular student. You ClassRecord will keep a list of Student objects.  That's another thing the other suggestion got right, at least.

Ask yourself what you can do with a ClassRecord.  You can ask it to go through the list of Students, get each score for say Test1, total all the scores and get an average.  That might be what you had in mind for the getAverageScore() method. That should belong to a ClassRecord class because it deals with all the student scores.

However, this getLtrGrade() method, what is that supposed to do? By the way, please don't abbreviate names like that. It makes it much harder to read. And how much harder is it to type out getLetterGrade anyway? Nobody wants to read code that mumbles and slurs.  Spell things out and help the reader. Don't be afraid of vowels, they won't cause bugs and they won't cause your program to blow up.  Anyway, does a letter grade belong to a ClassRecord? Or do you assign a LetterGrade to each individual score? Does each individual student get a single letter grade for the total of their scores? If so, then the getLetterGrade() method belongs in the Student class, not the ClassRecord class.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!

I swear, I am just doing as I was asked in the assignment.  Trust me, the wording is confusing sometimes.  This is exactly as I was instructed:

Rewrite the Week Four program to include the following five methods:

getUserInput
getAverageScore
getLtrGrade
getLtrList
displayClassReport

This is why my head is spinning.  As for Revised, I will change that.  That was just a way for me to differentiate the new program from my old one.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for the grades, my original program posted name, average,and grade for each individual as well as a group average and count of how many students received a certain grade.  After I broke it up into methods, now I don't get the correct group average or list of how many got certain grades....and I know this is because of my poor setup.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I guess there's little use in me giving you an entire lecture on proper object-oriented programming if your instructor is giving you instructions that are totally contradictory.

Here's what I can advise you then:

Lay out all the different concepts you're dealing with. Students, scores for each student, letter grades, averages, etc.  If you're breaking out functionality the way those methods suggest, then of course you're going to have to make all that data accessible and shared by all these different methods...

Let me just get this off my chest because I can't stand to not say anything. Those requirements are horrific! That is NOT how you should be writing programs in Java much less requiring students to write code like that in Java. The design you are being asked to implement is nothing more than procedural code written in the guise of object-oriented constructs, i.e. classes, instances, instance fields, and methods.

Now back to what I was saying...

What you seem to be missing is an understanding of scope. Scope basically define how widely a thing can be "seen" or referenced, in what context it can be referenced, and how long it retains its values/identity.  If you are not inclined to go outside of the "fence" that you have been boxed into, then you're going to have to do what I previously called a "duct taped" solution.  You'll have to use a list of arrays. But please, don't use a String[] to represent values that are numbers. Use an int[] or double[] instead.  A Scanner has methods that make it easy to read in user input and treat the values like int or double. See the Scanner API documentation to see which methods are appropriate for the type of data you expect the user to enter.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to limit the scope of variables and keep a handle on their management is to pass parameters and/or use return values from methods. However, I don't know if you have even been taught how to write methods that return values. From the code you posted, it seems like all you know how to write are void methods that operate on shared data.  Here's an alternative design you could consider, if you were allowed to do such a thing:

getUserInput returns a list of int[], each int[] in the list representing a set of scores for one student.

That list gets passed to the getAverageScore() method, which calculates the average score by going through the list it was passed. The method would return a single value, which is the average score (of all scores of all students?)

That single value of average score gets passed to the getLetterGrade() method (go ahead and mumble the name if you want, I prefer to spell out the name you should be using) which takes that score and translates it to a letter. That is the value it returns.

And so on. This way, you can eliminate the need to have so many shared variables at the instance level scope. Just pass parameters and use the results returned by one method as the input to the next method in the process.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.  That was the next direction I was going to go in.  We weren't really taught to do that, per se.  We were given a few things to read.  I was just going back to the materials to attempt it.  This class is basically read and do.  We had more guidance in the way of virtual labs in the beginning.  I'm trying my best.  I was better with C++ back in college over 17 years ago, when I could stop the professor and ask questions....
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

That was my reading.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a chance to talk to a bunch of students recently who mostly said they were more comfortable with C++ than they were with Java, which their instructor and I found somewhat perplexing and amusing since that statement is so incongruous with our experience. For me C++ has way too many pitfalls and is a tool for programmers who have more skill and discipline in managing their programs, both from the structural aspect as well as the conceptual aspects. I find Java to be higher-level than C++ in many respects. Admittedly, I don't do much C++ coding but I'd be willing to bet I know more about it than the average novice programmer who has taken courses in both Java and C++.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've seen many examples of procedural Java code over the years, many from students just learning how to program in Java, many just learning how to program at all. One thing they all have in common is that when the code is more procedural than object oriented, the perspective is backwards when you read the code. Object orientation is about objects and behavior, not so much about data. The OO principle of encapsulation is precisely to hide information inside an object so that you don't have to worry about its management and manipulation; let the object take care of it.

Your main focus as a programmer trying to design an OO program is the behavior of each object and their relationships with other objects. Data is simply something that can influence behavior in some way. You should think of objects as being independent entities with minds of their own. They know how to do things.

So, when you have code like what you have in main(), your focus is still too granular. This is you, the programmer, telling the object every little step to do and the order in which those steps are done. It's like you're a puppeteer, manipulating a mindless doll.

Think of it like this: If you go to a shoe store and can't find a particular shoe in your size, you ask a salesperson to find a pair for you in the stock room. That's it. You don't tell them to walk through the stock room door, go to the third rack, second shelf from the top, and grab the fifth box from the right. The salesperson knows how to do his thing better than you do. You should have this kind of perspective when programming objects. Put the logic for all those small steps in a high-level method of the object. Then you can just call that high-level method from main.

The difference in the code may seem trivial but the difference in your perspective is significant. Instead of you micromanaging your object from main, you just tell it to go do its thing.  
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think one of the keys to good object-oriented programs is "intentional cluelessness." In other words, abstraction.  When you write something like this:
This is you, the programmer, relinquishing the responsibility of knowing how to "do grades" to the ClassRecord object named cs101. You're intentionally staying "clueless" at this level of the code as to what exactly the act of "doing grades" entails.

On the other hand, when you write something like this instead:
this is you, the programmer, showing that you know more about the object's business of creating a class report than the object itself does. You have now stepped outside of the world of object-orientation and into a strange twilight zone where you're ostensibly using objects but you're really not. You're just puppeteering; you're manipulating data that's inside the object through "holes" in the object that you've created to be able to access that data. These "holes" are the methods you defined in the object's API. Here, you're forcing yourself to not be clueless and you're getting into the object's business. Mind your own business. Let the object do its thing.

It's like one of those compartments that are used to safely handle hazardous materials in laboratories. You put the hazardous material inside the compartment, then you seal it. You then stick your hands into those holes with the gloves inside the compartment and, through those gloves, you can handle the material inside. This is what the second listing of main() is like. You're sticking your hand inside these gloves called getUserInput, getAverageScore, getLtrGrade, etc. to make the object "do" things. In fact, by taking all those low-level methods and making them the API to your object, you are forcing yourself to do all the heavy lifting from outside of the object.

In contrast, the first version of main() above is like hitting the "Go" button on a robot and just watching it go do whatever it has been programmed to do.

Of course, the name "doGrades()" used in the first listing not a very good name but it's one I chose to illustrate the abstract nature of the perspective you should take at this level. I could have chosen a name like doYourThang() but then that might distract from the point I was trying to make. I'd probably just go with the name of the last method you show there since it has a nice, high-level sounding, and sufficiently clueless name, displayClassReport().
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, the more "clueless" version of the code you wrote would look like this:

If you chose better names, the program might actually start making sense, like it's telling a story:

If you use the Driver Class pattern, your "clueless" perspective might become even more clear:

Here, you've clearly separated two responsibilities: 1) being the main program entry point and creating and telling an object to do its thing and 2) actually knowing how to do something.  Responsibility #1 is assigned to the GradeReportingProgram class and #2 is assigned to the ClassRecord class.
 
Marshal
Posts: 73760
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:. . . students . . . said they were more comfortable with C++ than they were with Java . . .

That is because we were taught procedural coding throughout our schooldays. I was taught procedural coding at the age of five. Admittedly neither Miss Cutler nor I knew it was called procedural coding, but that is what it was. It was the sort of thing I learnt that lays the foundations for procedural thinking for life. Have a little example:-

Miss Cutler wrote:Campbell, what's 1 + 2?

If you start reading procedural code and compare it to school algebra/maths/arithmetic, doesn't it look similar? I think that is why people gravitate towards a procedural way of thinking. Of course, if people will start by teaching procedural coding, they are going to find it even harder to get people to think in objects later on.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you have a point there, Campbell. When the whole "paradigm shift" from procedural to object-oriented happened a couple of decades ago (as far as the majority of the programmer population was concerned at least), there was much more focus given in thinking in terms of objects than what I have observed there is now. Now, I fear the new programmers have been left with the assumption that the shift in mindset has happened and they just need to get with the program.

Unfortunately, the procedural mindset is well-entrenched from earlier in life. Additionally, the novice lacks context and tries to make up for that by looking for context-free rules which are essentially recipes. That is, they are looking for step-by-step instructions on how to do things they don't really understand how to do. I think this is where education is failing students. Not enough teachers are giving their students the proper context in which to understand objects and object-oriented thinking. They are simply giving students some pretty horrible "recipes," as illustrated by the OP's stated requirements, that are very procedural and procedural-thinking in nature.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.  Your comparisons are outstanding, by the way.  I did tweak it a little bit, but obviously still don't know what I am doing.  I will work on it more later trying to implement what you showed me.  Unfortunately, I had to submit my poorly written, not completely functional program last night.  I'll probably get a zero, but hey...I tried.  I am not giving up on it though.  I will make it work, for my own satisfaction.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a really good attitude to take and it's good to see. Too many folks taking up programming don't seem to care too much about doing the right things the right way. When you do something for the wrong reasons, you're probably going to end up doing the wrong things anyway. I hope you keep asking questions and practicing to be able to write proper Java code, despite the things you're being taught that may not be pointing you in the right direction. If you have any doubts about that, just ask questions here. There's always someone here who will set you back on the straight and narrow.

Good luck.
 
Campbell Ritchie
Marshal
Posts: 73760
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good luck with the marks, anyway.
I worry whenever I hear about people tweaking things. It makes me wonder whether they are guessing. You can guess 1000000× and as long as the guesses are all different, you will have some really good code in there. Somewhere...
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I changed a few methods into get-return ones.  Nothing huge, but I wanted to make sure I could make something work a little better.  Taking baby steps.  I'd show you, but I am at work.  I do appreciate the advice though.  This is my last week of a 6 week course and at least, this was the only time I had issues.  Last week, I had this programs fully functional with just plain code, not the methods thing.  I even managed to make some GUI that validated a login against a list of IDs and Passwords.  Again, baby steps.  I'm not giving up.  I just need to find more time to practice when this is done.  Straight into my next course for my Master's...and I believe this is the only coding class.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go ahead and post your changes. We can tell you if you're on the right track.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I handed in.  3/4 of us did not complete it, so the professor is making a video to help and giving us another opportunity.

 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what have you tweaked so far to make it better?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per my understanding you need a List here, as you are taking input for multiple students.  The List should be of a type Class lets say Student, and Student class should have 3 variables like score1,score2,score3.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The professor really wants get-return methods, so I managed to get one in there that works.  I'm waiting 9n a codeo he is about to do with more instructions.  3 out of 4 of is never finished it, so he's giving us another shot.  

Yes, the list is what I am having issues with.  I look at sample code and read text about it, but I really need to see and hear it explained in order to understand it, which he is about to do.   Sometimes it all looks like hieroglyphics to me, but occasionally the rosetta stone pops up and boom....I get the concept.  It's taking longer than usual this time.
 
Melissa Zimmerman
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Omg. Meant waiting on a video in the above reply.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have a similar assignment.  Do I need to enter data into arrays for the computer to use or run the code piece by piece?  currently I expect to run the code and it ask me to enter student and grade and other information to get later, however it does not.  I think it is because either I shouldn't be running all at once and do piece by piece so the program will ask me what to enter OR I thin I need to put the data in arrays.  Any advice?  I am not going to school to be a developer, this is a class to help me learn to talk to my developers but this has been much harder than I thought.  Any advice is greatly appreciated.  
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

It will be easier to give you advice if you posted the code you've written so far. That way, we'll understand better why it's behaving the way you describe.
 
Amanda Clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am very new to this and it is very confusing and hard to learn.  I am taking a fast paced course to basically introduce to me to programming so I can better understand what my developers at work do and the process involved and learn more terminology.  I won't lie. I am spinning my wheels here.  I have used the book and good and email other students who don't seem to be open to working together or maybe they just aren't like me and need to ask questions.  Anyway I have worked on this all weekend and got nowhere so started over and of course it is due today.  My first assignment is to build onto a previous assignment I had (but I didnt do well on it hence the starting over).  Here is the original assignment I am trying to do, then I need to add on for the current assignment get methods.  
Original Assignment:
Create a Java program to accept input for the following two variables: (a) Students and (b) Scores.
Create a repetitive loop so the program will ask the user if another entry is desired until the user indicates “No.”
Create a variable that will compute the average score for an entire class.
Create a variable that will assign a letter grade based on the student’s score using the chart below.
Create a variable that will list the number of students who received each of the following grade ranges: A, B, C, D, and F. (Note that “+” and “-” grades fall within the general letter grade range.)

I restarted trying to use code I found in an example in my text but when I run it I get a <identifier> expected at the line for "public static void main...." when I look up Identifiers it says it is naming something but I don't see anything there that I need to name?  I found on the internet that I could try to wrap it in a method but I thought this part is supposed to be all one method.  I am completely lost.  Any pointers would be appreciated to help me hobble to end of this class in a week.  

My code:


}





 
Amanda Clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh looks like I fixed my first problem for the <identifier> expected by making a new class and adding it as a 'public class' at the top so it looks like this:
public class FinalAssignment5 {
  public static void main(String[] args){

now I get a new error to try to troubleshoot 'else' without if' at line 20 which is the if statement for F grade.  I will play around with that
 
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That should be



Programming is full of that sort of thing: instead of an identifier ("args" in that code) the compiler comes across a closing bracket. That confuses the hell out of it so then it can't say anything helpful to you. Programmers get used to dealing with error messages of various degrees of helpfulness but it does take a while, there's no doubt about that.
 
Saloon Keeper
Posts: 8449
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Paul Clapham
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amanda Clark wrote:now I get a new error to try to troubleshoot 'else' without if' at line 20 which is the if statement for F grade.  I will play around with that



Look at lines 15, 17, and 19. They should all look similar but one is different. In a bad way.
 
Amanda Clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok now that I can get this to run without error, how come the output part of the screen is not telling me to enter students, scores or grades?  I thought I did this correctly now that I had no errors and I am even using my textbook as an example.  Thanks for any help/advice.  

Here is my code:
import java.util.Scanner;

public class Main {
  public static void main(String[] args){

  int score;
  char grade;
  System.out.println ("Enter Student");
  System.out.println ("Enter Score");
  Scanner keyboard = new Scanner (System.in);
  score = keyboard.nextInt();
  if (score>= 90)
     grade = 'A';
  else if (score>=80)
     grade='B';
  else if (score>=70)
     grade='C';
  else if (score>=60);
  grade='D';
   if (score>50);
     grade = 'F';
  System.out.println("Score="+ score);
  System.out.println("Grade="+ grade);
     String student = new String();
     System.out.println("Student"+ student);

   }


}
 
Carey Brown
Saloon Keeper
Posts: 8449
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The computer will execute each line in order (seeing as how you currently have no loops). Mentally look at each line of code and think what you're telling the computer to do and how it will interact with the user.
 
Junilu Lacar
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amanda Clark wrote:I am not going to school to be a developer, this is a class to help me learn to talk to my developers but this has been much harder than I thought. Any advice is greatly appreciated.


I'll offer you advice not on the programming parts but rather the "talk to my developers" part. I take it that you're in some kind of management role then? First bit of advice, stop thinking of them as "your developers." Speaking from experience, I would rather be thought of by others outside of the development team who also share a stake in the work we're doing as a partner. If you're part of a development team, you think of other developers as your teammates.

I don't know what kind of conversations with the developers at work you have in mind but if you want to support them as best you can, you'd make the conversation more about what you can do for them. As you may have realized by now, developers have enough to struggle with as it is in code and coming up with a clean solution to a problem without having to deal with everything else that's thrown at them from outside of all that.

So rather than "When are you going to be done with this feature?" you can ask "What I can I do to help you get this done sooner?"

Rather than ask "Why haven't you done this (or that)?" you can ask "What can I do to help you get this (or that) done?"

What I'm really getting at is the idea of servant leadership. In my opinion (and experience), this is the best way you as a leader can work with developers and help them do their best.
 
Amanda Clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Amanda Clark wrote:now I get a new error to try to troubleshoot 'else' without if' at line 20 which is the if statement for F grade.  I will play around with that



Look at lines 15, 17, and 19. They should all look similar but one is different. In a bad way.



Hi Paul, I wasn't sure how to reply so I hit 'quote'  I looked at those and then I looked at my text and it was exactly how they had the else statement.  I played around and added 'if' so that it would look like the others and still got error, when I took away the else and just left 'if (score>50); it stopped complaining at me.  Thanks so much.
 
Amanda Clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:

Amanda Clark wrote:I am not going to school to be a developer, this is a class to help me learn to talk to my developers but this has been much harder than I thought. Any advice is greatly appreciated.


I'll offer you advice not on the programming parts but rather the "talk to my developers" part. I take it that you're in some kind of management role then? First bit of advice, stop thinking of them as "your developers." Speaking from experience, I would rather be thought of by others outside of the development team who also share a stake in the work we're doing as a partner. If you're part of a development team, you think of other developers as your teammates.

I don't know what kind of conversations with the developers at work you have in mind but if you want to support them as best you can, you'd make the conversation more about what you can do for them. As you may have realized by now, developers have enough to struggle with as it is in code and coming up with a clean solution to a problem without having to deal with everything else that's thrown at them from outside of all that.

So rather than "When are you going to be done with this feature?" you can ask "What I can I do to help you get this done sooner?"

Rather than ask "Why haven't you done this (or that)?" you can ask "What can I do to help you get this (or that) done?"

What I'm really getting at is the idea of servant leadership. In my opinion (and experience), this is the best way you as a leader can work with developers and help them do their best.



Oh I am not in management - I am an equal to them but not a developer, I do the software testing and release management on my team.  It's me and 6 developers that is why I say 'my developers' just to separate them from me.  I guess the wording didn't come across correctly.  My job is to help them.  I take users calls and troubleshoot their problems before they have to go to a developer.  That is why I am taking this class, so I can learn more and be more helpful to them.  

I already had a huge appreciation for the developers on my team.  I see what they go through everyday and demands put on them to try to make miracles happen.  Whatever I cann do to help them is my first priority.  This class is giving me a front row view.  This is hard to learn and so many complexities ones I knew about and ones I didn't.  I only have this assignment left and then a final project and I feel like I have done most my learning on my own and not through the class.  I broke down in tears today because its so fast paced and I don't learn fast.  Between working 12 hour days and raising kids, I have spent all my time googling, reading and trying and failing at this.  Somehow I am still getting an A so I guess it is working for me.

 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic