0

I need help making this to display the results into a Jframe GUI instead of a console im failry new to java so please help me thanks, here is the code ive used:

import java.util.ArrayList;

public class ThreeArrayLists {

    public static void main(String[] args) {
        ArrayList priceList = new ArrayList();
        ArrayList quantityList = new ArrayList();
        ArrayList amountList = new ArrayList();
        //PRICE lIST
        priceList.add(new Double(10.62));
        priceList.add(new Double(14.89));
        priceList.add(new Double(13.21));
        priceList.add(new Double(16.55));
        priceList.add(new Double(18.62));
        priceList.add(new Double(9.47));
        priceList.add(new Double(6.58));
        priceList.add(new Double(18.32));
        priceList.add(new Double(12.15));
        priceList.add(new Double(3.98));
        //QUANTITY LIST   
        quantityList.add(new Double(4.0));
        quantityList.add(new Double(8.5));
        quantityList.add(new Double(6.0));
        quantityList.add(new Double(7.35));
        quantityList.add(new Double(9.0));

        quantityList.add(new Double(15.3));
        quantityList.add(new Double(3));
        quantityList.add(new Double(5.4));
        quantityList.add(new Double(2.9));
        quantityList.add(new Double(4.8));

        extend(amountList, quantityList, priceList);
        displayList(quantityList, priceList, amountList);


    }

    private static void displayList(ArrayList quantityList, ArrayList priceList, ArrayList amountList)  {

        for (int i = 0; i < 10; i++) {

            System.out.format("%d)  %.2f * %.2f = %.2f \n",i+1, Double.valueOf(priceList.get(i).toString()), Double.valueOf(quantityList.get(i).toString()), Double.valueOf(amountList.get(i).toString()));
        }
    }

    private static void extend(ArrayList amountList, ArrayList quantityList, ArrayList priceList) {

        for (int i = 0; i < 10; i++) {
            amountList.add((Double.valueOf(priceList.get(i).toString())) * (Double.valueOf(quantityList.get(i).toString())));

        }

    }
}

Edited by ccsj2206: errors

4
Contributors
5
Replies
12
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

I havente declared the Jframe becasue i am only using a console in this example, just trying to get a visual example...and yesi have been to that link and used it quite often thanks

0

Your use of ArrayLists corresponds to how Java was years ago, before version 1.5, and that's why your calculations (line 50) are difficult.
With modern Java you can declare what kind of Objects the ArrayList can hold, eg
ArrayList<Double> priceList = new ArrayList<Double>();
now Java knows the contents will always be Doubles, so priceList.get(i) will always return a Double, so you can just use it, eg
amountList.add(priceList.get(i) * quantityList.get(i));

Let us know how you are getting on with yout GUI.

0

I am actualy working on the same program and have also been able to create a GUI and show console output, but can not get the console output to display in my GUI, specifically a textArea.

0

Hi jakhondi
Welcome to DaniWeb

Please start your own new thread for your question, and explain exactly what the problem is, and post the relevant code so someone can help you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.