EXERCICIO 1:
import java.io.FileWriter;
import java.io.IOException;
public class FileWrite {
static void main(String[] args) {
String data = "Conteúdo para gravar no arquivo";
String hora = "Dados foram gravados!";
try (FileWriter escrever = new FileWriter("arquivo.txt")) {
escrever.write(data);
System.out.println(data);
System.out.println(hora);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Programa concluído");
}
}
====
EXERCICIO 2 e 3:
import com.google.gson.Gson;
public class Titulo {
static void main(String[] args) {
String nome = "Entre verdades e mentiras - vol. 3";
String nome2 = "Entre acasos e destinos - vol. 2";
String nome3 = "Entre perdas e ganhos - vol. 1";
Titulo titulo = new Titulo();
Gson gson = GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson("Livros do universo Letti: " + nome + " , " + nome2 + " , " + nome3 );
System.out.println(json);
}
}
===
EXERCICIO 4 :
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Veiculo {
static void main(String[] args) {
String modelo = "Compass - 4x4";
int ano = 2026;
String cor = "Preto";
double mediaPreco = 255000;
Veiculo veiculo = new Veiculo();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson("Modelo de veiculo atual: " + modelo + ", " + ano + ", " + cor + ", " + mediaPreco + " reais");
System.out.println(json);
}
}
====
Ps: tentei ao máximo fazer do meu jeito antes de conferir com a ideia do instrutor disponível, rodou e eu deixei kkkk :)