Results 1 to 2 of 2

Thread: i'm such a noob

  1. #1
    Join Date
    Feb 2009
    Posts
    96

    i'm such a noob

    i cant figure out how to get the prices higher then the average --- in the method highPrices () i need to find the prices higher then the average for the array and print them out onto a dialogbox. any help would be greatly appriciated... In JAVA
    import java.util.*;
    import javax.swing.JOptionPane;
    //create a class
    public class prices {

    //make the string input
    public static void main(String[] args){
    double nag= 0;
    String Input;
    double[] numbers; // An array for storing the input values.
    int numCt; // The number of numbers saved in the array.
    double num; // One of the numbers input by the user.

    numbers = new double[4]; // Space for 5 doubles.
    numCt = 0; // No numbers have been saved yet.

    Input = JOptionPane.showInputDialog(null, "Please enter a price.");

    while (numCt < numbers.length) { // Get the numbers and put them in the array.
    Input = JOptionPane.showInputDialog(null, "Please enter a price.");
    num = Double.parseDouble(Input);
    if (num <= 0)
    break;
    numbers[numCt] = num;
    numCt++;
    }
    sumArray(numbers);
    aveArray(numbers);
    //highPrices();
    JOptionPane.showMessageDialog(null,"ddd" + nag);
    }

    public static void sumArray(double arr[])
    {

    double sum = 0; // Start the total sum at 0.
    for (int i=0; i<arr.length; i++) {
    sum = sum + arr[i]; // Add the next element to the total
    }
    JOptionPane.showMessageDialog(null,"The sum of the prices is " + sum);

    }

    public static void aveArray(double rad[]){
    double avg = 0;

    double sum = 0; // Start the total sum at 0.
    for (int i=0; i<rad.length; i++) {
    sum = sum + rad[i]; // Add the next element to the total
    avg = sum/rad.length;
    }
    JOptionPane.showMessageDialog(null,"The average of the prices is " + avg);

    }

    public static double highPrices(){

    double avg = 0;

    double sum = 0; // Start the total sum at 0.
    for (int i=0; i<arr.length; i++) {
    sum = sum + arr[i]; // Add the next element to the total
    avg = sum/arr.length;
    if(avg < arr[i])
    return nag;




    //JOptionPane.showMessageDialog(null,"ddd" + ave);





    System.exit(0);

    }
    }

    }

  2. #2
    Join Date
    Dec 2008
    Posts
    202

    Re: i'm such a noob

    Hi Daren,

    This should work fine, what error message it is giving, please log the error message here so that I can help you.

    Regards

Similar Threads

  1. How can I Noob’s my first gaming PC?
    By Ouka in forum Hardware Peripherals
    Replies: 7
    Last Post: 24-09-2011, 04:09 PM
  2. please help a noob become stable overclock
    By Juggernaut in forum Overclocking & Computer Modification
    Replies: 2
    Last Post: 22-06-2011, 10:33 PM
  3. AMD Noob Looking For Wisdom
    By hardyB in forum Motherboard Processor & RAM
    Replies: 4
    Last Post: 18-12-2010, 10:16 AM
  4. Which antivirus for a noob?
    By SANDESH49 in forum Networking & Security
    Replies: 4
    Last Post: 18-08-2008, 01:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,513,157.75909 seconds with 16 queries