simulated datsets in java
import java.util.*;
import java.io.*;
class Student{
String id,firstname,lastname,city;
Student(String firstname,String lastname,String city){
this.id=UUID.randomUUID().toString();
this.firstname=firstname;
this.lastname=lastname;
this.city=city;
}
}
public class uid {
public static void main(String[] args){
ArrayList<Student> student=new ArrayList<>();
Scanner sc=new Scanner(System.in);
System.out.println("Enter no. of records:");
int n=sc.nextInt();
sc.nextLine();
int count=0;
while(n-->0){
System.out.println("Enter the record details for s"+(count+1)+":");
String firstname=sc.nextLine();
String lastname=sc.nextLine();
String city=sc.nextLine();
Student s=new Student(firstname,lastname,city);
student.add(s);
count++;
}
try{
FileWriter fw=new FileWriter("students.csv");
fw.write("ID,FIRSTNAME,LASTNAME,CITY\n");
for(Student s:student)
fw.write(s.id+","+s.firstname+","+s.lastname+","+s.city+"\n");
fw.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
output:
C:\Users\akhil\OneDrive\Desktop\cn>javac uid.java
C:\Users\akhil\OneDrive\Desktop\cn>java uid
Enter no. of records:
5
Enter the record details for s1:
101
akhil
darapu
Enter the record details for s2:
akhil
dara
tpe
Enter the record details for s3:
eee
dd
ee
Enter the record details for s4:
eee
dd
ddd
Enter the record details for s5:
dddd
eee
rrr
Comments
Post a Comment