Java将信息从一个类访问到另一个类

Java将信息从一个类访问到另一个类,java,class,oop,static,Java,Class,Oop,Static,我正在做我的家庭作业,我目前正试图把note和compt放在noter()到moyenne()中,这样我就可以对输入的笔记进行平均,这些笔记将放在20张表格中 谷歌驱动链接,供想查看的人使用:(pdf,法文内容): 下面是每个级别的noter() public static int noter() { int compt = 0; int note = 0; Scanner sc = new Scanner(System.in);

我正在做我的家庭作业,我目前正试图把note和compt放在noter()到moyenne()中,这样我就可以对输入的笔记进行平均,这些笔记将放在20张表格中

谷歌驱动链接,供想查看的人使用:(pdf,法文内容):

下面是每个级别的noter()

public static int noter() {
        int compt = 0;
        int note = 0;

        Scanner sc = new Scanner(System.in);

        do {
            System.out.println("Veuillez entrer la note de l'etudiant: ");
            note = sc.nextInt();
            compt++;
        } while (note != -1);

        System.out.println(compt);

        return compt;
    }`
这是所有学生的平均成绩

    public static int moyenne() {
int etudiant[i].moyenne = 0;  

    etudiant[i].moyenne = etudiant[i].noter.note/ etudiant[i].noter.compt;
    return etudiant[i].moyenne;
}
还有完整的代码,您可以看到我所说的内容表:

import java.util.Scanner;  // Utiliser mode console

public class GestEtudiant {

    private static String code;
    static Etudiant[] etudiant = new Etudiant[20]; // Attributs statiques
    static int nbreEtudiants; // comment mettre pour ne depasse pas 20

        // Méthodes statiques
    public static  int  ajoutEtudiant() {
        String nomTemp, prenomTemp;
        int anneeNaisTemp;

        Scanner sc = new Scanner(System.in);
        //Etudiant monEtudiant = new Etudiant();

        for (int i = 0; i < etudiant.length; i++) {
            System.out.println("Entrer les informations suivantes:\n1-Nom:\n2-Prenom:\n3-Annee de naissance:");

            nomTemp = sc.next();
            prenomTemp = sc.next();
            anneeNaisTemp = sc.nextInt();

            etudiant[i] = new Etudiant(nomTemp, prenomTemp, anneeNaisTemp);
            System.out.println(etudiant[i].code);

            if (i > 20) {
                System.out.println("Une erreur c'est produite, la limite d'etudiants a ete depassee, l'ajout n'a pas eu lieu ");
            }
        }

        return 0;
    }

    public static int noter() {
        int compt = 0;
        int note = 0;

        Scanner sc = new Scanner(System.in);

        do {
            System.out.println("Veuillez entrer la note de l'etudiant: ");
            note = sc.nextInt();
            compt++;
        } while (note != -1);

        System.out.println(compt);

        return compt;
    }

    public static int moyenne() {
    int etudiant[i].moyenne = 0;  

        etudiant[i].moyenne = etudiant[i].noter.note/ etudiant[i].noter.compt;
        return etudiant[i].moyenne;
    }

    public static double meilleur() {
        // A compléter ..
        return 0;
    }

    public static double tauxEchec() {
        // A compléter ..
        return 0;
    }

        // Méthode principale
    public static void main(String args []) {
        Scanner sc = new Scanner(System.in);
        int option;

            //Menu répétitif
        do {
            System.out.println("Quelle opération voulez-vous effectuer?\n(1) Inscrire un étudiant.\n(2) Entrer les notes des étudiants.\n(3) Afficher les étudiants.\n(4) Afficher les statistiques.\n(5) Quitter l'application.\n\n");
            option = sc.nextInt();

            switch(option) {

                case 1: { //Inscrire
                        // A compléter ..
                    break;
                }

                case 2: { //Noter
                    // A compléter ..
                    break;
                }

                case 3: { //Afficher
                    // A compléter ..
                    break;
                }

                case 4: { //Statistiques
                    // A compléter ..
                    break;
                }

                case 5: { //Quitter
                    // A compléter ..
                    break;
                }

                default: {
                    System.out.println("Choix Invalide - doit être compris entre 1 et 5");
                }
            } // fin du switch
        } while (option != 5); // fin de la boucle
    } //fin main
} //fin classe
import java.util.Scanner;//利用者模式控制台
公开课指导学生{
私有静态字符串代码;
静态Etudiant[]Etudiant=新Etudiant[20];//属性统计
static int nbreEtudiants;//注释mettre pour ne depasse pas 20
//Méthodes statiques
公共静态int-ajoutudiant(){
字符串nomTemp,prenomTemp;
int ANNENAISTEMP;
扫描仪sc=新的扫描仪(System.in);
//Etudiant monEtudiant=新的Etudiant();
for(int i=0;i20){
系统输出打印(“不需要产品,不需要用户,不需要用户”);
}
}
返回0;
}
公共静态int noter(){
int compt=0;
int note=0;
扫描仪sc=新的扫描仪(System.in);
做{
系统输出打印(“Veuillez enter la note de l'etudiant:”);
注=sc.nextInt();
compt++;
}while(注意!=-1);
系统输出打印项次(compt);
返回compt;
}
公共静态int moyenne(){
国际学生[i].moyenne=0;
etudiant[i].moyenne=etudiant[i].noter.note/etudiant[i].noter.compt;
return-etudiant[i].moyenne;
}
公共静态双meilleur(){
//公司。。
返回0;
}
公共静态双tauxEchec(){
//公司。。
返回0;
}
//Méthode principale
公共静态void main(字符串参数[]){
扫描仪sc=新的扫描仪(System.in);
int选项;
//菜单répétitif
做{
系统输出打印(“请操作”©定量您的效果?\n(1)在申请表中。\n(2)申请表。\n(3)申请表。©申请表。\ n(4)申请表。\ n(5)退出申请表。\ n\n”);
option=sc.nextInt();
开关(选件){
案例1:{//Inscrire
//公司。。
打破
}
案例2:{//Noter
//公司。。
打破
}
案例3:{//Afficher
//公司。。
打破
}
案例4:{//Statistiques
//公司。。
打破
}
案例5:{//Quitter
//公司。。
打破
}
默认值:{
系统输出打印(“伤残军人院-第1和第5中心”);
}
}//fin du开关
}while(选项!=5);//fin de la boucle
}//主鳍
}//金融类
另外,您可以执行以下操作: 在方法noter()中直接指定平均值(moyenne),如下所示:

    do {
        System.out.println("Veuillez entrer la note de l'etudiant: ");
        note += sc.nextInt(); // note here you have to add all values
        compt++;
    } while (note != -1);
    System.out.println(compt);
    etudiant[i].moyenne = note / compt;
Alors,你可以这样做: 在方法noter()中直接指定平均值(moyenne),如下所示:

    do {
        System.out.println("Veuillez entrer la note de l'etudiant: ");
        note += sc.nextInt(); // note here you have to add all values
        compt++;
    } while (note != -1);
    System.out.println(compt);
    etudiant[i].moyenne = note / compt;

那么问题出在哪里呢?在莫延恩,我无法将noter的成绩“转移”到莫延恩,以对所有20名学生进行平均。请注意,noter是以1乘以1的方式计算每个学生的所有成绩。以下是我现在正在尝试的:您甚至没有保存输入的笔记。在noter()方法中,将最后输入的注释保存为单个int,并每次重写它。因此,在局部变量中只有最后输入的注释,并且一旦mthod运行完毕,垃圾收集器将删除该注释。在考虑如何从其他地方访问数据之前,应该首先考虑一种数据结构,在该结构中实际存储输入的注释。因为您无法传输/访问当前不存在的内容。以下是我现在正在尝试的:
public static int noter(){int compt=0;int note=0;Scanner sc=new Scanner(System.in);do{System.out.println(“Veuillez enter la note de l'etudiant:”;note=sc.nextInt();compt++}while(note!=-1);System.out.println(compt);int moyenne=0;moyenne=note/compt;return compt;}
那么问题出在哪里?在moyenne我不能“转移”noter到moyenne的分数计算20名学生的平均值注意noter是1乘1计算每个学生的所有分数这是我现在正在尝试的:你甚至没有把输入的笔记保存在任何地方。在noter()方法中,将最后输入的注释保存为单个int,并每次重写它。因此,在局部变量中只有最后输入的注释,并且一旦mthod运行完毕,垃圾收集器将删除该注释。在考虑如何从其他地方访问数据之前,应该首先考虑一种数据结构,在该结构中实际存储输入的注释。因为您无法传输/访问当前不存在的内容。以下是我现在正在尝试的:
public static int noter(){int compt=0;int note=0;Scanner sc=new Scanner(System.in);do{System.out.println(“Veuillez enter la