Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29143 > unrolled thread
| Started by | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| First post | 2014-07-20 21:53 -0700 |
| Last post | 2014-07-30 21:00 -0700 |
| Articles | 17 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-20 21:53 -0700
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-20 21:57 -0700
Re: Class assignment help Roedy Green <see_website@mindprod.com.invalid> - 2014-07-20 22:55 -0700
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-20 23:59 -0700
Re: Class assignment help Tim Slattery <tim@risingdove.com> - 2014-07-21 10:50 -0400
Re: Class assignment help Roedy Green <see_website@mindprod.com.invalid> - 2014-07-21 12:35 -0700
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-21 14:22 -0700
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-21 14:29 -0700
Re: Class assignment help Jeff Higgins <jeff@invalid.invalid> - 2014-07-21 17:30 -0400
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-21 15:26 -0700
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-21 15:34 -0700
Re: Class assignment help Jeff Higgins <jeff@invalid.invalid> - 2014-07-21 18:35 -0400
Re: Class assignment help Jeff Higgins <jeff@invalid.invalid> - 2014-07-21 20:55 -0400
Re: Class assignment help markspace <markspace@nospam.nospam> - 2014-07-22 10:42 -0700
Re: Class assignment help Scott Dunning <scottwd01@gmail.com> - 2014-07-23 17:55 -0700
Re: Class assignment help cdalten@gmail.com - 2014-07-30 20:58 -0700
Re: Class assignment help cdalten@gmail.com - 2014-07-30 21:00 -0700
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-20 21:53 -0700 |
| Subject | Class assignment help |
| Message-ID | <lqi67a$1nt$2@dont-email.me> |
/*Write a java program that prompts the user to enter the number of
students and then each student’s name and score,
* and finally displays the student with highest score and the student
with the second- highest score.
* You are NOT allowed to use ‘Arrays’ for this problem (as we have not
covered arrays yet).
*
* HINT: You do not need to remember all the inputs. You only need to
maintain variables for max and second max
* scores and corresponding names. Whenever you read a new input, you
need to compare it to the so far established
* max & second max scores and change things accordingly. */
import java.util.Scanner;
public class StudentScore {
public static void main(String[] args) {
String studentName, highName, secondHighName;
int score, highScore=0, secondHighScore=0;
int count;
int classSize;
Scanner scan = new Scanner(System.in);
System.out.print("How many students' grades do you want to enter? ");
classSize = scan.nextInt();
for (int i = 0; i < classSize; i++) {
System.out.print("Please enter the students name? ");
studentName = scan.nextLine();
System.out.print("Please enter the students score? ");
score = scan.nextInt();
if (score >= secondHighScore) {
secondHighScore = highScore;
secondHighName = highName;
highScore = score;
highName = studentName;
}
}
System.out.print("Student with the highest score: " + highName + " " +
highScore);
System.out.print("Student with the second highest score: " +
secondHighName + " " + secondHighScore);
}
}
[toc] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-20 21:57 -0700 |
| Message-ID | <lqi6fl$3b3$1@dont-email.me> |
| In reply to | #29143 |
On 7/20/14, 9:53 PM, Scott Dunning wrote:
I sent that message prematurely. I'm in a class in college and we're
doing Java. This is only my 4th class so I'm super new (be nice). I'm
getting an error that I don't understand...
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at StudentScore.StudentScore.main(StudentScore.java:14)
> /*Write a java program that prompts the user to enter the number of
> students and then each student’s name and score,
> * and finally displays the student with highest score and the student
> with the second- highest score.
> * You are NOT allowed to use ‘Arrays’ for this problem (as we have not
> covered arrays yet).
> *
> * HINT: You do not need to remember all the inputs. You only need to
> maintain variables for max and second max
> * scores and corresponding names. Whenever you read a new input, you
> need to compare it to the so far established
> * max & second max scores and change things accordingly. */
>
>
> import java.util.Scanner;
>
> public class StudentScore {
>
> public static void main(String[] args) {
>
> String studentName, highName, secondHighName;
> int score, highScore=0, secondHighScore=0;
> int count;
> int classSize;
>
> Scanner scan = new Scanner(System.in);
>
> System.out.print("How many students' grades do you want to
> enter? ");
> classSize = scan.nextInt();
>
> for (int i = 0; i < classSize; i++) {
> System.out.print("Please enter the students name? ");
> studentName = scan.nextLine();
>
> System.out.print("Please enter the students score? ");
> score = scan.nextInt();
>
> if (score >= secondHighScore) {
> secondHighScore = highScore;
> secondHighName = highName;
> highScore = score;
> highName = studentName;
>
> }
> }
>
> System.out.print("Student with the highest score: " + highName
> + " " + highScore);
> System.out.print("Student with the second highest score: " +
> secondHighName + " " + secondHighScore);
>
> }
> }
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-07-20 22:55 -0700 |
| Message-ID | <tnaps91uuvk0tlsan8e2f0fg930u6vvo9i@4ax.com> |
| In reply to | #29144 |
On Sun, 20 Jul 2014 21:57:40 -0700, Scott Dunning <scottwd01@gmail.com> wrote, quoted or indirectly quoted someone who said : >Exception in thread "main" java.lang.Error: Unresolved compilation problem: That is the first time I have ever seen that message. How did you compile this? It was not javac.exe was it? Literally it is saying that there were compile time errors you ignored, but it tried to run anyway. What error messages came out at compile time? -- Roedy Green Canadian Mind Products http://mindprod.com Science is what we understand well enough to explain to a computer. Art is everything else we do. ~ Donald Ervin Knuth (born: 1938-01-10 age: 76)
[toc] | [prev] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-20 23:59 -0700 |
| Message-ID | <lqidjb$8l5$1@dont-email.me> |
| In reply to | #29146 |
On 7/20/14, 10:55 PM, Roedy Green wrote:
> On Sun, 20 Jul 2014 21:57:40 -0700, Scott Dunning
> <scottwd01@gmail.com> wrote, quoted or indirectly quoted someone who
> said :
>
>> Exception in thread "main" java.lang.Error: Unresolved compilation problem:
>
> That is the first time I have ever seen that message. How did you
> compile this? It was not javac.exe was it?
>
> Literally it is saying that there were compile time errors you
> ignored, but it tried to run anyway.
>
> What error messages came out at compile time?
>
That is in the IDE eclipse. I just tried to compile it in a text editor
with terminal and these are the errors I'm getting. I'm not really sure
what it means. Doesn't initializing it mean to declare the variables?
StudentScore.java:35: error: variable highName might not have been
initialized
secondHighName = highName;
^
StudentScore.java:42: error: variable highName might not have been
initialized
System.out.print("Student with the highest score: " + highName + " " +
highScore);
^
StudentScore.java:43: error: variable secondHighName might not have been
initialized
System.out.print("Student with the second highest score: " +
secondHighName + " " + secondHighScore);
^
3 errors
[toc] | [prev] | [next] | [standalone]
| From | Tim Slattery <tim@risingdove.com> |
|---|---|
| Date | 2014-07-21 10:50 -0400 |
| Message-ID | <jv9qs99vjkbrit3qjtnvmtn1853ise0r9b@4ax.com> |
| In reply to | #29149 |
Scott Dunning <scottwd01@gmail.com> wrote: >what it means. Doesn't initializing it mean to declare the variables? No, it means to assign them a value. You assigned values to highScore and secondHignScore in the declarations, but that syntax doesn't work for String. You'll need to assign them a dummy value (highName = "no name yet";) or an empty string (secondHighName = "";) to get rid of the error messages. -- Tim Slattery tim <at> risingdove <dot> com
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-07-21 12:35 -0700 |
| Message-ID | <qqqqs9lhgordsok2srcsjm52sfuv6qh2jh@4ax.com> |
| In reply to | #29158 |
On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> wrote, quoted or indirectly quoted someone who said : >You'll need to assign them a dummy value (highName = "no >name yet";) or an empty string (secondHighName = "";) to get rid of null will keep it happy. You might later get an NullPointerException if you don't get a real value in there soon enough. -- Roedy Green Canadian Mind Products http://mindprod.com Science is what we understand well enough to explain to a computer. Art is everything else we do. ~ Donald Ervin Knuth (born: 1938-01-10 age: 76)
[toc] | [prev] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-21 14:22 -0700 |
| Message-ID | <lqk06a$pg0$1@dont-email.me> |
| In reply to | #29163 |
On 7/21/14, 12:35 PM, Roedy Green wrote: > On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> > wrote, quoted or indirectly quoted someone who said : > >> You'll need to assign them a dummy value (highName = "no >> name yet";) or an empty string (secondHighName = "";) to get rid of > > null will keep it happy. You might later get an NullPointerException > if you don't get a real value in there soon enough. > Oh ok, I didn't realize. I thought I could just declare them like you do with an int or double...Thank you, I'll see if I can get it working now. Scott
[toc] | [prev] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-21 14:29 -0700 |
| Message-ID | <lqk0k5$sb1$1@dont-email.me> |
| In reply to | #29163 |
On 7/21/14, 12:35 PM, Roedy Green wrote: > On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> > wrote, quoted or indirectly quoted someone who said : > >> You'll need to assign them a dummy value (highName = "no >> name yet";) or an empty string (secondHighName = "";) to get rid of > > null will keep it happy. You might later get an NullPointerException > if you don't get a real value in there soon enough. > So I got it "working" which is to say it will run. However, after it asks to how many students names and grades I'd like to enter it asks both of the next questions at the same time and that then causes an error. Since it's in the for loop I'm not sure how to get it to ask the questions separately. Any tips?
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-07-21 17:30 -0400 |
| Message-ID | <lqk199$36f$1@dont-email.me> |
| In reply to | #29166 |
On 07/21/2014 05:29 PM, Scott Dunning wrote: > On 7/21/14, 12:35 PM, Roedy Green wrote: >> On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> >> wrote, quoted or indirectly quoted someone who said : >> >>> You'll need to assign them a dummy value (highName = "no >>> name yet";) or an empty string (secondHighName = "";) to get rid of >> >> null will keep it happy. You might later get an NullPointerException >> if you don't get a real value in there soon enough. >> > > > So I got it "working" which is to say it will run. However, after it > asks to how many students names and grades I'd like to enter it asks > both of the next questions at the same time and that then causes an > error. Since it's in the for loop I'm not sure how to get it to ask the > questions separately. Any tips? java.io.Console - if you're allowed to use it. <http://docs.oracle.com/javase/tutorial/essential/io/cl.html>
[toc] | [prev] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-21 15:26 -0700 |
| Message-ID | <lqk3tm$mif$1@dont-email.me> |
| In reply to | #29167 |
On 7/21/14, 2:30 PM, Jeff Higgins wrote: > On 07/21/2014 05:29 PM, Scott Dunning wrote: >> On 7/21/14, 12:35 PM, Roedy Green wrote: >>> On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> >>> wrote, quoted or indirectly quoted someone who said : >>> >>>> You'll need to assign them a dummy value (highName = "no >>>> name yet";) or an empty string (secondHighName = "";) to get rid of >>> >>> null will keep it happy. You might later get an NullPointerException >>> if you don't get a real value in there soon enough. >>> >> >> >> So I got it "working" which is to say it will run. However, after it >> asks to how many students names and grades I'd like to enter it asks >> both of the next questions at the same time and that then causes an >> error. Since it's in the for loop I'm not sure how to get it to ask the >> questions separately. Any tips? > > java.io.Console - if you're allowed to use it. > <http://docs.oracle.com/javase/tutorial/essential/io/cl.html> > Thanks for the suggestion Jeff but I'm not sure we're allowed to use that, we haven't learned it yet. I tried creating a separate for loop for each question but that doesn't work either. Any suggestions of the simpler kind?
[toc] | [prev] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-21 15:34 -0700 |
| Message-ID | <lqk4df$phm$1@dont-email.me> |
| In reply to | #29167 |
On 7/21/14, 2:30 PM, Jeff Higgins wrote: > On 07/21/2014 05:29 PM, Scott Dunning wrote: >> On 7/21/14, 12:35 PM, Roedy Green wrote: >>> On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> >>> wrote, quoted or indirectly quoted someone who said : >>> >>>> You'll need to assign them a dummy value (highName = "no >>>> name yet";) or an empty string (secondHighName = "";) to get rid of >>> >>> null will keep it happy. You might later get an NullPointerException >>> if you don't get a real value in there soon enough. >>> >> >> >> So I got it "working" which is to say it will run. However, after it >> asks to how many students names and grades I'd like to enter it asks >> both of the next questions at the same time and that then causes an >> error. Since it's in the for loop I'm not sure how to get it to ask the >> questions separately. Any tips? > > java.io.Console - if you're allowed to use it. > <http://docs.oracle.com/javase/tutorial/essential/io/cl.html> > I just stumbled onto something called hasNext, will something like that work you think, provided I can figure out how to use it?
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-07-21 18:35 -0400 |
| Message-ID | <lqk532$tup$1@dont-email.me> |
| In reply to | #29172 |
On 07/21/2014 06:34 PM, Scott Dunning wrote: > On 7/21/14, 2:30 PM, Jeff Higgins wrote: >> On 07/21/2014 05:29 PM, Scott Dunning wrote: >>> On 7/21/14, 12:35 PM, Roedy Green wrote: >>>> On Mon, 21 Jul 2014 10:50:22 -0400, Tim Slattery <tim@risingdove.com> >>>> wrote, quoted or indirectly quoted someone who said : >>>> >>>>> You'll need to assign them a dummy value (highName = "no >>>>> name yet";) or an empty string (secondHighName = "";) to get rid of >>>> >>>> null will keep it happy. You might later get an NullPointerException >>>> if you don't get a real value in there soon enough. >>>> >>> >>> >>> So I got it "working" which is to say it will run. However, after it >>> asks to how many students names and grades I'd like to enter it asks >>> both of the next questions at the same time and that then causes an >>> error. Since it's in the for loop I'm not sure how to get it to ask the >>> questions separately. Any tips? >> >> java.io.Console - if you're allowed to use it. >> <http://docs.oracle.com/javase/tutorial/essential/io/cl.html> >> > I just stumbled onto something called hasNext, will something like that > work you think, provided I can figure out how to use it? > > Please don't stumble, proceed with deliberation. <http://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html> Paper and pencil, although somewhat dated, can be very helpful.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-07-21 20:55 -0400 |
| Message-ID | <lqkd9v$da4$1@dont-email.me> |
| In reply to | #29174 |
On 07/21/2014 06:35 PM, Jeff Higgins wrote: > Paper and pencil, although somewhat dated, can be very helpful. > Oops. Should have been: Paper, pencil and pseudocode, although somewhat dated, can be very helpful. <http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html> Unfortunately, this link seems to be down at the moment. You may need to look for a cached version.
[toc] | [prev] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2014-07-22 10:42 -0700 |
| Message-ID | <lqm7r0$cj3$2@dont-email.me> |
| In reply to | #29178 |
On 7/21/2014 5:55 PM, Jeff Higgins wrote: > On 07/21/2014 06:35 PM, Jeff Higgins wrote: > >> Paper and pencil, although somewhat dated, can be very helpful. >> > Oops. Should have been: > Paper, pencil and pseudocode, although somewhat dated, can be very helpful. > <http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html> > Unfortunately, this link seems to be down at the moment. > You may need to look for a cached version. > The "Beginner" and "Debugging" sections of this website might help: http://www.patriciashanahan.com/
[toc] | [prev] | [next] | [standalone]
| From | Scott Dunning <scottwd01@gmail.com> |
|---|---|
| Date | 2014-07-23 17:55 -0700 |
| Message-ID | <lqplcm$th9$1@dont-email.me> |
| In reply to | #29200 |
On 7/22/14, 10:42 AM, markspace wrote: > On 7/21/2014 5:55 PM, Jeff Higgins wrote: >> On 07/21/2014 06:35 PM, Jeff Higgins wrote: >> >>> Paper and pencil, although somewhat dated, can be very helpful. >>> >> Oops. Should have been: >> Paper, pencil and pseudocode, although somewhat dated, can be very >> helpful. >> <http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html> >> Unfortunately, this link seems to be down at the moment. >> You may need to look for a cached version. >> > > The "Beginner" and "Debugging" sections of this website might help: > > http://www.patriciashanahan.com/ > > Thank you mark, I was able to figure out that I needed a new scanner in there between the questions. Also, my conditionals weren't correct either. Thanks for are your help!! Scott
[toc] | [prev] | [next] | [standalone]
| From | cdalten@gmail.com |
|---|---|
| Date | 2014-07-30 20:58 -0700 |
| Message-ID | <10bfe49d-5108-43be-8287-05a0fd1bc753@googlegroups.com> |
| In reply to | #29247 |
And the final solution is? Because the solution isn't clear to me. Chad
[toc] | [prev] | [next] | [standalone]
| From | cdalten@gmail.com |
|---|---|
| Date | 2014-07-30 21:00 -0700 |
| Message-ID | <f109f6ab-831e-4f74-abf5-15e66bf424ee@googlegroups.com> |
| In reply to | #29247 |
And the final solution is? Because the solution isn't clear to me. Chad
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web