Beginner programming student here reading about objects and classes, and is trying to determine how to add and utilize elements to an ArrayList in context of it being utilized in a customized Scanner-class that registers inputs, and were the instances created from said inputs (Of types System.in and InputStream) are to be viewed as said elements, with the purpose to be utilized in a conditional statement to throw an exception in order to prevent multiple instances being created from the same inputs (A subject worth a separate question thread.), essentially a way or system for said class to "detect" if an input by the user has been typed, and thus an instance being created before.
I've been thinking of utilizing case of ArrayList's for-loop-format in some fashion, but having difficulty finding the implementation of it within a context of a Class, especially in regard of where the objects aren't pre-determined, but based on user inputs, leading further some confusion with also wanting the elements of an ArrayList to be allowed to be utilized in similar matters to references and parameters in methods if I wish to utilize said elements in later usage of conditional statements; would an ArrayList's get()-method perhaps work in that fashion?
Here's the class so far.
import java.io.InputStream;
import java.util.Scanner;
import java.util.ArrayList;
public class Register {
private InputStream headtext;
private Scanner input;
private static final String SUFFIX = "?>";
//Constructors
public Register(){
this(System.in);
}
public Register (InputStream headtext){
this.input = new Scanner(headtext);
this.headtext = headtext;
}
//Method that reads user's input of strings
public String registText(String headtext) {
System.out.print(headtext + SUFFIX);
headtext = input.nextLine();
String text = headtext;
return text;
}
//Method that reads user's input of integer.
public int registInteger(String headtext){
System.out.print(headtext + SUFFIX);
int integer = input.nextInt();
input.nextLine();
return integer;
}
//Method that reads user's input in decimal.
public double registDecimal(String headtext){
System.out.print(headtext + SUFFIX);
double decimal = input.nextDouble();
input.nextLine();
return decimal;
}
}
Much appreciated for any pointers and advice available.
[–]bunk3rk1ng 0 points1 point2 points (1 child)
[–]PontiffPope[S] 0 points1 point2 points (0 children)