What I am trying to accomplish here is launching a program using three separate classes and I seem to get errors. I am relatively new to this and not entirely comprehend the java language yet. So please go easy on me and feel free to give me additional advice on anything that may be conducive to hone my skill.
package com.weightroom;
public class Baeyul { //?? ??
String name,gender;
int [] threemax = new int [3];
int weight,total,rank;
}
The second class
package com.weightroom;
import java.util.Scanner;
public class Record {
int inwon;
Baeyul[] bae;
Scanner sc= new Scanner(System.in);
public void set() {
do {
System.out.print("?? ?? ");
inwon= sc.nextInt();
}while(inwon<1||inwon>5);
bae= new Baeyul[inwon];
}
public void input() {
String[] title = {"???","???","???"};
//???
for(int i=0;i<inwon;i++) {
bae[i] = new Baeyul();
System.out.print((i+1)+ "?? ??? ");
bae[i].name = sc.next();
System.out.print("??? ");
bae[i].gender = sc.next();
System.out.print("???? ");
bae[i].weight = sc.nextInt();
for(int j=0;j<3;j++) { //????
System.out.print(title[j]);
bae[i].threemax[j] = sc.nextInt();
bae[i].total+= bae[i].threemax[j];
}
}
}
private void ranking() {
int i,j;
for (i=0;i<inwon;i++) {
bae[i].rank=1;
}
for(i=0;i<inwon-1;i++) {
for(j=1;j<inwon;j++) {
if(bae[i].total>bae[j].total) {
bae[j].rank++;
}else if(bae[i].total<bae[j].total) {
bae[i].rank++;
}
}
}
}
public void print() {
ranking();
for(int i=0;i<inwon;i++) {
System.out.printf("%6s", bae[i].name);
System.out.printf("%4s", bae[i].gender);
System.out.printf("%4d", bae[i].weight);
for(int j=0;j<3;j++) {
System.out.printf("%4d",bae[i].threemax);
}
System.out.printf("%4d",bae[i].total);
System.out.printf("%4d|n",bae[i].rank);
}
}
}
*The third class
package com.weightroom;
public class RecordUse {
public static void main(String[] args) {
Record li= new Record();
li.set();
li.input();
li.print();
}
}
launch
jamesException in thread "main" 1 100java.util.IllegalFormatConversionException: d != [I
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2793)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2747)
at java.util.Formatter.format(Formatter.java:2520)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at com.weightroom.Record.print(Record.java:83)
at com.weightroom.RecordUse.main(RecordUse.java:11)
question from:
https://stackoverflow.com/questions/65952127/using-3-classes-to-implement-a-program-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…