Hallo Leute!
Ich habe eine Frage zu meiner aktuellen Hausaufgabe die sich um Klassen und Methoden dreht.
Ich habe meinen Code für das Überprüfungsprogramm anpassen müssen und jetzt geht auf einmal
gar nichts mehr und ich weiß nicht warum. Hier mal der Code:
Testprogramm:
Und die dazugehörige Klasse:
Errorcode:
Zusätzlich bekomme ich im Editor folgende Fehler angezeigt:
(Jeweils in den Methoden Headern der Histo-Klasse!)
Ein Hinweis in die richtige Richtung oder die richtige Frage wären
vollkommen genug!
Vielen Dank im Voraus!
Ich habe eine Frage zu meiner aktuellen Hausaufgabe die sich um Klassen und Methoden dreht.
Ich habe meinen Code für das Überprüfungsprogramm anpassen müssen und jetzt geht auf einmal
gar nichts mehr und ich weiß nicht warum. Hier mal der Code:
Testprogramm:
Java:
import java.util.Arrays;
//import java.util.*;
public class Bsp11 {
/**
* @param args
*/
public static void main(String[] args) {
/* VARIABLEN */
int arrLength = (int)(50.0 * Math.random()) + 50; //Mindestens 50 + 50rnd
int[] grades = new int[arrLength];
int maxGrade = 5;
int rnd;
/* STARTARRAY FÜLLEN */
for(int i = 0; i < arrLength; i++){
rnd = (int)(maxGrade * Math.random()) + 1;
grades[i] = rnd;
}
/* NEUES HISTO OBJEKT MIT NOTEN ERSTELLEN */
Histo chart = new Histo();
System.out.println(Arrays.toString(chart.getCountGrade()));
System.out.println(chart.getTotalGrades());
/* USER BEZOGENER INPUT */
//Noten hinzufügen
int ag = SavitchIn.readInt();
chart.enter(ag);
//Array hinzufügen
System.out.println("Wieviele Noten möchten Sie hinzufügen?");
int n = SavitchIn.readInt();
int[] nga = new int[n];
for(int i = 0; i < n; i++){
nga[i] = SavitchIn.readInt();
}
chart.enter(nga);
System.out.println("Eingabe abgeschlossen!");
//Prozentsatz einer Note berechnen
System.out.println("Berechne Prozentsatz:");
int gp = SavitchIn.readInt();
System.out.println(chart.getPercentage(gp));
//Anzahl einer Note berechnen
System.out.println("Berechne Anzahl:");
int gc = SavitchIn.readInt();
System.out.println(chart.getCountGrade(gc));
//...
chart.displayHisto();
}
}
Und die dazugehörige Klasse:
Java:
import java.util.Arrays;
public class Histo {
/* global variables */
public Histo() {
int[] gradesGlobal;
/* resize gradesGlobal */
public void rgc(){
int[] gGNew = new int[gradesGlobal.length + 1];
for(int i = 1; i < gradesGlobal.length; i++){
gGNew[i] = gradesGlobal[i];
}
gradesGlobal = gGNew;
}
/* constructor: initializes the Histo object with an array of grades */
public Histo(int[] grades){
gradesGlobal = grades;
}
/* add one grade from 1-5 */
public void enter (int grade){
if(gradesGlobal[gradesGlobal.length - 1] == 0) rgc();
for(int i = 0; i < gradesGlobal.length; i++){
if(gradesGlobal[i] == 0){
gradesGlobal[i] = grade;
break;
}
}
}
/* add an array of grades like {1, 1, 5, 3, 5, 5, 5, 3, 2, 4, 2} */
public void enter (int[] grades){
}
/* get percentage of the given grade */
public double getPercentage(int grade){
double gp = 0;
for(int i = 0; i < this.getCountGrade().length; i++){
if((i + 1) == grade) {
gp = ((double)this.gradesGlobal.length / 100.0) * (double)this.getCountGrade()[i];
break;
}
}
return gp; //Grade Percentage
}
/* get percentages of all grades */
/* (percentage of 1 -> first array element, percentage of 5 -> last array element) */
public double[] getPercentage(){
double[] gpa = new double[this.getCountGrade().length];
int totCount = this.gradesGlobal.length;
for(int i = 0; i < this.getCountGrade().length; i++){
gpa[i] = ((double)totCount / 100.0) * (double)this.getCountGrade()[i];
}
return gpa; //Grade Percentage All
}
/* get count of the given grade */
public int getCountGrade(int grade){
int gc = 0;
for(int i = 0; i < this.getCountGrade().length; i++){
if((i + 1) == grade){
gc = this.getCountGrade()[i];
break;
}
}
return gc; //Grade Count
}
/* get counts of all grades */
/* (count of 1 -> first array element, count of 5 -> last array element) */
public int[] getCountGrade(){
int[] count = new int[5]; //Noten von 1 - 5
for(int i = 0; i < gradesGlobal.length; i++){
int grade = gradesGlobal[i];
for(int j = 1; j <= count.length; j++){
if(grade == j) count[j-1]++;
}
}
return count;
}
/* get the total count of all grades */
public int getTotalGrades(){
int totCount = gradesGlobal.length;
return totCount;
}
/* returns the average of all grades */
public double average(){
double ave = 0;
for(int i = 0; i < gradesGlobal.length; i++){
ave = (ave + gradesGlobal[i]) / i;
}
return ave;
}
/* show bar chart like in the example above; one X represents 2% (rounded) */
public void displayHisto(){
int[] cross = new int[this.getCountGrade().length];
int max1 = 0;
int max2 = 0;
for(int i = 0; i < this.getCountGrade().length; i++){
cross[i] = (int)this.getPercentage()[i] / 2;
if(cross[i] > max1) max1 = cross[i];
}
max2 = max1;
for(int i = 0; i < max2; i++){
System.out.print(" ");
for(int j = 0; j < cross.length; j++){
if(cross[j] >= max1) System.out.print("X ");
else System.out.print(" ");
}
System.out.println();
max1--;
}
System.out.println(" ---------");
System.out.println("Note: 1 2 3 4 5");
System.out.println("Gesamtanzahl: " + gradesGlobal.length);
}
}
}
Errorcode:
Code:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method getCountGrade() is undefined for the type Histo
The method getTotalGrades() is undefined for the type Histo
The method enter(int) is undefined for the type Histo
The method enter(int[]) is undefined for the type Histo
The method getPercentage(int) is undefined for the type Histo
The method getCountGrade(int) is undefined for the type Histo
The method displayHisto() is undefined for the type Histo
at Bsp11.main(Bsp11.java:30)
Zusätzlich bekomme ich im Editor folgende Fehler angezeigt:
(Jeweils in den Methoden Headern der Histo-Klasse!)
Code:
Multiple markers at this line
- Syntax error, insert "enum Identifier" to complete
EnumHeaderName
- Syntax error, insert "EnumBody" to complete BlockStatement
- Syntax error on token "void", @ expected
Ein Hinweis in die richtige Richtung oder die richtige Frage wären
vollkommen genug!
Vielen Dank im Voraus!