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 3 of 3

Thread: Need help with Methods!

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

    Default Need help with Methods!

    Hi there, so I'm basically lost on how to get Methods to work properly. Any help you could give me is greatly appreciated! I also attached a file with the requirements to do this project, so if you could take a look at that and tell me what you think, I would be very thankful!

    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
    		orgGrade(double orgGrade);  //get users grade. 
     
    		clearScreen(); //clear the screen
     
    		a = Menu(int a);  //show menu/selections
     
     
    			if (a == 1)                          
    				newGrade = orgGrade + points;
    				System.out.print("Curve applied: " + points);
    				System.out.print("Adjusted grade: " + newGrade);
    			else if (a == 2) 
    				newGrade = (orgGrade * percent) + orgGrade; 
    				gradePercent = orgGrade * percent;
    				System.out.print("Curve applied: " + gradePercent);
    				System.out.print("Adjusted grade: " + newGrade);
    			else if (a == 3)
    				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);
    			else if (a == 4)
    				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);
    			else if (a >= 5)
    				System.out.print("That is not valid a selection!");
     
     
     
     
     
     
     
     
     
     
    	}
    	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);
    		double orgGrade;
     
     
    		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) 
    	{
    		int a;
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.print("		Grade Aduster");
    		System.out.print("	   by Aaron Webster \n");   // Greet user
    		System.out.print("******************************");
    		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 
    }
    Attached Files Attached Files


  2. #2
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with Methods!

    You have a lot of mistakes in your program, I will go through 1 method and you figure the rest.

    Your method call:

    orgGrade(double orgGrade); // wrong method call

    Correction:
    First: your method name should be the same in the method call and the method.
    Second: you have typed the type (double) of orgGrade in the method call which is wrong.

    orignalgrade(orgGrade);// this is how your method should be called

    Your method:

    public static double orginalgrade(double orgGrade)
    {
    Scanner keyboard = new Scanner(System.in);
    // remove this: double orgGrade; its already declared in the method header no need to re declare.

    System.out.println("What is the original grade?"); //Get original grade from user
    orgGrade = keyboard.nextDouble();

    return orgGrade;
    }//end orgGrade

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

    Default Re: Need help with Methods!

    Thanks alot for the help!

Similar Threads

  1. HELP WITH METHODS!
    By swirth123 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: March 19th, 2013, 02:52 PM
  2. Methods
    By kave2 in forum Java Theory & Questions
    Replies: 8
    Last Post: January 22nd, 2013, 11:56 AM
  3. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  4. I need help with my methods please?
    By THeAnnonymous in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 11th, 2011, 09:22 AM
  5. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 05:04 PM