Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1919 > unrolled thread
| Started by | ericmiranda7@gmail.com |
|---|---|
| First post | 2012-07-01 09:18 -0700 |
| Last post | 2012-07-01 17:02 -0700 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.java.help
My first program = Quiz :D ericmiranda7@gmail.com - 2012-07-01 09:18 -0700
Re: My first program = Quiz :D Patricia Shanahan <pats@acm.org> - 2012-07-01 09:33 -0700
Re: My first program = Quiz :D ericmiranda7@gmail.com - 2012-07-01 09:47 -0700
Re: My first program = Quiz :D Patricia Shanahan <pats@acm.org> - 2012-07-01 09:57 -0700
Re: My first program = Quiz :D markspace <-@.> - 2012-07-01 10:11 -0700
Re: My first program = Quiz :D Lew <noone@lewscanon.com> - 2012-07-01 10:20 -0700
Re: My first program = Quiz :D ericmiranda7@gmail.com - 2012-07-01 10:20 -0700
Re: My first program = Quiz :D Patricia Shanahan <pats@acm.org> - 2012-07-01 10:59 -0700
Re: My first program = Quiz :D Roedy Green <see_website@mindprod.com.invalid> - 2012-07-03 05:16 -0700
Re: My first program = Quiz :D Roedy Green <see_website@mindprod.com.invalid> - 2012-07-01 17:02 -0700
| From | ericmiranda7@gmail.com |
|---|---|
| Date | 2012-07-01 09:18 -0700 |
| Subject | My first program = Quiz :D |
| Message-ID | <9c74bdc0-3238-4124-afcf-154eb305e5ae@googlegroups.com> |
Alright, here is my first program. Just testing it.
----------------------------------------
import java.util.Scanner;
public class quiz {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner myScanner = new Scanner(System.in);
String thisString;
double points = 0;
double total;
System.out.println("Did Germany win vs. Portugal? Yes or no");
thisString = myScanner.nextLine();
if (thisString.equals("Yes")) {
System.out.println("That is correct! Plus points!");
total = points + 1;
System.out.println("Is the Galaxy Tab android?");
thisString = myScanner.nextLine();
if (thisString.equals("Yes")) {
System.out.println("That is correct. Plus points!");
total = points + 1;
}
}
}
}
---------------------------------------------------------
Now, my question is -
I wrote the statement(total = points + 1;)twice. Even though I answered "yes
(the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
[toc] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-07-01 09:33 -0700 |
| Message-ID | <Cb-dnTP1TplI5m3SnZ2dnUVZ_hudnZ2d@earthlink.com> |
| In reply to | #1919 |
On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
> Alright, here is my first program. Just testing it.
>
> ----------------------------------------
> import java.util.Scanner;
> public class quiz {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> Scanner myScanner = new Scanner(System.in);
>
> String thisString;
> double points = 0;
> double total;
>
> System.out.println("Did Germany win vs. Portugal? Yes or no");
> thisString = myScanner.nextLine();
>
> if (thisString.equals("Yes")) {
> System.out.println("That is correct! Plus points!");
> total = points + 1;
> System.out.println("Is the Galaxy Tab android?");
> thisString = myScanner.nextLine();
> if (thisString.equals("Yes")) {
> System.out.println("That is correct. Plus points!");
> total = points + 1;
> }
> }
> }
> }
> ---------------------------------------------------------
> Now, my question is -
> I wrote the statement(total = points + 1;)twice. Even though I answered "yes
> (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
>
points is always zero - none of your code changes it - so (points + 1)
is always one.
Why the separate variables "points" and "total"?
Patricia
[toc] | [prev] | [next] | [standalone]
| From | ericmiranda7@gmail.com |
|---|---|
| Date | 2012-07-01 09:47 -0700 |
| Message-ID | <e50579ae-836c-46c5-952b-0cfdbfcbd7a8@googlegroups.com> |
| In reply to | #1920 |
On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
> > Alright, here is my first program. Just testing it.
> >
> > ----------------------------------------
> > import java.util.Scanner;
> > public class quiz {
> >
> > /**
> > * @param args
> > */
> > public static void main(String[] args) {
> > // TODO Auto-generated method stub
> > Scanner myScanner = new Scanner(System.in);
> >
> > String thisString;
> > double points = 0;
> > double total;
> >
> > System.out.println("Did Germany win vs. Portugal? Yes or no");
> > thisString = myScanner.nextLine();
> >
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct! Plus points!");
> > total = points + 1;
> > System.out.println("Is the Galaxy Tab android?");
> > thisString = myScanner.nextLine();
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct. Plus points!");
> > total = points + 1;
> > }
> > }
> > }
> > }
> > ---------------------------------------------------------
> > Now, my question is -
> > I wrote the statement(total = points + 1;)twice. Even though I answered "yes
> > (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
> >
>
> points is always zero - none of your code changes it - so (points + 1)
> is always one.
>
> Why the separate variables "points" and "total"?
>
> Patricia
I'm a newbie, and I really don't know why I did that. Could you tell me how to update the points variable? I'd much appreciate it. Thanks.
On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
> > Alright, here is my first program. Just testing it.
> >
> > ----------------------------------------
> > import java.util.Scanner;
> > public class quiz {
> >
> > /**
> > * @param args
> > */
> > public static void main(String[] args) {
> > // TODO Auto-generated method stub
> > Scanner myScanner = new Scanner(System.in);
> >
> > String thisString;
> > double points = 0;
> > double total;
> >
> > System.out.println("Did Germany win vs. Portugal? Yes or no");
> > thisString = myScanner.nextLine();
> >
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct! Plus points!");
> > total = points + 1;
> > System.out.println("Is the Galaxy Tab android?");
> > thisString = myScanner.nextLine();
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct. Plus points!");
> > total = points + 1;
> > }
> > }
> > }
> > }
> > ---------------------------------------------------------
> > Now, my question is -
> > I wrote the statement(total = points + 1;)twice. Even though I answered "yes
> > (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
> >
>
> points is always zero - none of your code changes it - so (points + 1)
> is always one.
>
> Why the separate variables "points" and "total"?
>
> Patricia
On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
> > Alright, here is my first program. Just testing it.
> >
> > ----------------------------------------
> > import java.util.Scanner;
> > public class quiz {
> >
> > /**
> > * @param args
> > */
> > public static void main(String[] args) {
> > // TODO Auto-generated method stub
> > Scanner myScanner = new Scanner(System.in);
> >
> > String thisString;
> > double points = 0;
> > double total;
> >
> > System.out.println("Did Germany win vs. Portugal? Yes or no");
> > thisString = myScanner.nextLine();
> >
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct! Plus points!");
> > total = points + 1;
> > System.out.println("Is the Galaxy Tab android?");
> > thisString = myScanner.nextLine();
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct. Plus points!");
> > total = points + 1;
> > }
> > }
> > }
> > }
> > ---------------------------------------------------------
> > Now, my question is -
> > I wrote the statement(total = points + 1;)twice. Even though I answered "yes
> > (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
> >
>
> points is always zero - none of your code changes it - so (points + 1)
> is always one.
>
> Why the separate variables "points" and "total"?
>
> Patricia
On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
> > Alright, here is my first program. Just testing it.
> >
> > ----------------------------------------
> > import java.util.Scanner;
> > public class quiz {
> >
> > /**
> > * @param args
> > */
> > public static void main(String[] args) {
> > // TODO Auto-generated method stub
> > Scanner myScanner = new Scanner(System.in);
> >
> > String thisString;
> > double points = 0;
> > double total;
> >
> > System.out.println("Did Germany win vs. Portugal? Yes or no");
> > thisString = myScanner.nextLine();
> >
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct! Plus points!");
> > total = points + 1;
> > System.out.println("Is the Galaxy Tab android?");
> > thisString = myScanner.nextLine();
> > if (thisString.equals("Yes")) {
> > System.out.println("That is correct. Plus points!");
> > total = points + 1;
> > }
> > }
> > }
> > }
> > ---------------------------------------------------------
> > Now, my question is -
> > I wrote the statement(total = points + 1;)twice. Even though I answered "yes
> > (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
> >
>
> points is always zero - none of your code changes it - so (points + 1)
> is always one.
>
> Why the separate variables "points" and "total"?
>
> Patricia
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-07-01 09:57 -0700 |
| Message-ID | <W7Wdnckxx6voHG3SnZ2dnUVZ_sSdnZ2d@earthlink.com> |
| In reply to | #1921 |
On 7/1/2012 9:47 AM, ericmiranda7@gmail.com wrote: > On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote: ... >> Why the separate variables "points" and "total"? >> >> Patricia > > I'm a newbie, and I really don't know why I did that. Could you tell me how to update the points variable? I'd much appreciate it. Thanks. I think you need to go back to whatever book or tutorial you are using, and re-read the basics of variables and assignment statements. Patricia
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-07-01 10:11 -0700 |
| Message-ID | <jsq0bl$c7s$1@dont-email.me> |
| In reply to | #1921 |
On 7/1/2012 9:47 AM, ericmiranda7@gmail.com wrote:
>> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
>>> import java.util.Scanner;
>>> public class quiz {
>>>
>
> I'm a newbie, and I really don't know why I did that. Could you tell
> me how to update the points variable? I'd much appreciate it.
> Thanks.
>
To elaborate on Patricia's statement a bit, your code looks like a class
assignment. The "quiz" name is a dead give-away. You should really
talk to your instructor or TA, they're the ones who know what parts of
your assignment you should be doing yourself and what parts you're
allowed to get help on. We're all kinda allergic to academic plagiarism
here, which includes getting others to do your assignments for you.
If this really is not classwork, where did you get the "quiz" from? Do
you have a link?
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-07-01 10:20 -0700 |
| Message-ID | <jsq0s7$aoi$1@news.albasani.net> |
| In reply to | #1921 |
ericmiranda7... wrote:
> Patricia Shanahan wrote:
>> ericmiranda7... wrote:
>>> Alright, here is my first program. Just testing it.
>>>
>>> ----------------------------------------
>>> import java.util.Scanner;
>>> public class quiz {
Just a side note, but when you're beginning it's better to establish good
habits than to have unlearn bad ones once you're more knowledgeable. In this
case I'm referring to source-code formatting conventions, which are
more-or-less universal for Java based on the standard in play since 1999.
<http://www.oracle.com/technetwork/java/codeconv-138413.html>
To fix your code to comply, spell type names (like 'quiz') with an initial
upper-case letter ('Quiz').
Indent 2 or 4 spaces per logical nesting level. (Never use TAB characters to
indent).
Fill out your Javadoc comments (the ones that start with /** ) completely.
Get rid of your template "// TODO Auto-generated" lines.
I'll return to your actual question below.
>>> /**
>>> * @param args
>>> */
>>> public static void main(String[] args) {
>>> // TODO Auto-generated method stub
>>> Scanner myScanner = new Scanner(System.in);
>>>
>>> String thisString;
Declare variables at the point of use. And use meaningful names. It isn't
important that this is "this string" but that it represents user input.
>>> double points = 0;
Just '0', with no decimal point, is an 'int' constant. It's better style to
initialize a double variable with a double constant.
>>> double total;
>>>
>>> System.out.println("Did Germany win vs. Portugal? Yes or no");
>>> thisString = myScanner.nextLine();
String userInput = myScanner.nextLine();
>>> if (thisString.equals("Yes")) {
>>> System.out.println("That is correct! Plus points!");
>>> total = points + 1;
See how you changed the value of 'total'? You can do the same sort of thing
with 'points'.
points = points + 1;
Of course, 'points' will need an initial value for that to work.
>>> System.out.println("Is the Galaxy Tab android?");
>>> thisString = myScanner.nextLine();
>>> if (thisString.equals("Yes")) {
>>> System.out.println("That is correct. Plus points!");
>>> total = points + 1;
>>> }
>>> }
>>> }
>>> }
>>> ---------------------------------------------------------
>>> Now, my question is -
>>> I wrote the statement(total = points + 1;)twice. Even though I answered "yes
>>> (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
>>
>> points is always zero - none of your code changes it - so (points + 1)
>> is always one.
>>
>> Why the separate variables "points" and "total"?
>>
>> Patricia
Don't quote sigs.
> I'm a newbie, and I really don't know why I did that. Could you tell me how to update the points variable? I'd much appreciate it. Thanks.
Don't repeat the entire post twice.
> On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
>> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
>>> Alright, here is my first program. Just testing it.
>>>
>>> ----------------------------------------
>>> import java.util.Scanner;
>>> public class quiz {
... [snip] ...
>>
>> Why the separate variables "points" and "total"?
Don't repeat the entire post three times.
> On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
>> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
>>> Alright, here is my first program. Just testing it.
>>>
>>> ----------------------------------------
>>> import java.util.Scanner;
>>> public class quiz {
... [snip] ...
>>
>> Why the separate variables "points" and "total"?
My God, man!
> On Sunday, July 1, 2012 10:03:25 PM UTC+5:30, Patricia Shanahan wrote:
>> On 7/1/2012 9:18 AM, ericmiranda7@gmail.com wrote:
>>> Alright, here is my first program. Just testing it.
>>>
>>> ----------------------------------------
>>> import java.util.Scanner;
>>> public class quiz {
>>>
... [snip] ...
>>
>> Why the separate variables "points" and "total"?
Are you quite certain you posted the same material enough times?
Read the official tutorials.
<http://www.oracle.com/technetwork/java/index-jsp-135888.html>
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | ericmiranda7@gmail.com |
|---|---|
| Date | 2012-07-01 10:20 -0700 |
| Message-ID | <fdfa4e75-4e4c-4df6-ac47-06fa88c1b721@googlegroups.com> |
| In reply to | #1919 |
On Sunday, July 1, 2012 9:48:55 PM UTC+5:30, ericmi...@gmail.com wrote:
> Alright, here is my first program. Just testing it.
>
> ----------------------------------------
> import java.util.Scanner;
> public class quiz {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> Scanner myScanner = new Scanner(System.in);
>
> String thisString;
> double points = 0;
> double total;
>
> System.out.println("Did Germany win vs. Portugal? Yes or no");
> thisString = myScanner.nextLine();
>
> if (thisString.equals("Yes")) {
> System.out.println("That is correct! Plus points!");
> total = points + 1;
> System.out.println("Is the Galaxy Tab android?");
> thisString = myScanner.nextLine();
> if (thisString.equals("Yes")) {
> System.out.println("That is correct. Plus points!");
> total = points + 1;
> }
> }
> }
> }
> ---------------------------------------------------------
> Now, my question is -
> I wrote the statement(total = points + 1;)twice. Even though I answered "yes
> (the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers.
Oh uh-... No, this isn't a class project/assignment. I'm 15 Years, and I'm doing this as a hobby. The "Quiz" comes from teaching myself some basic Shell Scripting, and I wanted to master the "if" and so on. And the quiz seemed to have enough 'if' :)
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-07-01 10:59 -0700 |
| Message-ID | <ML-dnSfPUqRkEm3SnZ2dnUVZ_i2dnZ2d@earthlink.com> |
| In reply to | #1925 |
On 7/1/2012 10:20 AM, ericmiranda7@gmail.com wrote: ... > Oh uh-... No, this isn't a class project/assignment. I'm 15 Years, > and I'm doing this as a hobby. The "Quiz" comes from teaching myself > some basic Shell Scripting, and I wanted to master the "if" and so > on. And the quiz seemed to have enough 'if' :) > Do you have a book or on-line tutorial on Java programming? It is not something I would recommend trying to learn by guessing, or by asking questions one at a time when you get something wrong. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-07-03 05:16 -0700 |
| Message-ID | <g7o5v7dk2dipiueferhnp4obpmkou09ulj@4ax.com> |
| In reply to | #1926 |
On Sun, 01 Jul 2012 10:59:21 -0700, Patricia Shanahan <pats@acm.org> wrote, quoted or indirectly quoted someone who said : >Do you have a book or on-line tutorial on Java programming? You don't need an up-to-date text. Used book stores should have some almost free. If there is a Java User Group where you live, likely members will have some slightly out of date texts they would give you free. Your guessing approach reminds me of the way I learned 7044 assembler. There were no texts available when I was 15, so I just studied listings from sample FORTRAN programs. I still recall my joy at suddenly figuring out the idea that an address was just a number that you could do arithmetic on. Another was figuring out that some arithmetic was done an assembly time and some at run time. These are very obvious ideas once you see them, but are quite baffling until that point. -- Roedy Green Canadian Mind Products http://mindprod.com Why do so many operating systems refuse to define a standard temporary file marking mechanism? It could be a reserved lead character such as the ~ or a reserved extension such as .tmp. It could be a file attribute bit. Because they refuse, there is no fool-proof way to scan a disk for orphaned temporary files and delete them. Further, you can't tell where the orhaned files ame from. This means the hard disks gradually fill up with garbage.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-07-01 17:02 -0700 |
| Message-ID | <n5p1v75qrma1fn0b9lvntnhr40o3vthgim@4ax.com> |
| In reply to | #1919 |
On Sun, 1 Jul 2012 09:18:55 -0700 (PDT), ericmiranda7@gmail.com wrote, quoted or indirectly quoted someone who said : >--------------------------------------------------------- >Now, my question is - >I wrote the statement(total = points + 1;)twice. Even though I answered "yes >(the correct answer to each question)twice my total points came to 1. Should they not add up and become two? Thank-you for the answers. Your IDE has a trace. Watch it calculate. Or pepper your code with out.println to see the intermediate results. points = 0. points +1 = 1 total = points thus gives 1 You want something like this total ++; or total += points; -- Roedy Green Canadian Mind Products http://mindprod.com Why do so many operating systems refuse to define a standard temporary file marking mechanism? It could be a reserved lead character such as the ~ or a reserved extension such as .tmp. It could be a file attribute bit. Because they refuse, there is no fool-proof way to scan a disk for orphaned temporary files and delete them. Further, you can't tell where the orhaned files ame from. This means the hard disks gradually fill up with garbage.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web