构造函数不能应用于给定的类型; 必需:java。 lang.String,java。郎。 String,int,int 发现:java。郎。串 原因:实际和正式的论点长度不同
当我尝试编译并且不知道如何修复它时,我一直收到此错误。
import java.util.Scanner;
public class TestTranscript {
public static void main(String[] args) {
Transcript t = new Transcript("student");
t.promptPIN();
t.printStudentInfo();
t.promptGrades();
t.printGrades();
t.printAverage();
}
}
该程序有两个文件用于作业。
import java.util.Scanner;
public class Transcript{
private int PIN = 164892; //student's personal identification number
private int grade1; //student's grades
private int grade2;
private int grade3;
private int grade4;
private int average; //student's total grade average
private String name; //student's full name
private String course; //student's course
private int year; //year student is attending
public Transcript(String name, String course, int year, int average)
{
this.name = name;
this.course = course;
this.year = year;
this.average = average;
}
//getters
public int getGrade1()
{
return grade1;
}
public int getGrade2()
{
return grade2;
}
public int getGrade3()
{
return grade3;
}
public int getGrade4()
{
return grade4;
}
//setters
public void setGrade1(int grade)
{
this.grade1 = grade;
}
public void setGrade2(int grade)
{
this.grade2 = grade;
}
public void setGrade3(int grade)
{
this.grade3 = grade;
}
public void setGrade4(int grade)
{
this.grade4 = grade;
}
public void printGrades(){
//grade 1
System.out.print("1st Grade: " + this.grade1 + " ");
if (grade1 < 101 && grade1 > 89) {
System.out.println("A");
} else if (grade1 < 90 && grade1 > 79) {
System.out.println("B");
} else if (grade1 < 80 && grade1 > 69) {
System.out.println("C");
} else if (grade1 < 70 && grade1 > 59) {
System.out.println("D");
} else if (grade1 < 60 && grade1 > 50) {
System.out.println("E");
} else if (grade1 <50 && grade1 > 0) {
System.out.println("F");
}
//grade 2
System.out.print("2nd Grade: " + this.grade2 + " ");
if (grade2 < 101 && grade2 > 89) {
System.out.println("A");
} else if (grade2 < 90 && grade2 > 79) {
System.out.println("B");
} else if (grade2 < 80 && grade2 > 69) {
System.out.println("C");
} else if (grade2 < 70 && grade2 > 59) {
System.out.println("D");
} else if (grade2 < 60 && grade2 > 50) {
System.out.println("E");
} else if (grade2 <50 && grade2 > 0) {
System.out.println("F");
}
//grade 3
System.out.print("3rd Grade: " + this.grade3 + " ");
if (grade3 < 101 && grade3 > 89) {
System.out.println("A");
} else if (grade3 < 90 && grade3 > 79) {
System.out.println("B");
} else if (grade3 < 80 && grade3 > 69) {
System.out.println("C");
} else if (grade3 < 70 && grade3 > 59) {
System.out.println("D");
} else if (grade3 < 60 && grade3 > 50) {
System.out.println("E");
} else if (grade3 <50 && grade3 > 0) {
System.out.println("F");
}
//grade 4
System.out.print("4th Grade: " + this.grade4 + " ");
if (grade4 < 101 && grade4 > 89) {
System.out.println("A");
} else if (grade4 < 90 && grade4 > 79) {
System.out.println("B");
} else if (grade4 < 80 && grade4 > 69) {
System.out.println("C");
} else if (grade4 < 70 && grade4 > 59) {
System.out.println("D");
} else if (grade4 < 60 && grade4 > 50) {
System.out.println("E");
} else if (grade4 <50 && grade4 > 0) {
System.out.println("F");
}
}
public void printStudentInfo() { //prints student's information
System.out.println("Student Information");
System.out.println(name); //prints student's name
System.out.println(course); //prints student's course
System.out.println(average); //prints student's grade average
System.out.println(year); //prints year of student's attendance
}
public void promptPIN() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter PIN: ");
while (sc.nextInt() != PIN) {
System.out.print("Invalid PIN");
}
}
public void promptGrades() {
Scanner sc = new Scanner(System.in);
System.out.println("Course 1: ");
this.grade1 = sc.nextInt();
System.out.println("Course 2: ");
this.grade2 = sc.nextInt();
System.out.println("Course 3: ");
this.grade3 = sc.nextInt();
System.out.println("Course 4: ");
sc.close();
}
public void printAverage() {
Scanner in = new Scanner(System.in);
average = (grade1 + grade2 + grade3 + grade4)/4;
System.out.println("Grade Average: " + average);
}
}
答案 0 :(得分:1)
您拥有 DataNode data = new DataNode();
data.getMap().put("testKey", "keyvalue");
data.getMap().put("myKey", "key value for my key");
:
constructor
但是像这样使用它:
public Transcript(String name, String course, int year, int average)
{
this.name = name;
this.course = course;
this.year = year;
this.average = average;
}
您需要其他参数。在你的情况下4。