Skip to content

Instantly share code, notes, and snippets.

@audunolsen
Created June 13, 2024 16:11
Show Gist options
  • Save audunolsen/6e4272a7e1e36df1c6cb4fbc3c04de9f to your computer and use it in GitHub Desktop.
Save audunolsen/6e4272a7e1e36df1c6cb4fbc3c04de9f to your computer and use it in GitHub Desktop.
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class PopulateDatabase {
// Main for del 1
public static void main(String[] args) {
try {
File file = new File("funn.txt");
Scanner scanner = new Scanner(file);
List<String> personData = new ArrayList<>();
List<String> museumData = new ArrayList<>();
List<String> findingsData = new ArrayList<>();
List<String> currentList = personData;
boolean skip = true;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (skip) {
skip = false;
continue;
}
if (line.equals("Personer:")) {
skip = true;
currentList = personData;
}
if (line.equals("Museer:")) {
skip = true;
currentList = museumData;
}
if (line.equals("Funn:")) {
currentList = findingsData;
}
currentList.add(line);
}
ParsePeople(String.join("\n", personData));
ParseMuseums(String.join("\n", museumData));
ParseFindings(String.join("\n", findingsData));
} catch (Exception e) {
System.out.println("Error reading file");
e.printStackTrace();
}
}
private static void ParsePeople(String input) {
List<Person> people = new ArrayList<>();
Scanner scanner = new Scanner(input);
int peopleCount = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < peopleCount; i++) {
int personId = Integer.parseInt(scanner.nextLine());
String name = scanner.nextLine();
String phone = scanner.nextLine();
String email = scanner.nextLine();
people.add(new Person(personId, name, phone, email));
}
for (Person person : people) {
person.insertIntoDB();
}
}
private static void ParseMuseums(String input) {
}
private static void ParseFindings(String input) {
}
}
class Person {
private int id;
private String name;
private String phone;
private String email;
public Person(int id, String name, String phone, String email) {
this.id = id;
this.name = name;
this.phone = phone;
this.email = email;
}
public void insertIntoDB() {
System.out.println("INSERTEDDDD");
System.out.println(this.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment