I cannot get to print out all my information.
I have written this code but i am having trouble printing out all the information at the end. Should I use ToString? Any help would be appreciated.
Code :
package drycleaner;
import java.util.Scanner;
/**
*
* @author Kl2eativ
*/
public class DryCleaning {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("For how many stores do you want to enter information for? ");
int storeNum = s.nextInt();
String[] dryCleaningStores = new String[storeNum];
s.nextLine();
for (int i = 0; i < storeNum; i++)
{
System.out.println("Please enter the store name: ");
String st = s.nextLine();
System.out.println("Enter total sales: ");
double ts = s.nextDouble();
System.out.println("Enter total of machines broken: ");
int mb = s.nextInt();
System.out.println("Number of employees: ");
int emp = s.nextInt();
s.nextLine();
}
}
}
Re: I cannot get to print out all my information.
Quote:
Originally Posted by
kl2eativ
I have written this code but i am having trouble printing out all the information at the end.
First of all, what are you having trouble with? You seem to be using println statements correctly. Can you please be more specific about what you are trying to print out?
Re: I cannot get to print out all my information.
Sorry if I did not make myself clear, When I ask for how many stores does the user wants to enter info for, Lets say he puts in 3, after the info for all 3 have been inputted, i want to print the info for all 3. Like say, This is the information for all 3 stores.
Re: I cannot get to print out all my information.
Why don't you use ArrayList then?
Have a method, something which would get called for every store information. Once you receive your parameters, pass them along to it and store them in ArrayList.
Your method should look like,
Code java:
public void add(String a, double b, int c, int d)
Refer how to add to ArrayList here: ArrayList add
Then once you are done with 3 inputs, iterate over the Arraylist and display all the info stored. As ArrayList adds the data sequentially, you would get the things in the same order as you have added them.
Hope that helps,
Goldest
Re: I cannot get to print out all my information.
I thought about that but I have to use an array :(