1
Hello. I need help to build a Java program with the following specifications:
1) Read, from the user, the following items: Name(String), Age(int), gender(char[M or F]), telephone(String), address(String), Cpf(String), rg(String), neighborhood(String), city(String), Uf(String), ra (if it is a student)(String), course (if it is a student)(String), Rp(if it is a teacher)(String), course taught(if it is a teacher)(String), salary(if teacher)(double).
2) It is necessary to create a class called "Student", which has the attributes of students. - Created class
package SistemaAcademico;
public class Aluno extends Pessoa {
public Aluno(String nome, int idade, char genero, String telefone, String endereco, String cpf, String rg, String bairro, String cidade, String uf) {
super(nome, idade, genero, telefone, endereco, cpf, rg, bairro, cidade, uf);
}
String ra;
String curso;
}
3) It is necessary to create a class called "Teacher", which has the attributes of teachers. - Created Class
package SistemaAcademico;
public class Professor extends Pessoa {
public Professor(String nome, int idade, char genero, String telefone, String endereco, String cpf, String rg, String bairro, String cidade, String uf) {
super(nome, idade, genero, telefone, endereco, cpf, rg, bairro, cidade, uf);
}
String rp;
String disciplinaMinistrada;
double salario;
}
4) It is necessary to create a class called "Person", which has common attributes between Students and Teachers. - Class created
package SistemaAcademico;
import java.util.Scanner;
public class Pessoa {
private String nome;
private int idade;
private char genero;
private String telefone;
private String endereco;
private String cpf;
private String rg;
private String bairro;
private String cidade;
private String uf;
public Pessoa(String nome, int idade, char genero, String telefone, String endereco, String cpf, String rg, String bairro, String cidade, String uf) {
this.nome = nome;
this.idade = idade;
this.genero = genero;
this.telefone = telefone;
this.endereco = endereco;
this.cpf = cpf;
this.rg = rg;
this.bairro = bairro;
this.cidade = cidade;
this.uf = uf;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
public char getGenero() {
return genero;
}
public void setGenero(char genero) {
this.genero = genero;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getRg() {
return rg;
}
public void setRg(String rg) {
this.rg = rg;
}
public String getBairro() {
return bairro;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}
public String getUf() {
return uf;
}
public void setUf(String uf) {
this.uf = uf;
}
}
5) The Person class must have a method that overrides the "toString" method so that it prints out all Person data.
6) Use polymorphism, so that the Student class can override the "toString" method, so that it delegates the writing of the attributes of the Person class to the superclass and prints out the unique methods of the Student class.
7) Use polymorphism, so that the Teacher class can override the "toString" method, so that it delegates the writing of the attributes of the Person class to the superclass and prints out the unique methods of the Teacher class.
(Where I should use toString in each class ?)
8) Create a method with the identification name in the Main class, which can be called without the need to instantiate an object (i.e., directly from the class). This method should not receive parameters and should print the following message: "Student Name - Student AR".
9) The user, when entering the data, must enter 1 to enter a Student or 2 to enter a Teacher. After selecting what you want to enter, you must present the fields to be entered from the respective register, that is, if it is 1, all Student data, if it is 2, all teacher data. The data must be inserted into a variable of the selected type. - Created
package SistemaAcademico;
import java.util.Scanner;
public class Principal {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int opcao = 0;
do {
System.out.println("##ESCOLHA UMA OPÇÃO\n");
System.out.println("1 - Cadastrar Aluno");
System.out.println("2 - Cadastrar Professor");
System.out.println("3 - Sair\n");
System.out.println("Digite uma opção: ");
opcao = scan.nextInt();
switch (opcao){
case 1:
cadastro.cadastrarAluno();
break;
case 2:
cadastro.cadastrarProfessor();
break;
case 3:
break;
default:
System.out.println("Esta não é uma opção válida!");
}
} while (opcao !=3 );
}
}
10) After entering the data, the system shall print the same.
11) Rules to be followed: a) Registration of students under 18 years of age is not allowed. A message should be displayed requesting that you enter at the acceptable age b) Registration of teachers under the age of 21 is not allowed. A message should be displayed requesting to enter at the age acceptable;
(I don’t know where to put these rules)
What is the specific question? did you manage to solve any exercise? Edit the question and put in part specifies you have problem or doubt.
– rray
Your question is on number 11 then?
– rray
Welcome to Sopt. We’re here to help, but consider asking more specific questions next time. You can ask as many questions as you want. Making them separate help organize and sort the content, and increase the chance to help others. We count on your collaboration to take full advantage of the site’s help potential.
– Maniero