ArrayList in Java and inputting

What you need in your loop condition is:

while ( input.get( input.size()-1 ) != end_signal );

What you're doing is decrementing the counter variable.

Also you should declare the ArrayList like so:

ArrayList<Double> list = new ArrayList<Double>();

This makes the list type-specific and allows the condition as given. Otherwise there's extra casting.


Answers:

>1. I can't seem to get the input loop to work out, what's the best practice for doing so.

I would rather have a simple while loop instead of a do{}while... and place the condition in the while... In my example it read:

while the read number is not end signal and count is lower than limit: do.

>2. What is the object-type going to be for the reading method? A double[], or an ArrayList?

An ArrayList, however I would strongly recommend you to use List ( java.util.List ) interface instead. It is a good OO practice to program to the interface rather to the implementation.

>2.1How do I declare method-type to be an arraylist?

See code below.

>2.2. How do I prevent the array from having more than 1000 values stored within it?

By adding this restriction in the while condition.

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class InputTest{
    
    private int INPUT_LIMIT = 10000;

    public static void main( String [] args ) {
        InputTest test = new InputTest();
        System.out.println("Start typing numbers...");
        List list = test.readRange( 2.0 );
        System.out.println("The input was " +  list );
    }

    /**
     * Read from the standar input until endSignal number is typed.
     * Also limits the amount of entered numbers to 10000;
     * @return a list with the numbers.
     */
    public List readRange( double endSignal ) {
        List<Double> input = new ArrayList<Double>();
        Scanner kdb = new Scanner( System.in );
        int count = 0;
        double number = 0;
        while( ( number = kdb.nextDouble() ) != endSignal && count < INPUT_LIMIT ){
            System.out.println( number );
            input.add( number );
        }
        return input;
    }
}

Final remarks:

It is preferred to have "instance methods" than class methods. This way if needed the "readRange" could be handled by a subclass without having to change the signature, thus In the sample I've removed the "static" keyword an create an instance of "InputTest" class

In java code style the variable names should go in cammel case like in "endSignal" rather than "end_signal"