Cumulative project 2 returns 4 errors

I am nearly finishing the Unquote project (Cumulative project 2), but only to find out a bunch of errors in my code snippets.

Here’s my AndroidOS. java

public class AndroidOS {
    public AndroidOS() {
        System.out.println("AndroidOS Booting Up...");
    }

    public void runQuizApp() {
        // Create three questions here
        Question question1 = new Question(921238, "1024 ft", "1063 ft", "1124 ft", "1163 ft", 1);
        
        Question question2 = new Question(107343, "Charles Babbage", "John Carmack", "Alan Turing", "Ada Lovelace", 3);

        Question question3 = new Question(748294, "What is the name for the patch of skin found on your elbow", "Fascia Elbora", "Wenis", "Todd", 2);
        
        System.out.println("Question 1: " + question1.questionText);
        
    }

    public static void main(String[] args) {
        System.out.println("Starting: AndroidOS");
        AndroidOS androidOS = new AndroidOS();
        androidOS.runQuizApp();
    }
}

The errors are:

AndroidOS.java:8: error: constructor Question in class Question cannot be applied to given types;
        Question question1 = new Question(921238, "1024 ft", "1063 ft", "1124 ft", "1163 ft", 1);
                             ^
  required: int,String,String,String,String,String,int
  found: int,String,String,String,String,int
  reason: actual and formal argument lists differ in length
AndroidOS.java:10: error: constructor Question in class Question cannot be applied to given types;
        Question question2 = new Question(107343, "Charles Babbage", "John Carmack", "Alan Turing", "Ada Lovelace", 3);
                             ^
  required: int,String,String,String,String,String,int
  found: int,String,String,String,String,int
  reason: actual and formal argument lists differ in length
AndroidOS.java:12: error: constructor Question in class Question cannot be applied to given types;
        Question question3 = new Question(748294, "What is the name for the patch of skin found on your elbow", "Fascia Elbora", "Wenis", "Todd", 2);
                             ^
  required: int,String,String,String,String,String,int
  found: int,String,String,String,String,int
  reason: actual and formal argument lists differ in length
./Question.java:22: error: incompatible types: int cannot be converted to String
    imageId = imageIdentifier;
              ^
4 errors

I appreciate any insights as to what went wrong here.

It seems that the Question class accepts 7 arguments, but you’ve only provided it with 6. Are you missing an argument when you initiate a Question object, or did you put too many parameters in your Question constructor?

Thank you for getting back to me @codeneutrino . I actually missed an argument for every single question on public void runQuizApp(), the errors for this are gone once I added them.

Still, there’s one more error left and I have absolutely no clue about the fix.

Question.java:15: error: incompatible types: int cannot be converted to String
    imageId = imageIdentifier;
              ^
1 error

And the corresponding code is here:

// Define your Question class here:
public class Question {
    String imageId;
    int correctAnswer;
    int playerAnswer;
    String questionText;
    String answer0;
    String answer1;
    String answer2;
    String answer3;

    
  Question(int imageIdentifier, String questionString, String answerZero, String answerOne, String answerTwo, String answerThree, int correctAnswerIndex)  
  { 
    imageId = imageIdentifier;
    questionText = questionString;
    answer0 = answerZero;
    answer1 = answerOne;
    answer2 = answerTwo; 
    answer3 = answerThree;
    correctAnswer = correctAnswerIndex;
    playerAnswer = -1;
   }
}

The error specifically points out to imageId = imageIdentifier;
I double checked with typos and so on but it still doesn’t fire correctly. Any insights much appreciated.

You’ve declared the variable imageId as a string. However, the argument imageIdentifier is an int. You’re trying to assign imageIdentifier to imageId, but this will throw an error since they are different data types.

1 Like

Thank you for this solution! I just declared it back as int. It now fires correctly.

1 Like