Java Academic System [closed]

1

Hello .. I need help setting up a Java program with the following specifications:

1) Read the following items from the user: Name (String), Age (int), Genre (char [M or F]), Phone (String), Address (String), cpf (String), rg (String), Neighborhood uf (String), ra (if it is a student) (String), course (if it is a student) (String), rp (if it is a teacher) for teacher) (double).

2) It is necessary to create a class called "Student", which has the student attributes. - 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 the common attributes between Students and Teachers. - Created class

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 all Person data.

6) Use the polymorphism so that the Student class can override the "toString" method, so that it delegates to the superclass the writing of the attributes of the Person class and prints out the unique methods of the Student class.

7) Use the polymorphism, so that the Teacher class can override the "toString" method, so that it delegates to the superclass writing the attributes of the Person class and prints out the unique methods of the Teacher class.

(Where should I 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 (ie directly from the class). This method should not receive parameters and should print the following message: "Student Name - Student RA".

9) The user, when entering the data, must enter 1 to insert a Student or 2 to insert a Teacher. After selecting what you want to insert, you must enter the fields to be inserted in the respective register, that is, if it is 1, all Student data, if it is 2, all the teacher data. The data must be entered 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 should print the same.

11) Rules to follow: a) The registration of students under the age of 18 is not allowed. You should show a message asking you to enter the acceptable age b) The registration of teachers under 21 years old is not allowed. You should show a message asking you to enter the acceptable age;

(I do not know where to enter these rules)

    
asked by anonymous 16.08.2016 / 03:41

1 answer

2

1) You can use showInputDialog () in variables to make a dialog appear with a field to type. This would be the simplest way to get the data (not the prompt, of course). If it is by the prompt, use an object of type Scanner

String name = JOptionPane.showInputDialog("Digite o nome do aluno");

With Scanner:

in = new Scanner(System.in);
System.out.print("Digite um nome: ");
String input = in.nextLine();

2 and 3) Look for the basic structure of a Java class, also known as POJO. You would gain a lot of time if you could also use an IDE such as NetBeans or Eclipse for this.

4) To do this, first create a Person class, which you will be considering as the parent class of Student and Teacher. Ideally, data such as "name, age, gender ..." (all that both Students and Teachers may possess) are in this class. Look for examples of inheritance in Java.

5) To override toString, just add the method to the desired class (in this case, Person). Just use this.Atribute to reference the desired attributes in return.

public String toString() { 
return "Name: '" + this.name + "', Height: '" + this.height + "', Birthday: '" + this.bDay + "'"; }

6) You have written methods, but I believe you are referring to attributes. Just create a toString () within Student where you will only reference the attributes that the Person class does not have. (For example, RA).

7) Same thing, now with the unique data / attributes of the Teacher class.

8) Do you know when you start writing the method? To be able to call it without instantiating an object, add static in the header.

public static int MeuMetodo() {}

And to call, just call it from the class.

ClasseAluno.MeuMetodo()

9) This is pure programming logic. You just need to create lines of execution for each case. A very simple example of an if:

if(numero == 1) {
   // Faça o recebimento de aluno aqui 
} else if(numero == 2) {
   //Faça o recebimento do professor aqui
}else {
   System.out.println("Digite 1 ou 2!")
}

10) Use System.out.println in a for or while as long as it goes through all the attributes of who is being inserted / inserted. Easy.

11) Remember the if I showed you the question 9 ? Simply add these restrictions in the program flow, ideally upon receipt of the old variable.

I hope I have helped. I believe that with this information and considering that these are the only requirements, you will be able to finish everything quickly. (using, of course, if )

    
16.08.2016 / 04:11