Results 1 to 20 of 37
Thread: scanner questions
- 10-24-2010, 10:40 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
scanner questions
Write a program that accepts the letter grades for a student, calculates the student's gpa, and prints it out, along with one of the following five messages:
Eligible
Ineligible, taking less than 4 classes
Ineligible, gpa below 2.0
Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
Ineligible, gpa below 2.0 and has F grade
2. Your program must use an appropriate sequence of nested if-else statements to print out the appropriate message.
3. The message "Ineligible, taking less than 4 classes" has priority over the other 3 ineligible cases.
4. The class will not ask the user for how many grades are in a student's report card. The program will continue to read grades until a non-grade character is input. At this point, some type of loop will cease and the program prints the GPA value and the eligibility message.
5. Example of run output: GPA = 3.75 Eligible
6. You do not have to print out any of the individual grades.
7. Your program should allow input of grades in either upper or lower case.
showing this would i need to import a scanner for gpa?
and if i do could it be
Scanner scan = new Scanner ?
-
That's not how to construct a class -- you may need to review your notes on the way to call a constructor, but you will need parenthesis and in the case of Scanner, you will need to pass in a parameter. The tutorial will show you how: Scanning (The Java™ Tutorials > Essential Classes > Basic I/O)
On an unrelated note, you appear to be fragmenting this discussion amongst several threads and have ignored responses to your questions in previous threads. If you want to encourage folks to help you, you should consider replying to the help they give.Last edited by Fubarable; 10-24-2010 at 10:56 PM.
- 10-24-2010, 10:52 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
showing this would i need to import a scanner for gpa?
One way of obtaining the input would be to use an instance of Scanner.
and if i do could it be
Scanner scan = new Scanner ?
No, that is not correct Java syntax. Read your textbook to find out the correct usage of the "new" keyword. And look at the Scanner API docs for the valid constructors you might use. And an example of creating a scanner to read input from the console.
- 10-24-2010, 10:57 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
so basically from the information given above i need to give the letter grades a value from the 1.0 - 4.0 GPA scale .. so far for scanner i have this
Java Code:import java.util.Scanner; public class grades { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); double gpa; } }
- 10-24-2010, 11:00 PM #5
That looks right, now all you need to do is get the gpa from the user using your new scanner.
Sincerely, Joshua Green
Please REP if I help :)
- 10-24-2010, 11:05 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
caould i use if statements to assign the letter values to a numerical value
- 10-24-2010, 11:09 PM #7
- 10-24-2010, 11:10 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
thank you so farr for your help
- 10-24-2010, 11:15 PM #9
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Java Code:Scanner in = new Scanner(System.in);
Yes, that looks a lot better.
so basically from the information given above i need to give the letter grades a value from the 1.0 - 4.0 GPA scale ..
You are not at that point yet. You are still working on the part of the assignment that says "that accepts the letter grades for a student". At this point you should decide how the user is going to input the letter grades: all on one line? On multiple lines? Both?
Extend what you have written to:
* prompt the user (tell them what to enter)
* use the scanner methods to obtain the grade letters one by one
--------
For each grade letter you obtain your program will have to keep track of the information you will need to produce the output. This may be to keep track of the gpa. But a common tactic when you are calculating an average to actually keep track of two things: the total grade points so far and the number of grades entered. Using this information you can calulate the gpa once all the grades are in. In your case you also need a variable to keep track of whether you have seen an 'F' grade as this also has a bearing on the message that will be output.
(The simplest way converting from grade letters to grade points is to write a separate method for this. It can be as straightforward as a bunch of if-elseif-... or a switch statement. The method's argument is the char or String and its return value is the number of grade points.)
Perhaps before you go a lot further with the coding you should stop and figure out a battle plan. You need a plain English (but *very* precise) recipe for how you are going to output the appropriate message: what information you are going to keep track of, how it will be updated for each grade letter, and how it will be used to determine the message.Last edited by pbrockway2; 10-24-2010 at 11:16 PM. Reason: ... very slow ;(
- 10-24-2010, 11:15 PM #10
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
with this code, im trying to get it to print a letter grade given from the if statement of the GPA.. im basically trying to gett when i enter a GPA number from 1.0 to 4.0 it would give me a letter from F,D,C,B,A. Am i on the right track?Java Code:import java.util.Scanner; public class grades { /** * @param args */ public static main(String[] args); boolean t double b { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); double GPA; System.out.println("GPA = "); if (3.0 <= GPA <= 4.0){ System.out.println("A"); } } }
- 10-24-2010, 11:29 PM #11
The syntax is wrong on your if statement. What you need to write is a compound if statement combining two logical calculations. Using the OR operator '||'. Also refer to the following link to get an idea of how to use the scanner class to receive a double from the user: JAVA Scanner Class
Sincerely, Joshua Green
Please REP if I help :)
- 10-24-2010, 11:46 PM #12
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
im having an error. i think i am not using the else if statements correctly this is the code
Java Code:import java.util.Scanner; public class grades { /** * @param args * @return */ public static void main(String[] args); // TODO Auto-generated method stub Scanner in = new Scanner(System.in); double GPA=in.nextDouble(); System.out.println("GPA = "); if ( GPA == 4.0){ System.out.println("A"); }else{ if (GPA >=3.0 || < 4.0) System.out.println("B"); }else{ if (GPA >=2.0 || < 3.0) System.out.println("C"); }else{ if (GPA >=1.0 || < 2.0) System.out.println("D");} else { if (GPA == 0){ System.out.println("F"); }
- 10-25-2010, 12:37 AM #13
The syntax on your "else if" statements is wrong. Instead of writing:
Java Code:}else{ if (GPA >=3.0 || < 4.0) System.out.println("B");
It should look more like:
Java Code:else if( GPA >= 3.0 || (this is wrong, fix syntax here as well) ) { System.out.println("B"); }Sincerely, Joshua Green
Please REP if I help :)
- 10-25-2010, 12:52 AM #14
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
i changed the format of my else if statments thank you. but when i run this code
the code does not print anytihng.. not even the scanner saying "GPA ="? im stuck :/Java Code:mport java.util.Scanner; public class grades { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); double GPA=in.nextDouble(); System.out.println("GPA = "); if ( GPA == 4.0) { System.out.println("A"); } else if (GPA >=3.0 || GPA < 4.0) { System.out.println("B"); } else if (GPA >=2.0 || GPA < 3.0) { System.out.println("C"); } else if (GPA >=1.0 ||GPA < 2.0) { System.out.println("D"); } else if (GPA == 0) { System.out.println("F"); } } }
- 10-25-2010, 01:03 AM #15
The code works fine for me. You have to type in your GPA and hit enter before it will print anything. Maybe you should add a prompt for the user to enter the GPA.
Sincerely, Joshua Green
Please REP if I help :)
- 10-25-2010, 01:07 AM #16
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
when i run the code, there is no prompt that comes up saying "GPA ="
- 10-25-2010, 01:09 AM #17
Look at these lines:
Java Code:double GPA=in.nextDouble(); System.out.println("GPA = ");
Which line do you get the GPA on?Sincerely, Joshua Green
Please REP if I help :)
- 10-25-2010, 01:12 AM #18
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
im a beginner in an AP Computer Science class, the prompt is the print method, and im guessing you get the GPA on the first line?
- 10-25-2010, 01:13 AM #19
- 10-25-2010, 01:19 AM #20
Member
- Join Date
- Oct 2010
- Posts
- 81
- Rep Power
- 0
ok thank you very much. and now i realized how aggravting coding can get. It wants to output a value :/ then saying eligible or not depending on the circumstances above for my assignment.
it says
"Example of run output: GPA = 3.75 Eligible" I did the complete opposite and read the entire assignment wrong :O
Similar Threads
-
Using scanner for CSV
By getName() in forum Advanced JavaReplies: 7Last Post: 06-20-2010, 04:33 PM -
Help With Scanner
By jtmoney0511 in forum New To JavaReplies: 10Last Post: 10-12-2009, 11:24 PM -
Need help with scanner.
By mainy in forum New To JavaReplies: 3Last Post: 07-28-2009, 02:11 PM -
Scanner questions
By Suzanne1187 in forum New To JavaReplies: 12Last Post: 03-12-2009, 02:31 AM -
need help with scanner
By whiterex in forum New To JavaReplies: 1Last Post: 04-22-2008, 01:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks