|
I'm working on a small project, and I've hit a wall. I'm supposed to write my own class (named Student), whose constructor has a number of parameters: a first and last name, three regular test grades, three homework grades, and a grade on a semester final. Using the graded information, I'm supposed to calculate the semester average for that student, then use that average to determine the letter grade. Now, I have to read all the information for each student from a file (their names and graded information), store the information for each student in its own instance of the class (which I think means I'd have to store it in my constructor), call the method I use to calculate the semester average and letter grade, and then take all of that information for each student(the original attributes, the semester average, and letter grade) and store it as its own element in an array of instances of my class Student. From there, I have to call another method to display the attributes of each element of that array - that is, I have to call a print method for each instance of Student that I stored in the array. I'm having a couple of problems with this. I've never had to read data from a file into an instance of a class, so I don't know where to begin using FileReader to read all that data into my constructor. I also don't know how I would make sure that once it reaches the end of a line in my data file, it would proceed to put the next line's data into a new instance of my Student class. I have no problem writing the methods to compute the semester average and to display the data from my constructor, but I'm confused about the array. I'm computing the average and letter grade separately from the constructor, but I still have to take that information, on top of what's in my constructor, and wrap it all together so it can be just one element in my array. I had thought to start like this: code:
I'm really lost here. Any light you all could shine on this would be greatly appreciated. If there's anything I should clarify, let me know and I'll do my best.
|
# ? Feb 8, 2009 22:11 |
|
|
# ? May 8, 2024 06:02 |
|
JulianD posted:I'm working on a small project, and I've hit a wall... The first step is to write the constructor for your Student class by following the spec provided: code:
code:
code:
That will cut the record into individual pieces. So, that data array be of size 9, with data[0] being the first name, data[1] being the last, etc. You can convert Strings to ints with the Integer.parseInt(String) method. Hopefully that will put you on the right track.
|
# ? Feb 8, 2009 23:45 |
|
I wrote a ton of Java in high school and college, and moved into PHP and Ruby on Rails when I took the Webmaster position at the university. I'm looking to start interviewing for developer positions soon and I want to brush up on some enterprise java technologies. Thus far I've been reading the documentation for Spring and Hibernate. Should I also look into frameworks such as Struts or Tapestry or are they going out of style? I'd also like to start playing around with a full blown application server. Tomcat is just for servlets, right? Are there any other free app servers worth fooling around with? Is glassfish worth using yet?
|
# ? Feb 9, 2009 03:19 |
|
Ghotli posted:Tomcat is just for servlets, right? Geronimo is the attempt at a full-fledged application server by assembling the various OSS components.
|
# ? Feb 9, 2009 13:53 |
|
covener posted:Geronimo is the attempt at a full-fledged application server by assembling the various OSS components.
|
# ? Feb 9, 2009 14:36 |
|
Struts and Tapestry are still wanted but are unlikely to be used in projects getting off the ground these days. Weblogic, JBoss, and Tomcat are still kings for "enterprise" application servers IMO. Never got a request for anything else besides Apache from my customers. For educational purposes, Stripes is certainly worth a shot - it looks quite fun, which is frankly a bit rare in the Java world to me. Is there any professional value besides educational ones in messing with Glassfish? I don't know of any prominent organization that's used GlassFish to serve their applications, but maybe I'm missing someone huge that's used it. It may turn out like Django in the Python world though and take off after another year or so. As far as jobs, it looks like few give a crap about your Java skills until you've spent 3+ years with Spring, Hibernate, Jboss, Tomcat, J2EE-specific frameworks, and a major DB or two. Otherwise, it's purely entry level it seems.
|
# ? Feb 9, 2009 17:54 |
|
necrobobsledder posted:Is there any professional value besides educational ones in messing with Glassfish? I don't know of any prominent organization that's used GlassFish to serve their applications, but maybe I'm missing someone huge that's used it. It may turn out like Django in the Python world though and take off after another year or so. Version 3 isn't out yet (it's being timed to coincide with the new servlet spec etc. I think) but I imagine they'll start pushing it harder with that one. Having used JBoss and all that sort of thing I'm of the opinion that things can only get better with app servers for people who use them though. necrobobsledder posted:As far as jobs, it looks like few give a crap about your Java skills until you've spent 3+ years with Spring, Hibernate, Jboss, Tomcat, J2EE-specific frameworks, and a major DB or two. Otherwise, it's purely entry level it seems. That said most people looking for that specific skillset might not have an interesting jobs going...
|
# ? Feb 10, 2009 10:44 |
|
There are also a large number of non-web-related Java programming jobs out there — right now, I'd say it's probably the major cross-platform language for large projects (do not read this as an endorsement of Java over your pet language). Whether there are open non-web-related Java programming positions is, of course, a question about the economy and not languages.
|
# ? Feb 10, 2009 16:51 |
|
Not a CS major but in a CS class that is currently kicking my rear end. My latest set of assignments has been to create our own scanner and iterator classes. Unfortunately each one builds on the next one and we haven't gotten any feedback on our older stuff so I think I've hit a wall with this project. We've been designing classes that scan a string and isolate words and numbers within the string. The trick is, every token was separated by exactly one space. So to do this, I've been finding the spaces and just storing what's between the spaces. Now we have to scan a string that can contain "double quote characters". It also says that these characters are preceded by a backwards slash. So for example, if the input was: code:
code:
I don't mean for this to be a "help me with my homework" post but if anyone has any tips on where I should move from here, I'd really appreciate it.
|
# ? Feb 11, 2009 17:33 |
|
Lord Wexia posted:So my question is, how should I think about this double quote character and can my space-character oriented method still work? Or am I going to have to re-write this? I'm going to assume that you have to do all this stuff on your own and not just rely on some smart other tool or library. Your space-based approach may be rewritten to handle this case as well. There are at least two solutions. One which is more simple but specific to your current problem, and one which is more general. A really simple, but hard to modify and adapt solution would be as follows: simply keep track of whether you are within quotes or not using a Boolean variable. If you are, then all characters you read (until you encounter the closing "-character) should be appended to your current partial result. If you are not within quotes, then continue like you have before with your space-based parser. A nicer approach would look as follows in pseudo code. code:
If you would implement the second solution, you obviously need to perform more error checking and stuff. In particular, you might want to throw the empty string away. ynef fucked around with this message at 18:15 on Feb 11, 2009 |
# ? Feb 11, 2009 18:10 |
|
I need to do a basic loop that will read a list of exam scores given as integer precentages in the range 0 to 100. I need to display the total number of grades and the number of grades in each letter-grade category.
|
# ? Feb 12, 2009 00:56 |
|
Logostomp posted:I need to do a basic loop that will read a list of exam scores given as integer precentages in the range 0 to 100. I need to display the total number of grades and the number of grades in each letter-grade category. That's a great homework assignment. You got a question to go with that?
|
# ? Feb 12, 2009 01:08 |
|
Mill Town posted:That's a great homework assignment. You got a question to go with that? I've got the input working. Here's the question. Write a program to read a list of exam scores given as integer percentages in the range 0 to 100. Display the total number of grades and the number of grades in each letter-grade category as follows: 90 to 100 is an A, 80 to 89 is an B, 70 to 79 is an C, 60 to 69 is an D, 0 to 59 is an F. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is only used to end the loop, so do not use it in the calculations.). For example, if the input is 98, 87, 86, 85, 78, 73, 72, 72, 70, 66, 63, 50, -1 the output would be: Total number of grades = 14 Number of A's = 1 Number of B's = 4 Number of C's = 6 Number of D's = 2 Number of F's = 1
|
# ? Feb 12, 2009 01:18 |
|
Logostomp posted:I've got the input working. Here's the question. I should have been more specific. I mean, what is your question? What, specifically, are you having trouble with in this assignment and what would you like advice on?
|
# ? Feb 12, 2009 01:19 |
|
Logostomp posted:I've got the input working. Here's the question. Not really seeing a question (or why this is even hard) here but make 5 stacks or something. Push the input into the correct stack when read in. Count the data structure for the output.
|
# ? Feb 12, 2009 01:38 |
|
Mill Town posted:I should have been more specific. I mean, what is your question? What, specifically, are you having trouble with in this assignment and what would you like advice on? Putting the numbers in their correct grades.
|
# ? Feb 12, 2009 03:41 |
|
Logostomp posted:Putting the numbers in their correct grades. Do you know how to compare two numbers? Do you know how if works? Edit: Interestingly, the sample output given by your professor is wrong. Here's the right output: Total number of grades = 12 Total number of A's = 1 Total number of B's = 3 Total number of C's = 5 Total number of D's = 2 Total number of F's = 1 Mill Town fucked around with this message at 14:24 on Feb 12, 2009 |
# ? Feb 12, 2009 03:50 |
|
Logostomp posted:Putting the numbers in their correct grades. This isn't the first time you've asked for help with your homework in this very thread. Don't you have some classmates to talk to? Any kind of collaborative spirit in the computer lab?
|
# ? Feb 12, 2009 05:03 |
|
royallthefourth posted:This isn't the first time you've asked for help with your homework in this very thread. Don't you have some classmates to talk to? Any kind of collaborative spirit in the computer lab? I don't mind helping him if he can formulate his question as an actual QUESTION about JAVA like the thread title says. Previously he's been better about it, I don't know why he's having so much trouble now. Three posts about this assignment and none of them contain an actual specific question... Edit: Also, I was bored so I actually did his homework. I'm not gonna show him the answer, though Mill Town fucked around with this message at 14:24 on Feb 12, 2009 |
# ? Feb 12, 2009 14:22 |
|
royallthefourth posted:This isn't the first time you've asked for help with your homework in this very thread. Don't you have some classmates to talk to? Any kind of collaborative spirit in the computer lab? Am I really hurting anybody by asking a question? I'm not asking for the answer. Just asking for some help.
|
# ? Feb 12, 2009 18:37 |
|
Logostomp posted:Am I really hurting anybody by asking a question? I'm not asking for the answer. Just asking for some help. But you are not asking for help, you are asking for us to do your homework. An example of asking for help would be, "How should I store all the numbers as they come in?". Your so called question can be answered by a 1 second google search, you already know how to compare 2 numbers.
|
# ? Feb 12, 2009 18:50 |
|
Logostomp posted:Am I really hurting anybody by asking a question? No, but I was in the mood to use and you were a prime target
|
# ? Feb 12, 2009 18:58 |
|
Logostomp posted:Am I really hurting anybody by asking a question? I'm not asking for the answer. Just asking for some help. Dude, I'm trying to tell you, you need to be very specific with your questions. Your "question" right now, and I use quotes because you didn't actually ask a question, consists of "How do I do this homework assignment?" We don't do that here. Make it more specific, like "how do I count a number of different parameters?" and you'll get useful answers.
|
# ? Feb 13, 2009 06:30 |
|
Anyone know a simple way to send some POST data to a web page using Java? I have a PHP page I want to ping with a single value of data, similar to how a web browser would access the page. Found a few (more complicated) solutions thus far, but I thought someone might have done this before.
|
# ? Feb 15, 2009 04:56 |
|
Cloud Dog posted:Anyone know a simple way to send some POST data to a web page using Java? I have a PHP page I want to ping with a single value of data, similar to how a web browser would access the page. Found a few (more complicated) solutions thus far, but I thought someone might have done this before. simple one here: http://apache.pastebin.ca/1337704 (you may want to change to HTTP/1.1 and add a proper Host: header)
|
# ? Feb 15, 2009 05:15 |
|
If you create a HttpURLConnection from a URL (cast the regular URLConnection), that's a bit more high level and has convenience methods for HTTP-specific functionality.
|
# ? Feb 15, 2009 07:05 |
|
Logostomp posted:Am I really hurting anybody by asking a question? I'm not asking for the answer. Just asking for some help.
|
# ? Feb 15, 2009 19:24 |
|
How do I tell how many elements are in an String array that I've created? If I read in a bunch of stuff to a String foo, then do foo.split() it gives me a String[] but if I want to loop through the elements I don't know how many there are. e: it's foo.split().length. e2: Different question. Is there any way to parse a line by quotes? I can't do foo.split("""); e3: foo.split("\""); Dire Penguin fucked around with this message at 07:32 on Feb 16, 2009 |
# ? Feb 16, 2009 07:03 |
|
Dire Penguin posted:How do I tell how many elements are in an String array that I've created? If I read in a bunch of stuff to a String foo, then do foo.split() it gives me a String[] but if I want to loop through the elements I don't know how many there are. You can also for-each over arrays if you're using JRE5+: code:
|
# ? Feb 16, 2009 14:04 |
|
I am very new to Java, and I am attempting to compile a project found on Source Forge:https://sourceforge.net/projects/opensmus/ Problem: The source code I downloaded seems to require third-party classes/libraries. I know this due to compile errors. I am downloading classes one by one, as the compiler complains. Some of the packages I download then complain about other required third party packages. I have no idea if I will have to download hundreds of packages. This seems horribly inefficient. Is there a way to get a list of all required packages, perhaps via Netbeans or other IDE? Example third-party packages: javax, junit, hamcrest.
|
# ? Feb 17, 2009 20:51 |
|
Why doesn't the regular expression \\Q.\\E\\w\\w\\w/?[\\s$] trigger a match with the line code:
|
# ? Feb 18, 2009 07:10 |
|
Because '$' inside square brackets means a literal dollar sign.
|
# ? Feb 18, 2009 07:33 |
|
Trying to learn basic socket programming in Java, and I'm having a problem. I have a simple client program: code:
code:
|
# ? Feb 18, 2009 21:05 |
|
The client code is the bit that's repeating the first line. In the server you just want, code:
code:
|
# ? Feb 18, 2009 21:28 |
|
Yep that did it, thank you.
|
# ? Feb 18, 2009 21:48 |
|
Captain Pike posted:I am very new to Java, and I am attempting to compile a project found on Source Forge:https://sourceforge.net/projects/opensmus/ Absolutely. Check out Maven. [edit] Maven requires that there is a Maven-specific file, but serious projects use it. If this one doesn't, suggest it! ynef fucked around with this message at 07:38 on Feb 19, 2009 |
# ? Feb 19, 2009 07:35 |
|
Ant is another alternative to Maven and a lot of projects still use ant.
|
# ? Feb 19, 2009 20:27 |
|
I'm primarily a C++ guy, but I'm working on a Java project, and this reference problem has me stumped.code:
In C++, I'd just have the implementation of getArrayListByType() return a pointer to foo and bar, which I could dereference.
|
# ? Feb 20, 2009 01:34 |
|
There is no way to directly achieve that in Java short of storing these references in different objects.
|
# ? Feb 20, 2009 02:32 |
|
|
# ? May 8, 2024 06:02 |
|
For class, we've been assigned to make an 8x8 board for various pieces to move around on. I've run into a problem with user input, specifically dealing with how to handle tokens. I'm using Scanner to break up the input, but the problem is the largest command will have 5 tokens and the shortest will only have one. The way it's set up now is that it needs a command that will use all 5 tokens or else it crashes.code:
I'm still fairly new to java, any help would be appreciated. And just an example of what the user input would look like: "create 4 3 fast flexible" with fast and flexible being different types of pieces. It works fine with a command like that, but crashes with a command like "print"
|
# ? Feb 20, 2009 05:28 |