The Big Programming Thread - Page 65
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
bautistaaa
United States9 Posts
| ||
O3
Singapore99 Posts
On July 11 2011 04:16 AkaHenchway wrote: Hey guys having some trouble again (Java). I have looked aroud for some help but every explanation im given is way above my head.....write a program taht prompts the user to enter the number of students and each students name and score, and finally displays the name of the student with the highest score is what I am supposed to be doing. + Show Spoiler + import java.util.Scanner; public class highscore{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int i = 0; System.out.print("How many student's are there? "); int count = input.nextInt(); do{ if (i > count) break; System.out.print("Students name: "); String n = input.nextLine(); System.out.print("Student Score: "); int score = input.nextInt(); i++;} while (i != 0); System.out.println("No students left"); } } Basically I am unsure of how to put my 2 questions that I want to continuously ask over and over again into a loop. As it currently sits it rune/displays but has both quesitons I want to ask on the same line....Also unsure of how I will save the names inputted by the user as well as their scores since I will be recalling names and numbers further in the program.....I was suggested to create a student class and create a student object inside my loop, but frankly I need it explained out a little better. You can create a Student Object with 2 "properties": Name and Score. Create your constructor, accessors, mutators. Then you create an array that is based on the size the user states. To ask 'that' number of times, make use of a for-loop that Scans in name and score. To get the highest score, traverse through the array and use the Student Object's accessor to get the score. Compare to see who's score is highest at the end of traversal and print the score. | ||
EvanED
United States111 Posts
On July 11 2011 04:03 RedJustice wrote: Well I already know Java alright. (Not brilliantly, but have been using it for the past 5 years on and off, so what I don't know I can figure out eventually. I can't necessarily write super clean sexy code in Java, but I can write stuff that works.) I would just like to learn something a bit more professionally standard for the industry I want to work in, and I know it is not Java. If you know Java, you already know most of C#. Microsoft basically took Java, made it less dumb, and called the result C#. [B]OHmmm well for the C++ vs C#, it seems (please correct me if I'm wrong anywhere, just want to make sure I understand right)-- They are similar enough I could understand the other alright if I knew one. C++ seems to be used the most in professional fields. Unfortunately, this is probably true. If C# is easier to work with, and would still give me a pretty good idea of C++, I think I would like to learn C# first, and then maybe I can use C++ later so I have less new things to worry about. If your goal is to go to C++, I'd just make the switch now. C# would teach you maybe a couple small bits about C++ that you don't get from Java (e.g. the ability to do operator overloading), but really it's not worth it. C# is a reasonably good language, and if you wanted to learn it, that's pretty reasonable... but it sounds like C++ is more of an ultimate goal. And if that's the case, and you'd just be using C# as a stepping stone, I think you shouldn't bother. I'm not sure I'm the person to evaluate how worthy a goal "learn C++" is. | ||
Badjas
Netherlands2038 Posts
![]() GHAAAAA! but it's a cool language. Edit: Solved. Always put standard header includes at the the top, BEFORE the inclusions of your own header files. And thanks for the enigma, language designers. I'm sure there are occasions where it is useful to declare a struct as extern (I forgot a semicolon, of course). | ||
EvanED
United States111 Posts
On July 11 2011 04:45 Badjas wrote: I am reminded once again how stupid those compiler error messages are in C++. I've frickin' hacked stuff onto another C++ compiler but I can't for the life of me figure out why it doesn't like my constructor declaration. (and no I'm not gonna show it, it's my first lines of C++ in two years time and this is hella embarrassing ![]() GHAAAAA! but it's a cool language. Don't ever use Latex if you think C++ compiler errors are bad. The errors are no more helpful than "there's an error somewhere in your document" on a far-to-frequent basis. :-) | ||
Siniyas
Germany66 Posts
On July 11 2011 04:36 O3 wrote: You can create a Student Object with 2 "properties": Name and Score. Create your constructor, accessors, mutators. Then you create an array that is based on the size the user states. To ask 'that' number of times, make use of a for-loop that Scans in name and score. To get the highest score, traverse through the array and use the Student Object's accessor to get the score. Compare to see who's score is highest at the end of traversal and print the score. Also the reason your questions are in the same line, is because you use print. Use println, to have a linebreak after the given text. You can also create a buffer for the highest score, so you dont have to make an extra for loop. | ||
Badjas
Netherlands2038 Posts
On July 11 2011 04:48 EvanED wrote: Don't ever use Latex if you think C++ compiler errors are bad. The errors are no more helpful than "there's an error somewhere in your document" on a far-to-frequent basis. :-) I love LaTeX ^_^ | ||
RedJustice
United States1004 Posts
LaTeX satisfied all of my hidden OCDness, lol. Frustrating to work with, but so pretty at the end. XD | ||
AkaHenchway
United States41 Posts
On July 11 2011 04:36 O3 wrote: You can create a Student Object with 2 "properties": Name and Score. Create your constructor, accessors, mutators. Then you create an array that is based on the size the user states. To ask 'that' number of times, make use of a for-loop that Scans in name and score. To get the highest score, traverse through the array and use the Student Object's accessor to get the score. Compare to see who's score is highest at the end of traversal and print the score. We have not gone over arrays in this class (beginning java) . I'm not real sure what you exactly mean by making a student object with 2 properties as well as constructor , accessors, mutators. Think you could link me to an example . | ||
RedJustice
United States1004 Posts
On July 11 2011 04:58 AkaHenchway wrote: We have not gone over arrays in this class (beginning java) . I'm not real sure what you exactly mean by making a student object with 2 properties as well as constructor , accessors, mutators. Think you could link me to an example . What have you gone over in class/what is the concept you are learning atm? | ||
JeffJohnson
Germany62 Posts
On July 11 2011 04:45 Badjas wrote: I am reminded once again how stupid those compiler error messages are in C++. I've frickin' hacked stuff onto another C++ compiler but I can't for the life of me figure out why it doesn't like my constructor declaration. Give the clang compiler a try. It produces much much better error messages than g++ :-) But afaik boost dont work with clan atm ![]() | ||
bautistaaa
United States9 Posts
| ||
japro
172 Posts
On July 11 2011 04:48 EvanED wrote: Don't ever use Latex if you think C++ compiler errors are bad. The errors are no more helpful than "there's an error somewhere in your document" on a far-to-frequent basis. :-) I think template errors in C++ beat latex errors by a fair margin :D. I'm working on a expression template library at the moment and every trivial mistake like missing a const or something will result in multiple errors that explode into pages over pages of unreadable "template traces". | ||
EvanED
United States111 Posts
On July 11 2011 04:49 Badjas wrote: I love LaTeX ^_^ Ugh. I use Latex because I don't know anything better (you probably have to get into some expensive professional book-publishing software or something). But man do I hate it with a passion. :-) On July 11 2011 05:26 japro wrote:I think template errors in C++ beat latex errors by a fair margin :D. I'm working on a expression template library at the moment and every trivial mistake like missing a const or something will result in multiple errors that explode into pages over pages of unreadable "template traces". I'm sure a lot of this is background -- I have a strong C++ background, while my knowledge of Tex/Latex is a lot more hacky and operational. If you throw out the easy Latex errors like "undefined command" ("oh, I made a typo"), a lost of the time in both cases the first thing to do if you don't see what's wrong right away is to head to the line number they give you. A lot of the time that solves it. But after that is where I think they differ. Template errors are awful, but it's very rare that I'll run across one that I can't figure out after looking at for a couple minutes. They really do mean something in the end. But if you contrast that with Latex, a lost of the time the error message is basically nonsensical, and a lot of the time I don't know what to do to solve it other than try something different. A "missing \endcsname" error is essentially useless to me. (Or this.) So for me the difference between those error messages is between "bad=hard to figure out" and "bad=completely meaningless." | ||
AkaHenchway
United States41 Posts
On July 11 2011 05:06 RedJustice wrote: What have you gone over in class/what is the concept you are learning atm? Currently just going over loops right now. | ||
tec27
United States3690 Posts
On July 11 2011 04:16 AkaHenchway wrote: Hey guys having some trouble again (Java). I have looked aroud for some help but every explanation im given is way above my head.....write a program taht prompts the user to enter the number of students and each students name and score, and finally displays the name of the student with the highest score is what I am supposed to be doing. + Show Spoiler + import java.util.Scanner; public class highscore{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int i = 0; System.out.print("How many student's are there? "); int count = input.nextInt(); do{ if (i > count) break; System.out.print("Students name: "); String n = input.nextLine(); System.out.print("Student Score: "); int score = input.nextInt(); i++;} while (i != 0); System.out.println("No students left"); } } Basically I am unsure of how to put my 2 questions that I want to continuously ask over and over again into a loop. As it currently sits it rune/displays but has both quesitons I want to ask on the same line....Also unsure of how I will save the names inputted by the user as well as their scores since I will be recalling names and numbers further in the program.....I was suggested to create a student class and create a student object inside my loop, but frankly I need it explained out a little better. You're trying to overcomplicate what you have to do here. They want you to take in students' names and their respective scores, and return the max score. You're trying to take in students' names and respective scores, store all of those in memory, then iterate over them and return the highest score. This middle part is a huge waste of memory and execution time for this task, since you're already iterating over the names (essentially) when they are input. So instead of trying to store all of the names and scores, just simply store the highest one. Whenever you input a new score, check it against your stored score. If its higher, store the new score and name. If its not, leave the old one. When you get to the end of your inputting phase, you'll have the highest score stored already and can simply print out the name and score. | ||
japro
172 Posts
On July 11 2011 05:49 EvanED wrote: Template errors are awful, but it's very rare that I'll run across one that I can't figure out after looking at for a couple minutes. They really do mean something in the end. Yeah, it's mostly about finding the part where it says "Error:" between all the "instatiated from..." crap. Its basically the monochrome text version of where is Waldo... | ||
Orome
Switzerland11984 Posts
| ||
AkaHenchway
United States41 Posts
On July 11 2011 06:01 tec27 wrote: You're trying to overcomplicate what you have to do here. They want you to take in students' names and their respective scores, and return the max score. You're trying to take in students' names and respective scores, store all of those in memory, then iterate over them and return the highest score. This middle part is a huge waste of memory and execution time for this task, since you're already iterating over the names (essentially) when they are input. So instead of trying to store all of the names and scores, just simply store the highest one. Whenever you input a new score, check it against your stored score. If its higher, store the new score and name. If its not, leave the old one. When you get to the end of your inputting phase, you'll have the highest score stored already and can simply print out the name and score. Yea just realized that not to long ago, here is where I am at so far, still struggling but getting there. + Show Spoiler + import java.util.Scanner; public class highscore{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int i = 0; int hiscore; string hiscorename; System.out.print("How many student's are there? "); int count = input.nextInt(); for(int i = 0; i < count; i++){ System.out.println("Students name: "); string n = input.nextLine(); System.out.println(""); System.out.println("Student Score: "); int score = input.nextInt();} if (score > 0){ score = hiscore; System.out.println(n + " has the highest score with " + hiscore);} if (score > hiscore){ score = hiscore; System.out.println(n + " has the highest score with " + hiscore);} else if (hiscore > score); while (i > count); System.out.println("No students left"); | ||
AkaHenchway
United States41 Posts
| ||
| ||