//Chu Po Ling: Fighter.java (20071018)import java.util.Random; //program uses class Ramdompublic class Fighter//class name{Random number = new Random();//create a Random resultprivate int PlayerPower = 100;//player power for the fighterprivate String PlayerName = "Yuki";//player name for the fighterpublic Fighter (String PlayerName)//constructor initializes fightername{this.PlayerName = PlayerName;}//initializes fighternamepublic Fighter() {} public Fighter( String PlayerName , int PlayerPower ) {this.PlayerName = PlayerName; this.PlayerPower = PlayerPower; }//end constructor public void setPlayerName( String PlayerName )//method to set the player name {this.PlayerName = PlayerName;}//end method set player name public String getPlayerName()//method to retrieve the course name {return PlayerName;}//end method getPlayerName public void setPlayerPower( int PlayerPower)//method to set player power {this.PlayerPower = PlayerPower;}//end method set player power public int getPlayerPower()//method to retrieve the player power {return PlayerPower;}//end method get player power public int attack ( Fighter Ling ){int RoundNumber = 1;//initialize roundnumberSystem.out.println();//output a newlineSystem.out.printf("*~~~~~~ Round %d ~~~~~~*\n", RoundNumber);//display the round numberSystem.out.println(getPlayerName() + "'s Power = " + getPlayerPower());//display Yuki powerSystem.out.println(Ling.getPlayerName() + "'s Power = " + Ling.getPlayerPower());//display Ling powerSystem.out.println("==> " + getPlayerName() + " Attacks " + Ling.getPlayerName() + "!" );//display Yuki Attacks Ling!int df = Math.abs(getPlayerPower() - Ling.getPlayerPower());//calculate the different//do repetition statement.do{ int pby = 0 + number.nextInt(2); if(df == 0)//if the different 0 {df += 1;}//add 1 to the different else //else resultis not 0, so calculate the different {df = Math.abs(getPlayerPower() - Ling.getPlayerPower());} if(pby > 0.5) {System.out.println("Yuki wins at this round!");//display results PlayerPower += df;//add the different to Yuki power Ling.PlayerPower -= df;}//subtract the different to Ling power else {System.out.println("Yuki loses at this round!");//display results PlayerPower -= df;//subtract the different to Yuki power Ling.PlayerPower += df;}//add the different to Ling power if(PlayerPower<0.5)//if Yuki power less than0.5 break;//necessary to exit switch if(Ling.PlayerPower<0.5)//if Ling power less than0.5 break;//necessary to exit switchRoundNumber += 1;//add 1 to the roundnumberSystem.out.println();//output a newlineSystem.out.printf("*~~~~~~ Round %d ~~~~~~*\n", RoundNumber);//display the new round numberSystem.out.println(getPlayerName() + "'s Power = " + getPlayerPower());//display Yuki powerSystem.out.println(Ling.getPlayerName() + "'s Power = " + Ling.getPlayerPower());//display Ling powerSystem.out.println("==> " + getPlayerName() + " Attacks " + Ling.getPlayerName() + "!" );//display Yuki Attacks Ling! }//end do while(PlayerPower>= 0);//stop at player power less than or equal to 0 return PlayerPower;} public int killed(Fighter Ling){ if(PlayerPower<= 0)//if Yuki power less than or equal to 0 {System.out.println(getPlayerName() + " is killed!");}//display Yuki is killed! if(Ling.PlayerPower<= 0)//if Ling power less than or equal to 0 {System.out.println(Ling.getPlayerName() + " is killed!");}//display Ling is killed! return PlayerPower;}public int GameOver(Fighter Ling){System.out.println();//output a newlineSystem.out.println("*~~~~~~ Game Over ~~~~~~*");//display Game OverSystem.out.println(getPlayerName() + "'s Power = " + getPlayerPower());//display resultsSystem.out.println(Ling.getPlayerName() + "'s Power = " + Ling.getPlayerPower());//display results return PlayerPower;}public static void main( String args[])//main method begins execution of Java application{System.out.println();//output a newlineSystem.out.println("Name: Chu Po Ling, ID: 8059722");//display headersSystem.out.println();//output a newlineSystem.out.println("Java Of The Simple Fighter! 20071018");//display title Fighter player1 = new Fighter(); Fighter player2 = new Fighter("Ling",100); player1.attack(player2); player1.killed(player2); player1.GameOver(player2);}//end main method}//end class Fighter