У меня это как задание, чтобы раскрасить картинку, вроде голландского флага.Но у меня много трудностей, когда я не могу понять, как разделить высоту на секции.Когда я сделал это, как показано ниже, я получил много ошибок, которые в основном говорят, что «не может разрешить переменную».Вот мой код:
/* Assignment 3, Part 2 - Go Dutch! */
public class Assignment3Part2
{
//
public static void main(String [] args) throws InterruptedException
{
String filename;
if (args.length > 0) {
// got a filename passed into program as a parameter
// don't change this part of the code needed by TA for grading
filename = args[0];
System.out.println("Filename passed in: " + filename);
} else {
// ask user for a picture
filename = FileChooser.pickAFile();
System.out.println("User picked file: " + filename);
}
Picture pic = new Picture(filename); // Picture to modify
//
pic.show(); // Show the original picture
Thread.sleep(1000); // Pause for 1 second. You can pause for less if you like
Pixel[] pixelArray = pic.getPixels();
// TODO:
for(int x = 0; x < pic.getWidth(); x++);
{
for (int y = 0; y < pic.getHeight(); y++);
{
int h = pic.getHeight();
if ( y <=(h/3))
{
value = pic.getOrange();
value = (int)(value*1.5);
pic.setOrange(value);
}
if ( y > (h/3)&& y < (2*h/3))
{
value = pic.getWhite();
value = (int)(value*1.5);
pic.setWhite(value);
}
else {
value = pic.getGreen();
value = (int)(value*1.5);
pic.setGreen(value);
}
}
}
}
pic.repaint();
} // End of main
} // End of Class
А вот ошибки, которые система выдает:
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 34]
Error: y cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 37]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 37]
Error: The method getOrange() is undefined for the type Picture
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 38]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 38]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 39]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 41]
Error: y cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 41]
Error: y cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 44]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 44]
Error: The method getWhite() is undefined for the type Picture
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 45]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 45]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 46]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 50]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 50]
Error: The method getGreen() is undefined for the type Picture
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 51]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 51]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 52]
Error: value cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 60]
Error: Syntax error on token "repaint", Identifier expected after this token
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\Assignment3Part2.java [line: 62]
Error: Syntax error on token "}", delete this token
Может кто-нибудь объяснить, а также помочь мне решить эту проблему?спасибо