Results 1 to 8 of 8
  1. #1
    lebron11 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default Help compeleting four average mark.

    Hello, I am new at java I am having a problem finishing my first assignment lol. I am trying to make a program that will take 4 marks and average them out. Looks easy sounds easy but not really lol.

    Here is what I got so far.

    Java Code:
    public static void main (String[] args)
    {
    	c = new Console () ;
    	int x;
    	String i[] = new String[3] ;
    	c.printIn (“Four Courses Average Taker”) ;
    	for (x=0;x < 3;x++)
    	{
    		c.print (“Enter your first mark“) ;
    		i [x] =c.readLine () ;
    	}
    	c.printIn (“Your average for the four courses is
    the problem I am having is how to tell the program Enter the Second mark because i x is going to say to all the numbers
    ENTER YOUR FIRST NUMBER= 85
    ENTER YOUR FIRST NUMBER=95
    ENTER YOUR FIRST NUMBER=99
    ENTER YOUR FIRST NUMBER=50

    after doing that how do I tell it to average out.

    any input will do more I learn different people better is for me. So give me anything I will try to understand. Thanks a lot YOUR THE BEST!!!
    Last edited by lebron11; 03-08-2010 at 04:48 PM.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Uhm, you have four inputs, but only an array with three 'slots'.
    Have a look at Integer.parseInt(String s)
    How would you calculate an average on a piece of paper?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    lebron11 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    I have three slots because I think 0 is a slot as well it will start from 0 1 2 3 that makes it four slots that;s why I have 3 there
    Integer.parseInt (String s) i have no idea how to put that in there.
    lol I like your last questions I would take 4 numbers 85+95+99+50=329/4=82.25 lol not rocket science.

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by lebron11 View Post
    I have three slots because I think 0 is a slot as well it will start from 0 1 2 3 that makes it four slots that;s why I have 3 there
    Integer.parseInt (String s) i have no idea how to put that in there.
    lol I like your last questions I would take 4 numbers 85+95+99+50=329/4=82.25 lol not rocket science.
    False, String i[] = new String[3] is three slots [0,1,2].
    If you had run your code you had noticed that it'll only ask for input three times.

    Have you read the Integer API? How would you calculate numbers with having Strings only?

    So you have to change the inserted number literals into numbers, add them up and divide them by four. And before you ask why your average calculation comes up with 82, think about datatypes and read this:
    Using Variable Argument Lists and Some Things You Should Know About Floating-Point Arithmetic
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    lebron11 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Your the best man thanks for explaining about the slots lol U got me there lol. Nope I have not read the integer API, ya your right I do need interger code in there. I will figure that out how get back to you so you can check the rest of it. I will read it and come back to you ASAP. THANKS alot for explaining YOUR THE BEST. PLease check in 9mins I will write you back on here.

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Hmpf, calm down. I'll have a look in an hour :)
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    lebron11 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    lol I'm getting too excited lol. So here is another program

    Java Code:
    Import java.util.Scanner;
    
    Class apples{
    	Public static void main (String[] args) {
    		Scanner input = Scanner (system.in) ;
    		Int total = 0
    		Int grade ;
    		Int average ;
    		Int counter = 0;
    	
    		While (counter < 4) {
    			grade = input .nextInt () ;
    			total = total + grade ;
    			counter++;
    		}
    		average = total/4
    		System.out.printIn (“Your average is “+ average) ;
    	}
    }
    Now this program is not using integer why? and they somehow manage to do it! I am just having a hard time doing it my way I don;t know how to add integer into my thing so it will read only numbers and then divide that number by 4 to get the average. Can you feed that in my table so I can see because there is no way I can do it my way. Maybe next year or never lol
    Last edited by lebron11; 03-08-2010 at 05:51 PM.

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    That one doesn't even compile.

    No, I won't change your program, that's your job. You won't learn anything by that. Do your best, post your code and ask specific questions when you're stuck.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Replies: 1
    Last Post: 02-12-2010, 01:50 PM
  2. average using dialog boxes.
    By sarahhh in forum New To Java
    Replies: 1
    Last Post: 01-22-2010, 10:10 PM
  3. Test score average
    By ryn21 in forum New To Java
    Replies: 11
    Last Post: 10-17-2008, 05:49 AM
  4. Calculate Average
    By sthack99 in forum New To Java
    Replies: 4
    Last Post: 06-13-2008, 11:09 AM
  5. Calculate average age for women and men?
    By Legoland in forum New To Java
    Replies: 3
    Last Post: 04-18-2007, 10:38 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
  •