Results 1 to 5 of 5
  1. #1
    cybershark is offline Member
    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0

    Default help me with my code

    So I'm new at JAVA , I'm trying to make an program to calculate my grade on an specific class .
    Heres the code:
    Java Code:
    import java.util.Scanner; 
    
    public class nota {
    	public static void main (String [] args){
    		Scanner sc = new Scanner(System.in);
    		
    		String name; 
    		String surname;
    		float test1;
    		float test2;
    		float test3;
    		int provimi; // FINAL TEST
    		int grade; 
    		
    		
    		
    		System.out.print("Name of student: ");
    		name = sc.nextLine();
    		System.out.print("Surname of student: ");
    		surname = sc.nextLine();
           System.out.print("How much % has the student on the first test?: ");
            test1 = sc.nextFloat();
            if (test1>15){
    		System.out.println("Student can't get more than 15% in the first test!!");
    				}		
            System.out.print("How much % has the student on the second test?");
    		
      
    
      }
    	
    
     
     
     }
    So basicly what I want to make is when the user types "16 or more" on the first test the output to show that "Student can't get more than 15% in the first test!!" and then repeat "How much % has the student on the first test?: " until the user types "15 or lower" so every time the user types "16,17 or more " the output to show "Student can't get more than 15% in the first test!!" until the answer is right .

    I don't care if the program calculates my grade good or wrong I just want to make some practice and experimenting with code .

    I think the code to do what I'm asking is "while" and true and false but I dont understand "WHILE" so good .
    Thank you
    Last edited by cybershark; 12-04-2016 at 06:21 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: help me with my code

    Moved to New section.

    What problems are you having with your code? If errors or wrong results, copy the console's contents and paste it here to show us what the program is doing.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Note: It be useful for anyone reading the code if the description of what you want the code to do was included in the source code as comments. Then the description and code would all be in one place.
    Last edited by Norm; 12-04-2016 at 04:23 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    cybershark is offline Member
    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0

    Default Re: help me with my code

    Quote Originally Posted by cybershark View Post
    So I'm new at JAVA , I'm trying to make an program to calculate my grade on an specific class .
    Heres the code:
    Java Code:
    import java.util.Scanner; 
    
    public class nota {
    	public static void main (String [] args){
    		Scanner sc = new Scanner(System.in);
    		
    		String name; 
    		String surname;
    		float test1;
    		float test2;
    		float test3;
    		int provimi; // FINAL TEST
    		int grade; 
    		
    		
    		
    		System.out.print("Name of student: ");
    		name = sc.nextLine();
    		System.out.print("Surname of student: ");
    		surname = sc.nextLine();
           System.out.print("How much % has the student on the first test?: ");
            test1 = sc.nextFloat();
            if (test1>15){
    		System.out.println("Student can't get more than 15% in the first test!!");
    				}		
            System.out.print("How much % has the student on the second test?");
    		
      
    
      }
    	
    
     
     
     }
    So basicly what I want to make is when the user types "16 or more" on the first test the output to show that "Student can't get more than 15% in the first test!!" and then repeat "How much % has the student on the first test?: " until the user types "15 or lower" so every time the user types "16,17 or more " the output to show "Student can't get more than 15% in the first test!!" until the answer is right .

    I don't care if the program calculates my grade good or wrong I just want to make some practice and experimenting with code .

    I think the code to do what I'm asking is "while" and true and false but I dont understand "WHILE" so good .
    Thank you
    HERE I REQOUTED and added tags

  4. #4
    cybershark is offline Member
    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0

    Default Re: help me with my code

    I dont have any erros . I'm just asking how can I do something

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: help me with my code

    Ok, I'm looking in the code to see what it is supposed to do and don't see any comments describing anything.

    until the answer is right .
    Use a while loop when the end of the looping is not known before the loop starts.
    Last edited by Norm; 12-04-2016 at 09:30 PM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Posting code to forum : Code to code tags
    By rushtojess in forum Suggestions & Feedback
    Replies: 2
    Last Post: 04-21-2015, 09:16 PM
  2. Replies: 1
    Last Post: 03-25-2012, 04:40 AM
  3. Replies: 16
    Last Post: 01-31-2012, 09:36 PM
  4. Replies: 0
    Last Post: 08-07-2011, 09:32 PM
  5. Replies: 0
    Last Post: 02-21-2011, 12:50 PM

Posting Permissions

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