In this task we need terminal. I tryied wrote javac Solution.java.
And I get
Command 'javac' not found, but can be installed with:
sudo apt install openjdk-11-jdk-headless # version 11.0.17+8-1ubuntu2~22.04, or
sudo apt install default-jdk # version 2:1.11-72build2
sudo apt install openjdk-17-jdk-headless # version 17.0.5+8-2ubuntu1~22.04
sudo apt install openjdk-18-jdk-headless # version 18.0.2+9-2~22.04
sudo apt install openjdk-19-jdk-headless # version 19.0.1+10-1ubuntu1~22.04
sudo apt install openjdk-8-jdk-headless # version 8u352-ga-1~22.04
sudo apt install ecj # version 3.16.0-1
I wrote -> sudo apt install openjdk-19-jdk-headless # version 19.0.1+10-1ubuntu1~22.04
and answer for my 0 error program, when I wrote another time -> javac Solution.java -> is :
Solution.java:16: error: cannot find symbol
public static List<Person> allPeople = new ArrayList<>();
^
symbol: class Person
location: class Solution
Solution.java:20: error: cannot find symbol
allPeople.add(Person.createMale("Donald Chump", new Date())); // id=0
^
symbol: variable Person
location: class Solution
Solution.java:21: error: cannot find symbol
allPeople.add(Person.createMale("Larry Gates", new Date())); // id=1
^
symbol: variable Person
location: class Solution
Solution.java:50: error: cannot find symbol
for (Person p : allPeople) {
^
symbol: class Person
location: class Solution
4 errors
I don't know what's going on. I don't understand why I haven't java in intelliji :(
package com.codegym.task.task17.task1710;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.*;
/*
CRUD
*/
public class Solution {
public static List<Person> allPeople = new ArrayList<>();
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static String line;
static {
allPeople.add(Person.createMale("Donald Chump", new Date())); // id=0
allPeople.add(Person.createMale("Larry Gates", new Date())); // id=1
try {
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws IOException {
// first option from crud -> -c
if (line.startsWith("-c"))
firstOption();
// second option -> -u (update)
if (line.startsWith("-u"))
secondOption();
// third option -> -d (delete)
if (line.startsWith("-d")) {
thirdOption();
}
// fourth option -> -i (displaying information)
if (line.startsWith("-i")) {
fourthOption();
}
System.out.println("-------");
for (Person p : allPeople) {
System.out.println(p);
}
System.out.println("-------");
reader.close();
}
// -c Washington m "04 15 1990"
public static void firstOption() {
String[] dateSplitting = line.split("\"");
String[] crudString = line.split(" ");
String name = crudString[1];
String sex = crudString[2];
String date = dateSplitting[1];
String[] finalDate = date.split(" ");
String month = finalDate[0];
String day = finalDate[1];
String year = finalDate[2];
if (sex.equals("m")) {
allPeople.add(Person.createMale(name, new Date(Integer.parseInt(year) - 1900, Integer.parseInt(month) - 1,
Integer.parseInt(day))));
} else {
allPeople.add(Person.createFemale(name, new Date(Integer.parseInt(year) - 1900, Integer.parseInt(month) - 1,
Integer.parseInt(day))));
}
System.out.println("id=" + (allPeople.size() - 1));
}
public static void secondOption() {
String[] crudString = line.split(" ");
String id = crudString[1];
String name = crudString[2];
String sex = crudString[3];
String month = crudString[4].replaceAll("\"", "");
String day = crudString[5];
String year = crudString[6].replaceAll("\"", "");
if (Integer.parseInt(id) < allPeople.size()) {
allPeople.remove(Integer.parseInt(id));
if (sex.equals("m")) {
allPeople.add(Integer.parseInt(id), Person.createMale(name, new Date(Integer.parseInt(year) - 1900, Integer.parseInt(month) - 1,
Integer.parseInt(day))));
} else {
allPeople.add(Integer.parseInt(id), Person.createFemale(name, new Date(Integer.parseInt(year) - 1900, Integer.parseInt(month) - 1,
Integer.parseInt(day))));
}
}
}
public static void thirdOption() {
String[] crudString = line.split(" ");
int id = Integer.parseInt(crudString[1]);
allPeople.get(id).setBirthDate(null);
allPeople.get(id).setSex(null);
allPeople.get(id).setName(null);
}
public static void fourthOption() {
String[] crudString = line.split(" ");
int id = Integer.parseInt(crudString[1]);
String name = allPeople.get(id).getName();
String sex = allPeople.get(id).getSex() == Sex.MALE ? "m" : "f";
Date date = allPeople.get(id).getBirthDate();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH);
String formattedDate = simpleDateFormat.format(date);
System.out.printf(name + " " + sex + " " + formattedDate);
}
}