Hi there, I'm fairly new to java and I have a question about creating an array of objects for a class and allowing data entry for each individual object in the array.
I'm a little confused on how to go about doing this correctly.
As of right now I have about half of my project written for just one individual object as opposed to various different ones.
I'll show you, then explain:
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Random;
public class Subscriber {
public String name;
public String url;
public String friendsList = "";
public int adClicks = 0;
public int friendIndex = 1;
public int subNum = 0;
public static void main(String[] args) {
Subscriber subscriberList[MAX_NUM];
String anyMore;
StringTokenizer tokenizedList;
Random generator = new Random();
Scanner keyboard = new Scanner(System.in);
adClicks = generator.nextInt(100000);
System.out.println("Please enter your friend's name, last name first,"
+ "when prompted.");
System.out.println();
do
{
System.out.println("Name of friend (last name first!): ");
name = keyboard.nextLine().toUpperCase();
friendsList = friendsList.concat(name);
System.out.println("\nDo you want to enter another name? (Y/N): ");
anyMore = keyboard.nextLine().toUpperCase();
if (anyMore.equals("Y"))
{
friendsList = friendsList.concat(";");
System.out.println();
friendIndex ++;
}
} while(anyMore.equals("Y"));
tokenizedList = new StringTokenizer(friendsList, ";");
System.out.println("\n" + adClicks + " users have clicked on your ads.");
System.out.println("You have " + friendIndex +" friend(s): ");
while (tokenizedList.hasMoreTokens())
{
System.out.println(tokenizedList.nextToken());
}
}
}
As you can see I'm trying to create an array of objects for the Subscriber class. I'd like to be able to loop through entering as many subscribers as necessary as well as inputting and storing their data respectively.
I know this is simple stuff, but if you guys wouldn't mind giving me a push in the right direction that would be great. I'm fairly new to Java and programming as a whole (I've done some C++ work, but not much and it's been a while since then).
Thank you!