Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class P8_16
- {
- private static double totalPrice;
- private static int itemCount;
- private ArrayList<Double> items; //array for storing the values
- public P8_16()//constructor
- {
- this.totalPrice=0;
- this.itemCount=0;
- }
- private static ArrayList<Double> readUserInput()
- {
- Scanner in = new Scanner(System.in);
- ArrayList<Double> inputs = new ArrayList<Double>();
- while(in.hasNextDouble())
- {
- inputs.add(in.nextDouble());
- }
- return inputs;
- }
- public static int getCount(ArrayList<Double> prices)
- {
- int i = 0;
- while(i< prices.size())
- {
- itemCount++;
- i++;
- }
- return itemCount;
- }
- public static double addItem(ArrayList<Double> prices)
- {
- Scanner in = new Scanner(System.in);
- int i = 0;
- while(i< prices.size())
- {
- totalPrice = totalPrice + prices.get(i);
- i++;
- }
- return totalPrice;
- }
- public void clear()
- {
- itemCount = 0;
- totalPrice = 0;
- }
- public static void main (String [] args)
- {
- System.out.println("Please enter the values (price), enter 0 to quit");
- ArrayList<Double> prices = readUserInput();
- int count = getCount(prices);
- System.out.println("The count is: " + count);
- System.out.println("The total price is: " + addItem(prices));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement