Hi! I'm new to Java programming and my professor assigned this really hard assignment, and I can't seem to get the right output. I get the right results, but it doesn't match the way the output is suppose to look like. I tried a lot of ways, but I can't fix it.
The code algorithm runs like this: It takes in a file, and you assign a constraint, and then the program runs and assigns a bracket if the grade in the file corresponds to the grades from 0-100.
I am afraid you have methods too long. Your main method should ideally contain one statement.
I think you are trying to write code before you have worked out what to do. You need to write down (preferably with paper pencil and [important]eraser) what you intend to do. When you have a formula, algorithm or similar, then you have a good chance of converting it into code.
I agree, you'd better have single method for loading data from file to array. then another to ask for input. etc... you see, at least your printBar is a dedicated method - it is good.
To your question - it looks worth starting with flipping the output upside down. Your main loop counts from small values to large - and you obviously need to count from large to smaller. Start changes from here.
I'm new to Java programming and my professor assigned this really hard assignment
I'm sorry to say this, but it is very easy assignment. Just compose yourself and fix your code step by step. This assignment do not contain any puzzle, nothing which requires some brain-storming. It is very routine thing - simply to read data and plot them. So keep calm and continue, good luck
In your original post it looked like your buckets were just coming out in the wrong sequence. So what's the problem now?
And if I misunderstood your original problem... it helps if you spell things out for us. When I look at your code it doesn't seem to represent buckets in any obvious way (at least not obvious to me in my 30-second look), so it's really hard for an outsider (i.e. anybody but you) to point to problems with it.
posted 3 years ago
And yes the buckets were wrong, but I fixed it. It's suppose to print out "" for the constraint the user inputs.
Kevin Kang wrote:So, I tweaked some parts of my code, but I still don't get the correct output. Could I have some assistance, please?
We're trying; but nobody here is simply going to hand you the code.
1. StopCoding (←click). You're not writing "Hello World" any more, you have a substantial task; and you can't expect to simply bash out code to solve it. Right now, you're so busy thinking about what you've written and trying to "tweak" it to get it to work that you can't see the wood for the trees.
2. In order to write a good program, you need to understand what it needs to do (Note: WhatNotHow (←click)), and in order to do that you need to understand the problem.
3. Write out, in English (or your native language), all the things that need to be done.
You know you need to read grades from a file, so one task might be 'Read grade', or 'Read grades' (or maybe both).
You also know that grades in the file are strings, but your program will probably want them as numbers, so another task might be 'Convert grade'.
You also need to get a "bucket size", so another task might be 'get Bucket Size'.
You'll then probably need to convert your bucket size to ranges, so how about 'convert Bucket Size to ranges'.
and so on.
Note that you're not interested (at this point) in HOW they're going to work, simply that it's something you'll need to do.
Alternatively, if you really feel you have to put them in sequence, write some pseudo-code, but write it in English, not in Java.
Once you've done that, go back to your Histogram class, and see if it bears any resemblance to what you've mapped out. I doubt it will, but that's good, because now you're designing.
Hope it helps.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here