Java Academic System

Asked

Viewed 1,846 times

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)

  • 2

    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.

  • Your question is on number 11 then?

  • 1

    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.

1 answer

2


1) You can use showInputDialog() on variables to bring up a dialog with a input field. This would be the simplest way to receive the data (other than by the prompt, of course). If by the prompt, use a scanner object

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

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. It would save you a lot of time if you could also use an IDE like Netbeans or Eclipse for this.

4) For this, first create a Person class, which you will be considering as the parent class of Student and Teacher. The ideal is that data such as "name, age, gender..." (all that both Students and Teachers can 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. Attribute 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. Simply 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) Know when you start writing the method? In order 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 only need to create execution lines for each case. 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 on one for or while, since it goes through all the attributes of who is being inserted/has been inserted. Quiet.

11)Remember if I showed you at question 9? Simply add these restrictions into the program flow, ideally after receiving the age variable.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.