Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: Help resolving these errors? Please!

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help resolving these errors? Please!

    Ok, so I keep on getting the errors where it says my variable may not have been initialized. I get this error in lines 22 regarding orgGrade, 26 regarding variable 'a', 33 regarding newGrade, 37 regarding newGrade and gradePercent, 41 regarding newGrade and gpoints, 45 regarding newGrade and gpercent. Any reason that is obvious that I'm missing?

    import java.util.Scanner; //for the ability to get input from 
    						  //the keyboard 
    import java.text.DecimalFormat;
     
    public class Project3
    {					  
     
    	public static void main(String[] args)
    	{
    		//enter variable below
    		double orgGrade;   //Variable for the Original Grade
    		double newGrade;	   //Variable for the Grade after the Curve
    		double gradePercent;   //Variable for displaying the percentage from option 4.
    		double points = 10.0;  //Variable for points added
    		double percent = .10;   //Variable for given percentage
    		double gpoints;          //Variable for the Given points
    		double gpercent;         //Variable for the Given percentage
    		int a;					 // Variable for Menu Selection
    		Scanner keyboard = new Scanner(System.in);
    		DecimalFormat df = new DecimalFormat("00.0");
    		//start program here
    		orginalgrade(orgGrade);  //get users grade. 
     
    		clearScreen(); //clear the screen
     
    		Menu(a);				//show menu/selections
     
    		System.out.print(a + orgGrade); 
     
    			switch (a)
    			{	
    				case '1':
    				addPoints(newGrade, orgGrade, points);
    				break;
     
    				case '2':
    				addPercent(newGrade, orgGrade, percent, gradePercent);
    				break;
     
    				case '3':
    				givenPoints(newGrade, orgGrade, gpoints);
    				break;
     
    				case '4':
    				givenPercent(newGrade, orgGrade, gpercent);
    				break;
     
    				case '5':
    				System.out.print("That is not valid a selection!");
    				break;
    			}
     
     
     
     
     
     
     
     
     
     
     
    	}//end main
    	public static void clearScreen()
    	{
    		System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	}//end clearScreen
     
    	public static void freezeScreen()
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print("	       -- Press Enter to Continue --");
    		keyboard.nextLine();
    	}//end freezeScreen
     
    	public static double orginalgrade(double orgGrade)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
     
     
    		System.out.println("What is the original grade?");     //Get original grade from user
    		orgGrade = keyboard.nextDouble();
     
    		return orgGrade; 
    	}//end orgGrade
     
    	public static int Menu(int a) 
    	{
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("	    Grade Aduster");
    		System.out.println("	   by Aaron Webster ");   // Greet user
    		System.out.println("******************************\n");
    		System.out.println("1. Curve by 10 points.");              //menu options here
    		System.out.println("2. Curve by 10 percent.");
    		System.out.println("3. Curve by a certain number of points.");
    		System.out.println("4. Curve by a given percentage"); 
    		System.out.println("5. Exit program\n");
    		System.out.println("Enter your selection here");
    		a = keyboard.nextInt();
     
    		return a;
    	}//end Menu
     
    	public static double addPoints(double newGrade, double orgGrade, double points)
    	{
     
    				newGrade = orgGrade + points;
    				System.out.print("Curve applied: " + points);
    				System.out.print("Adjusted grade: " + newGrade);
     
     
    		return newGrade;
    	}//end addPoints	
     
    	public static double addPercent(double newGrade, double orgGrade, double percent, double gradePercent)
    	{
    				newGrade = (orgGrade * percent) + orgGrade; 
    				gradePercent = orgGrade * percent;
    				System.out.print("Curve applied: " + gradePercent);
    				System.out.print("Adjusted grade: " + newGrade);
     
    		return newGrade;
    	}//end addPercent
     
    	public static double givenPoints(double newGrade, double orgGrade, double gpoints)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.print("How many points should be applied to curve the grade?");
    				gpoints = keyboard.nextDouble();
    				newGrade = gpoints + orgGrade;
    				System.out.print("Curve applied: " + gpoints);
    				System.out.print("Adjusted grade: " + newGrade);
     
    		return newGrade;
    	}//end givenPoints
     
    	public static double givenPercent(double newGrade, double orgGrade, double gpercent)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.print("Enter the percentage of the curve. (Ex. 10% would be .10)");
    				gpercent = keyboard.nextDouble();
    				newGrade = (gpercent * orgGrade) + orgGrade;
    				System.out.print("Curve applied: " + gpercent);
    				System.out.print("Adjusted grade: " + newGrade);
     
    		return newGrade;
    	}//end givenPercent
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    variable may not have been initialized.
    Assign all the variables a value when they are defined:
    int var = 0;
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    I tried doing that, but say I put a = 0; which a is the variable that holds the menu selection, well even when I chose a different number, 'a' still stays at 0, so how can I fix that?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    when I chose a different number, 'a' still stays at 0, how can I fix that?
    Assign a the new value. What value do you want a to have? Where does that value come from?
    The value returned by the Menu() method should be saved in a.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    Yeah, the Menu method should assign a new value to 'a', but it doesn't, 'a' stays at 0 no matter what number you enter for its new value. Same problem with my 'orgGrade" variable, the originalGrade method should assign that a new number but it keeps it at whatever number I define it at, which I've been using 0.

    import java.util.Scanner; //for the ability to get input from 
    						  //the keyboard 
    import java.text.DecimalFormat;
     
    public class Project3
    {					  
     
    	public static void main(String[] args)
    	{
    		//enter variable below
    		double orgGrade = 10;   //Variable for the Original Grade
    		double newGrade = 0;	   //Variable for the Grade after the Curve
    		double gradePercent = 0;   //Variable for displaying the percentage from option 4.
    		double points = 10.0;  //Variable for points added
    		double percent = .10;   //Variable for given percentage
    		double gpoints = 0;          //Variable for the Given points
    		double gpercent = 0;         //Variable for the Given percentage
    		int a = 0;					 // Variable for Menu Selection
    		String Msg = "Press ENTER to return to the menu";
    		Scanner keyboard = new Scanner(System.in);
    		DecimalFormat df = new DecimalFormat("00.0");
    		//start program here
     
    		clearScreen();
     
    		orginalgrade(orgGrade);  //get users grade. 
     
    		clearScreen(); //clear the screen
     
     
    		Menu(a);				//show menu/selections	
     
     
     
     
     
     
    			switch (a)
    			{	
    				case '1':
    				addPoints(newGrade, orgGrade, points, Msg);
    				break;
     
    				case '2':
    				addPercent(newGrade, orgGrade, percent, gradePercent, Msg);
    				break;
     
    				case '3':
    				givenPoints(newGrade, orgGrade, gpoints, Msg);
    				break;
     
    				case '4':
    				givenPercent(newGrade, orgGrade, gpercent, Msg);
    				break;
     
    				case '5':
    				System.out.print("That is not valid a selection!");
    				break;
    			}
     
     
     
     
     
     
     
     
     
     
     
    	}//end main
    	public static void clearScreen()
    	{
    		System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	}//end clearScreen
     
    	public static void freezeScreen()
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print("	       -- Press Enter to Continue --");
    		keyboard.nextLine();
    	}//end freezeScreen
     
    	public static void freezeScreen(String Msg)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print(Msg);
    		keyboard.nextLine();
    	}//end freezeScreen
     
    	public static double orginalgrade(double orgGrade)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
     
     
    		System.out.print("What is the original grade?");     //Get original grade from user
    		orgGrade = keyboard.nextDouble();
     
    		return orgGrade; 
    	}//end orgGrade
     
    	public static int Menu(int a) 
    	{
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("	    Grade Aduster");
    		System.out.println("	   by Aaron Webster ");   // Greet user
    		System.out.println("******************************\n");
    		System.out.println("1. Curve by 10 points.");              //menu options here
    		System.out.println("2. Curve by 10 percent.");
    		System.out.println("3. Curve by a certain number of points.");
    		System.out.println("4. Curve by a given percentage"); 
    		System.out.println("5. Exit program\n");
    		System.out.print("Enter your selection here: ");
    		a = keyboard.nextInt();
     
    		return a;
    	}//end Menu
     
    	public static double addPoints(double newGrade, double orgGrade, double points, String Msg)
    	{
     
    				newGrade = orgGrade + points;
    				System.out.print("Curve applied: " + points);
    				System.out.print("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end addPoints	
     
    	public static double addPercent(double newGrade, double orgGrade, double percent, double gradePercent, String Msg)
    	{
    				newGrade = (orgGrade * percent) + orgGrade; 
    				gradePercent = orgGrade * percent;
    				System.out.print("Curve applied: " + gradePercent);
    				System.out.print("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end addPercent
     
    	public static double givenPoints(double newGrade, double orgGrade, double gpoints, String Msg)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.print("How many points should be applied to curve the grade?");
    				gpoints = keyboard.nextDouble();
    				newGrade = gpoints + orgGrade;
    				System.out.print("Curve applied: " + gpoints);
    				System.out.print("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end givenPoints
     
    	public static double givenPercent(double newGrade, double orgGrade, double gpercent, String Msg)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.print("Enter the percentage of the curve. (Ex. 10% would be .10)");
    				gpercent = keyboard.nextDouble();
    				newGrade = (gpercent * orgGrade) + orgGrade;
    				System.out.print("Curve applied: " + gpercent);
    				System.out.print("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end givenPercent
    }

    Reposted so you could see what I have so far.

    --- Update ---

    Also, I tried to assign a value of 1 to my variable 'a' so that it would atleast execute the first option in the switch statement, but it doesn't even do that, my program ends. Is my coding wrong with the switch too?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    Did you see this line in post#4?

    The value returned by the Menu() method should be saved in a.

    See the tutorial: Returning a Value from a Method (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    Ok, thanks so much for all your help. I just have one last question. So I have everything working now, except one thing.

    import java.util.Scanner; //for the ability to get input from 
    						  //the keyboard 
    import java.text.DecimalFormat;
     
    public class Project3
    {					  
     
    	public static void main(String[] args)
    	{
    		//enter variable below
    		double orgGrade = 0;   //Variable for the Original Grade
    		double newGrade = 0;	   //Variable for the Grade after the Curve
    		double gradePercent = 0;   //Variable for displaying the percentage from option 4.
    		double points = 10.0;  //Variable for points added
    		double percent = .10;   //Variable for given percentage
    		double gpoints = 0;          //Variable for the Given points
    		double gpercent = 0;         //Variable for the Given percentage
    		int a = 0;					 // Variable for Menu Selection
    		String Msg = "Press ENTER to return to the menu";
    		Scanner keyboard = new Scanner(System.in);
    		DecimalFormat df = new DecimalFormat("00.0");
    		//start program here
     
    		clearScreen();
     
    		orgGrade = orginalgrade(orgGrade);  //get users grade. 
     
    		clearScreen(); //clear the screen
     
     
    		a = Menu(a);				//show menu/selections	
     
     
     
     
     
     
     
    			switch (a)
    			{	
    				case 1:
    				addPoints(newGrade, orgGrade, points, Msg);
    				break;
     
    				case 2:
    				addPercent(newGrade, orgGrade, percent, gradePercent, Msg);
    				break;
     
    				case 3:
    				givenPoints(newGrade, orgGrade, gpoints, Msg);
    				break;
     
    				case 4:
    				givenPercent(newGrade, orgGrade, gpercent, Msg);
    				break;
     
    				case 5:
    				System.out.print("That is not valid a selection!");
    				break;
    			}
     
     
     
     
     
     
     
     
     
     
     
     
    	}//end main
    	public static void clearScreen()
    	{
    		System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	}//end clearScreen
     
    	public static void freezeScreen()
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print("	       -- Press Enter to Continue --");
    		keyboard.nextLine();
    	}//end freezeScreen
     
    	public static void freezeScreen(String Msg, int a)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print(Msg);
    		keyboard.nextLine();
    		Menu();
    	}//end freezeScreen
     
    	public static double orginalgrade(double orgGrade)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
     
     
    		System.out.print("What is the original grade?");     //Get original grade from user
    		orgGrade = keyboard.nextDouble();
     
    		return orgGrade; 
    	}//end orgGrade
     
    	public static int Menu(int a) 
    	{
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("	    Grade Aduster");
    		System.out.println("	   by Aaron Webster ");   // Greet user
    		System.out.println("******************************\n");
    		System.out.println("1. Curve by 10 points.");              //menu options here
    		System.out.println("2. Curve by 10 percent.");
    		System.out.println("3. Curve by a certain number of points.");
    		System.out.println("4. Curve by a given percentage"); 
    		System.out.println("5. Exit program\n");
    		System.out.print("Enter your selection here: ");
    		a = keyboard.nextInt();
     
    		if (a > 5 || a < 1)
    		{
    			System.out.print("That is not a valid option!\n\n");
    		}
    		freezeScreen(Msg);
    		return a;
    	}//end Menu
     
    	public static double addPoints(double newGrade, double orgGrade, double points, String Msg)
    	{
     
    				newGrade = orgGrade + points;
    				System.out.println("Curve applied: " + points);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end addPoints	
     
    	public static double addPercent(double newGrade, double orgGrade, double percent, double gradePercent, String Msg)
    	{
    				newGrade = (orgGrade * percent) + orgGrade; 
    				gradePercent = orgGrade * percent;
    				System.out.println("Curve applied: " + gradePercent);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end addPercent
     
    	public static double givenPoints(double newGrade, double orgGrade, double gpoints, String Msg)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.println("How many points should be applied to curve the grade?");
    				gpoints = keyboard.nextDouble();
    				newGrade = gpoints + orgGrade;
    				if (newGrade > 100)
    				{
    					newGrade = 100;
    				}
    				System.out.println("Curve applied: " + gpoints);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end givenPoints
     
    	public static double givenPercent(double newGrade, double orgGrade, double gpercent, String Msg)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.println("Enter the percentage of the curve. (Ex. 10% would be .10)");
    				gpercent = keyboard.nextDouble();
    				newGrade = (gpercent * orgGrade) + orgGrade;
    				System.out.println("Curve applied: " + gpercent);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end givenPercent
    }

    In my freezeScreen(String Msg) method, I need to call my Menu method inside of it. But I'm not sure how that works, so I guess my question is how to call a method from a method? Thanks

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    how to call a method from a method?
    That's a strange question. The posted code is full of examples. Here are three places methods are called:
                    clearScreen();
     
    		orgGrade = orginalgrade(orgGrade);  //get users grade. 
     
    		clearScreen(); //clear the screen

    Can you explain what the problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    public static void freezeScreen(String Msg, int a)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print(Msg);
    		keyboard.nextLine();
    		Menu();
    	}//end freezeScreen

    I need to call my Menu method from my freezeScreen(String Msg) method.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    The posted code has a call to the menu() method in it now???? (Method names should start with lowercase letters)
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    Scroll down near the end is where my question lies.

    import java.util.Scanner; //for the ability to get input from 
    						  //the keyboard 
    import java.text.DecimalFormat;
     
    public class Project3
    {					  
     
    	public static void main(String[] args)
    	{
    		//enter variable below
    		double orgGrade = 0;   //Variable for the Original Grade
    		double newGrade = 0;	   //Variable for the Grade after the Curve
    		double gradePercent = 0;   //Variable for displaying the percentage from option 4.
    		double points = 10.0;  //Variable for points added
    		double percent = .10;   //Variable for given percentage
    		double gpoints = 0;          //Variable for the Given points
    		double gpercent = 0;         //Variable for the Given percentage
    		int a = 0;					 // Variable for Menu Selection
    		String Msg = "Press ENTER to return to the menu";
    		Scanner keyboard = new Scanner(System.in);
    		DecimalFormat df = new DecimalFormat("00.0");
    		//start program here
     
    		clearScreen();
     
    		orgGrade = orginalgrade(orgGrade);  //get users grade. 
     
    		clearScreen(); //clear the screen
     
     
    		a = enu(a);				//show menu/selections	
     
     
     
     
     
     
     
    			switch (a)
    			{	
    				case 1:
    				addPoints(newGrade, orgGrade, points, Msg);
    				break;
     
    				case 2:
    				addPercent(newGrade, orgGrade, percent, gradePercent, Msg);
    				break;
     
    				case 3:
    				givenPoints(newGrade, orgGrade, gpoints, Msg);
    				break;
     
    				case 4:
    				givenPercent(newGrade, orgGrade, gpercent, Msg);
    				break;
     
    				case 5:
    				System.out.print("That is not valid a selection!");
    				break;
    			}
     
     
     
     
     
     
     
     
     
     
     
     
    	}//end main
    	public static void clearScreen()
    	{
    		System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	}//end clearScreen
     
    	public static void freezeScreen()
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print("	       -- Press Enter to Continue --");
    		keyboard.nextLine();
    	}//end freezeScreen
     
    	public static void freezeScreen(String Msg, int a)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print(Msg);
    		keyboard.nextLine();
    		[B]I NEED TO CALL MY MENU METHOD FROM THIS METHOD[/B]
    	}//end freezeScreen
     
    	public static double orginalgrade(double orgGrade)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
     
     
    		System.out.print("What is the original grade?");     //Get original grade from user
    		orgGrade = keyboard.nextDouble();
     
    		return orgGrade; 
    	}//end orgGrade
     
    	public static int menu(int a) 
    	{
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("	    Grade Aduster");
    		System.out.println("	   by Aaron Webster ");   // Greet user
    		System.out.println("******************************\n");
    		System.out.println("1. Curve by 10 points.");              //menu options here
    		System.out.println("2. Curve by 10 percent.");
    		System.out.println("3. Curve by a certain number of points.");
    		System.out.println("4. Curve by a given percentage"); 
    		System.out.println("5. Exit program\n");
    		System.out.print("Enter your selection here: ");
    		a = keyboard.nextInt();
     
    		if (a > 5 || a < 1)
    		{
    			System.out.print("That is not a valid option!\n\n");
    		}
    		freezeScreen(Msg);
    		return a;
    	}//end Menu
     
    	public static double addPoints(double newGrade, double orgGrade, double points, String Msg)
    	{
     
    				newGrade = orgGrade + points;
    				System.out.println("Curve applied: " + points);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end addPoints	
     
    	public static double addPercent(double newGrade, double orgGrade, double percent, double gradePercent, String Msg)
    	{
    				newGrade = (orgGrade * percent) + orgGrade; 
    				gradePercent = orgGrade * percent;
    				System.out.println("Curve applied: " + gradePercent);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end addPercent
     
    	public static double givenPoints(double newGrade, double orgGrade, double gpoints, String Msg)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.println("How many points should be applied to curve the grade?");
    				gpoints = keyboard.nextDouble();
    				newGrade = gpoints + orgGrade;
    				if (newGrade > 100)
    				{
    					newGrade = 100;
    				}
    				System.out.println("Curve applied: " + gpoints);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end givenPoints
     
    	public static double givenPercent(double newGrade, double orgGrade, double gpercent, String Msg)
    	{
    				Scanner keyboard = new Scanner(System.in);
     
    				System.out.println("Enter the percentage of the curve. (Ex. 10% would be .10)");
    				gpercent = keyboard.nextDouble();
    				newGrade = (gpercent * orgGrade) + orgGrade;
    				System.out.println("Curve applied: " + gpercent);
    				System.out.println("Adjusted grade: " + newGrade);
    				freezeScreen(Msg);
     
    		return newGrade;
    	}//end givenPercent
    }


    --- Update ---

    I put my question in all CAPS inside the code, near the bottom. In the freezeScreen(String Msg) method

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    Why hide the question? What should I look for? Give me a String to Find: ***HERE***
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    I don't know how to do that.. So I'll just restate my question again.

    So my freezeScreen(String Msg) method on line 87
    public static void freezeScreen(String Msg,)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print(Msg);
    		keyboard.nextLine();
     
    	}//end freezeScreen

    I need to call this Method from the method listed above.
    {
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("	    Grade Aduster");
    		System.out.println("	   by Aaron Webster ");   // Greet user
    		System.out.println("******************************\n");
    		System.out.println("1. Curve by 10 points.");              //menu options here
    		System.out.println("2. Curve by 10 percent.");
    		System.out.println("3. Curve by a certain number of points.");
    		System.out.println("4. Curve by a given percentage"); 
    		System.out.println("5. Exit program\n");
    		System.out.print("Enter your selection here: ");
    		a = keyboard.nextInt();
     
    		if (a > 5 || a < 1)
    		{
    			System.out.print("That is not a valid option!\n\n");
    		}
    		freezeScreen(Msg);
    		return a;
    	}//end Menu

    So, basically whenever i call my freezeScreen(Msg), I need the menu() to come with it.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    What happened with the code posted in post#9?

    What will the freezeScreen() method do with the value returned by the menu() method?
    You may need to call the menu() method after each call to the freezeScreen() method.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    It's the 1st code in #13. Ok, so In the Menu Method, the user can select 1 -5, but if the user makes in invalid selection such as 6, it will say "That is an invalid selection!", then the freezeScreen(String Msg) is called, which will say "Press ENTER to return to the Menu". Which is why I need the Menu Method to be called with the freezeScreen(String Msg). I would just put the Menu Method after each freezeScreen(String Msg), but my Professor doesn't want us to do that.

    So I need my code to look like
    public static void freezeScreen(String Msg,)
    	{
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print(Msg);
    		keyboard.nextLine();
                    Menu();
     
    	}//end freezeScreen

    So that my menu pops up after each freezeScreen

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    What will the freezeScreen() method do with the value returned by the menu() method? Isn't that value needed somewhere else in the program?

    Maybe menu() should call freezeScreen().
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help resolving these errors? Please!

    Well, my variable 'a' is being defined in the Menu() method, but the only valid options are 1-5, so if anything else is put into variable 'a', the freezeScreen() is called which says "That is not a Valid Selection" which then says "Press ENTER to go back to the Menu". So then the Menu() should be called, and the variable 'a' can be reset. Right now I have my program working except whenever I enter an invalid selection, the freezeScreen() is called, but I can't get the Menu() to reappear too.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help resolving these errors? Please!

    variable 'a' is being defined in the Menu() method
    A variable defined in a method can't be used by any other methods. The menu() method returns the value of a so other methods can use it value. The code that calls menu() should save what it returns so it can be used in the program.

    Maybe menu() should call freezeScreen()
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help With errors. Please.
    By wrx12 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 11th, 2012, 11:53 AM
  2. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  3. help with errors
    By hello_world in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 9th, 2011, 09:11 PM
  4. Many Errors
    By Woody619 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: July 16th, 2010, 09:36 PM
  5. Why am I getting 62 errors?
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 1st, 2010, 04:41 AM