Results 1 to 6 of 6
  1. #1
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Scanner, if (if/else) and loop

    Scanner, if (if/else) and loop-4.jpg

    This is what I have so far, which I know is wrong, but I am referencing Google:

    import java.util.Scanner;

    public class evaluateGrade {
    public static void main(String[] args) {
    Scanner console = new Scanner(System.in);

    public static double grade(int score) {
    double grade = (score - 60) / 10.0;
    return Math.max(1, grade);
    }

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Scanner, if (if/else) and loop

    1. Please surround your code with [code][/code] tags to make it easier to read.
    2. Your code isn't valid - you should add braces where necessary.
    3. Can you tell us specifically what it is you're having trouble with? It is getting the input? Or what to do with it? Or something else?

  3. #3
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: Scanner, if (if/else) and loop

    Java Code:
    import java.util.Scanner;
    
    public class evaluateGrade {
    public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    
    public static double grade(int score) { 
    double grade = (score - 60) / 10.0; 
    return Math.max(1, grade); 
    }
    If I knew where to add the braces & how to make the program compile, I would not be here... I do not know how to make it work or how to add the numbers and stuff. Please, do not refer me to a book, like seriously.

  4. #4
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Scanner, if (if/else) and loop

    I didn't refer you to a book. I was simply giving you some tips and attempting to narrow down where your problem was since your question was extremely vague.

    Braces { and } are used to indicate blocks or sections of code. Your class, evaluateGrade, should entirely contain the methods (main and grade). Similarly, the braces associated with the methods should entirely contain their contents. The code you supplied is missing two braces, and should be written like this:

    Java Code:
    import java.util.Scanner;
    
    public class evaluateGrade
    {
    	public static void main(String[] args)
    	{
    		Scanner console = new Scanner(System.in);
    	}
    	
    	public static double grade(int score)
    	{
    		double grade = (score - 60) / 10.0;
    		return Math.max(1, grade);
    	}
    }
    Last edited by AndrewM16921; 09-25-2013 at 06:53 AM.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,923
    Rep Power
    5

    Default Re: Scanner, if (if/else) and loop

    Quote Originally Posted by manibby93 View Post
    do not refer me to a book, like seriously.
    Like seriously -- what do you have against reading? You need to get a good book, read the Oracle tutorials, learn to read and understand the Java API documentation, and practice writing code yourself if you really want to learn Java. If you don't then why are you taking the course?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: Scanner, if (if/else) and loop

    I'm saying people refer me to books when they could just help me. I don't need to do anything. If anything, I need to get tutoring, which I cannot get before I need to turn in these assignments. That's why I'm here. I don't understand why I can't ask for help on a Java Forum w/o getting criticized. I'm taking the course because I'm a COSC minor and need the credits. I transferred to a new college and thought I'd be working with Visual Basic which I know a little about, but my professor basically gave us all the answers in that class. Last time I checked, you take a class to learn, not because you necessarily know everything there is to learn in the class already. In 4 weeks, you shouldn't know everything. I'm just trying to pass. I'm taking 6 classes. My professor didn't recommend a book.

Similar Threads

  1. Scanner for String in for loop
    By CannonVulcan in forum New To Java
    Replies: 3
    Last Post: 11-24-2012, 07:29 PM
  2. For loop with scanner and strings
    By jwl in forum New To Java
    Replies: 20
    Last Post: 09-15-2012, 08:05 PM
  3. Scanner Loop
    By Phenomena in forum New To Java
    Replies: 2
    Last Post: 04-01-2010, 07:47 PM
  4. Problem with scanner in loop
    By grifan526 in forum New To Java
    Replies: 2
    Last Post: 07-21-2009, 01:06 AM
  5. Scanner-While Loop
    By hyunski in forum New To Java
    Replies: 2
    Last Post: 03-12-2009, 03:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •