Home > Back-end >  New instruction, Java compile-time appeared some problems, don't know what to do.
New instruction, Java compile-time appeared some problems, don't know what to do.

Time:10-26

In the joint compilation of time appear a few problems, where the hell could not clear problem, help you guies
Land. Java: 3: error: can't find the symbols
Village. SetWaterAmount (200);
^
Symbol: variable Village
Location: class Land
Land. Java: 4: error: can't find the symbols
Int leftWater=Village. WaterAmount;
^
Symbol: variable Village
Location: class Land
Land. Java: 6: error: can't find the symbols
Village zhaoZhuang, maJiaHeZhi;
^
Symbol: class Village
Location: class Land
Land. Java: 7: error: can't find the symbols
ZhaoZhuang=new Village (" Zhao Zhuang ");
^
Symbol: class Village
Location: class Land
Land. Java: 8: error: can't find the symbols
MaJiaHeZhi=new Village (" Ma Jiahe son ");
^
Symbol: class Village
Location: class Land
Land. Java: 18: error: can't find the symbols
System. The out. Println (name + "found" Wells were + leftwater + "premium");
^
Symbol: variable leftwater
Location: class Land
6 error


Specific code is as follows:

Land. Java
Public class Land {
Public static void main (String args []) {
Village. SetWaterAmount (200);
Int leftWater=Village. WaterAmount;
System. The out. Println (" well "+ leftWater +" premium ");
Village zhaoZhuang, maJiaHeZhi;
ZhaoZhuang=new Village (" Zhao Zhuang ");
MaJiaHeZhi=new Village (" Ma Jiahe son ");
ZhaoZhuang. SetPeopleNumber (80);
MaJiaHeZhi. SetPeopleNumber (120);
ZhaoZhuang. DrinkWater (50);
LeftWater=maJiaHeZhi. LookWaterAmount ();
String name=maJiaHeZhi. Name;
System. The out. Println (name + "Wells found" + leftWater + "premium");
MaJiaHeZhi. DrinkWater (100);
LeftWater=zhaoZhuang. LookWaterAmount ();
Name=zhaoZhuang. Name;
System. The out. Println (name + "found" Wells were + leftwater + "premium");
Int peopleNumber=zhaoZhuang. GetPeopleNumber ();
System. The out. Println (" Zhao Zhuang population "+ peopleNumber);
PeopleNumber=maJiaHeZhi. GetPeopleNumber;
System. The out. Println (" Ma Jiahe child population "+ peopleNumber);
}
}

Village. Java

Public class Village {
Static int waterAmount;
Int peopleNumber;
String name;
Village (String s) {
Name=s;
}
The static void setWaterAmount (int m) {
If (m> 0)
WaterAmount=m;
}
Void drinkWater (int n) {
If (waterAmount - n>=0) {
WaterAmount=waterAmount - n.
System. The out. Println (name + "drank" + n + "premium");
}
The else
WaterAmount=0;
}
Static int lookWaterAmount () {
Return waterAmount;
}
Void setPeopleNumber (int n) {
PeopleNumber=n;
}
Int getPeopleNumber () {
Return peopleNumber;
}
}

CodePudding user response:

Ah... Code writing carefully, I get the code can be, there is no logical problems, see your that error message might be:
Variable error Village: possible reason is that you have no guide package, the compiler will prompt you to directly click can guide package, or you write these two classes in a fast
Variable leftwater error: you wrote leftwater above is capital (w), the compiler should prompt you to that piece of error, the compiler can view the message you find the problem

CodePudding user response:

CMD window, should be to compile and run Java file, and compile can't reverse the order of,

CodePudding user response:

Village. SetWaterAmount (200); In the village and the village below, is not the same class
  • Related