i have written a simple object array which takes five strings. what i am trying to do is is use a for loop to create to entries in the object array at position 0 and 1. Then create a folder which holds a text file for position 0 and the create a folder which holds a text file for position 1. The expected result
folder0-> 0.txt
text file content
Jeremey 12 male 120 120
Somebody 12 female 100 100
folder1-> 1.txt
text file content
Jeremey 12 male 120 120
Somebody 12 female 100 100
the following is sample of code already written.
object array class:
public class Info
{
private String Name;
private String age;
private String Gender;
private String Height;
private String weight;
Info(String Name, String age, String Gender, String Height, String weight)
{
this.Name = Name;
this.age = age;
this.Gender = Gender;
this.Height = Height;
this.weight = weight;
}
public String getName()
{
return this.Name;
}
public String getAge()
{
return this.age;
}
public String getGender()
{
return this.Gender;
}
public String getHeight()
{
return this.Height;
}
public String getWeight()
{
return this.weight;
}
}
Main class:
import java.util.*;
public class UseInfo
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);
Info infor[] = new Info[2];
for(int i = 0; i < 2; i++)
{
System.out.println("Please enter Name: ");
String name = in.nextLine();
System.out.println("Please enter age: ");
String age = in.nextLine();
System.out.println("Please enter Gender: ");
String gender = in.nextLine();
System.out.println("Please enter Height: ");
String height = in.nextLine();
System.out.println("Please enter Weight: ");
String weight = in.nextLine();
infor[i] = new Info(name, age, gender, height, weight);
}
for(int k = 0; k < infor.length; k++)
{
System.out.println("Name : " + infor[k].getName() + " Age : " + infor[k].getAge() + " Gender : " + infor[k].getGender() + " Height : " + infor[k].getHeight() + " Weight : " + infor[k].getWeight() );
}
}
}
I cant figure out how to take the information from the array and pass it in to a file and store file in folder.