急!!!!大家帮帮忙 把这个c++翻译成java
#include<iostream>#include<string>
#include<math>
//Get a random number,indicating the chance and ranging from 1 to 100
int chance(){
return 1+rand()%100;
}
//Team's Class
class team{
private:
string name;
string location;
int player;
int score;
public:
void get_Name();
void get_Location();
bool pass();
bool shoot();
void print_Team_Status();
};
//methods of classes
//Get team's name
void team::get_Name(){
cin>>name;
}
//Get team's location
void team::get_Location(){
cin>>location;
}
//Pass the ball
//Return with a boolean indicating whethe the pass is successful
bool team::pass(){
bool success=(chance()<=50);
if(success)
if(player<3) player++;//if a striker(when player is 3) makes a successful pass, the value of player won't change
else
player=0;
return success;
}
//Shoot
//Return with a boolean indicating whethe the shoot is successful
bool team::shoot(){
bool success;
swich(player){
case:1
success=(chance()<=10);
break;
case:2
success=(chance()<=10);
break;
case:3
success=(chance()<=10);
}
if(success) score++;
player=0;
return success;
}
//Print the status of the team
//The status includes location,name,score and which player is holding the ball if the team has the ball
void team::print_Team_Status(){
cout<<location<<' '<<name<<" has "<<score<<" goals.";
switch(player)
{
case 1:
cout<<" Their Defender has the ball."
break;
case 2:
cout<<" Their Midfielder has the ball."
break;
case 3:
cout<<" Their Striker has the ball."
}
cout<<endl;
}