Results 1 to 2 of 2
  1. #1
    ebrown086 is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default Write a program that finds and prints the average of two numbers.

    "Write a program that finds and prints the average of two numbers.
    For this program, I will need two files: AverageRunner (contains the main method) and Average (the class you will create).
    In the Average class, I need two instance variables – one for each number I am averaging. I will also need two constructors – one default constructor and one that initializes the variables to be equal to the parameters. Finally, I will need a method that calculates and prints the average.
    In the AverageRunner class, create three instances of the Average class, giving each object two values to average. Then use those objects to calculate and print the average of the numbers I chose."

    I missed about a week of class when we were working on identifying constructors and methods, and have little to no clue on how to do this. I know that I will need to start with 2 variables and declare them in a public method, but don't know where to go from there. Why the program does what it does would be nice to know as well.

    Here is what I have so far:

    Java Code:
    public class averageProgram{ //main method
    	private int n1;
    	private int n2;
    	public averageProgram()// edited this to be a constructor
            //I do believe that this needs to be another constructor, but I don't know exactly where to go from here...
            //one more constructor here
    I am pretty stuck at this point due to the fact that I missed class.... :/
    Last edited by ebrown086; 10-10-2013 at 08:50 PM. Reason: Edit my code submitted

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Write a program that finds and prints the average of two numbers.

    Check out the Oracle tutorials in my signature below. You may also want to discuss this with your instructor.
    Once the code is written you can post it here and the forum will be better able to assist.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-06-2013, 02:43 AM
  2. Replies: 2
    Last Post: 10-06-2012, 05:29 AM
  3. Average of 3 numbers
    By TravisDavis in forum New To Java
    Replies: 3
    Last Post: 10-04-2012, 11:59 PM
  4. Replies: 0
    Last Post: 12-02-2011, 10:03 AM
  5. Trying to write to a file but it only prints last line
    By beauti477 in forum New To Java
    Replies: 1
    Last Post: 07-22-2011, 02:19 AM

Tags for this Thread

Posting Permissions

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