The last one!

I am trying to write a game program that will allow players to battle each other but i am having trouble implimenting the 2 player objects that i have to create.
Here is my code so far.
public class Player {
private String name;
private String description;
private int honor;
private double strength;
private double totalstrength;
/** Constructs a default player.*/
public Player() {
name = null;
description = null;
honor = 0;
strength = 0;
/** Constructs Player object with specific name, description, and
* honor.
* @param n the player's name
* @param d the player's description
* @param q the player's honor*/
public Player(String n, String d, int q) {
this.name = n;
this.honor = q;
this.strength = this.calculateStrength();
this.description = this.calculateDescription();
/** Set the name of the item.
* @param n the player's name*/
public void setName(String n) {
this.name = n;
/** Returns the name of the item.
* @return the player's name*/
public String getName() {
return this.name;
/** Set the description of the item.
* @param d the player's description*/
public void setDescription(String d) {
this.description = d;
/** Returns the description of the item.
* @return the player's description*/
public String getDescription() {
return this.description;
/** Set the description of the item.
* @param q the player's honor*/
public void setHonor(int q) {
this.honor = q;
this.strength = this.calculateStrength();
this.description = this.calculateDescription();
/** Returns the description of the item.
* @return the player's honor*/
public int getHonor() {
return this.honor;
/** Returns the strength of the player.
* @return the player's stength*/
public double getStrength() {
return this.strength;
/** Calculates the strength of the player.
* @return the player's stength*/
public double calculateStrength() {
return honor/3. + Math.sqrt(honor);
/** Determines rank of player.
* @return the player's rank*/
public String calculateDescription()
int rank = honor + (int)strength;
if (rank < 500)
return "Peasant";
else if (rank < 1000)
return "Knight";
else
return "Royalty";
/** Produce rendering of object with name, description, quantity. Also,
* calls Objects toString() method.
* @return the Player object as a String*/
//'super' refers to parent or super class
public String toString() {
return super.toString() + " " + name + " " + description + " " + honor + " " + strength;
public Player battle(Player p){
double totalstrength = (p.calculateStrength() + this.calculateStrength());
Random generator = new Random();
generator.nextDouble();
double c = generator.nextDouble();
double fight = (this.calculateStrength()/totalstrength);
if(fight < c)
return this;
else
return p;
Here is my test class so far
public class PlayerTest {
     public static void main(String[] args) throws IOException {
          if(args.length != 0) {
               if(args.length != 3) {
                    System.err.println("Wrong number of arguments!");
                    System.exit(1);
               Player player1 = new Player(args[0], args[1], Integer.parseInt(args[3]));
               System.out.println(player1.toString());
               System.exit(0);
          Player player1 = new Player();
          BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
          String input = "go";
          System.out.println("Welcome to my game!");
          while(!(input.equals("x"))) {
               System.out.println("Enter n for name, h for honor, x to exit:");
               input = console.readLine();
               if(input.equals("n")) {
                    System.out.println("Enter the name of the player:");
                    input = console.readLine();
                    player1.setName(input);
                    System.out.println("The Player is ...");
                    System.out.println("Name: " + player1.getName());
                    System.out.println("Description: " + player1.getDescription());
                    System.out.println("Name: " + player1.getHonor());
                    System.out.println("Name: " + player1.getStrength());
               else if(input.equals("h")) {
                    System.out.println("Enter the honor of the player:");
                    input = console.readLine();
                    player1.setHonor(Integer.parseInt(input));
                    System.out.println("The Player is ...");
                    System.out.println("Name: " + player1.getName());
                    System.out.println("Description: " + player1.getDescription());
                    System.out.println("Honor: " + player1.getHonor());
                    System.out.println("Strength: " + player1.getStrength());
               else if(input.equals("x")) {
                    System.out.println("Good-bye!");
               else {
                    System.out.println("Error: Try Again");

This is a new PlayerTest.java:
import java.io.*;
public class PlayerTest
    private BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args)
    throws IOException
        (new PlayerTest()).exec();
    void exec()
        while (true)
            try
                System.out.println();
                System.out.print("New game (n) or quit (q)? ");
                String input = console.readLine();
                if (input.equalsIgnoreCase("n"))
                    playTheGame();
                else if (input.equalsIgnoreCase("q"))
                    break;
                else
                    System.out.println("Bad input");
                    continue;
            catch (IOException e)
                break;
        System.out.println("Goodbye!");
    void playTheGame()
    throws IOException
        Player player1 = getPlayer("First player");
        displayPlayer(player1);
        Player player2 = getPlayer("Second player");
        displayPlayer(player2);
        Player winner = player1.battle(player2);
        System.out.println();
        System.out.println("*** And the winner is ****");
        displayPlayer(winner);
    Player getPlayer(String title)
    throws IOException
        System.out.println();
        System.out.println(title);
        System.out.print("Name: ");
        String name = console.readLine();
        int honor;
        while (true)
            System.out.print("Honor: ");
            String honorStr = console.readLine();
            try
                honor = Integer.parseInt(honorStr);
                break;
            catch (NumberFormatException e)
                System.out.println("Bad input.");
                continue;
        return new Player(name, honor);
    void displayPlayer(Player player)
        System.out.println();
        System.out.println("Name: " + player.getName());
        System.out.println("Description: " + player.getDescription());
        System.out.println("Honor: " + player.getHonor());
        System.out.println("strength: " + player.getStrength());
}And there is a little modification I made in Player.java:
import java.util.*;
public class Player
    /** Constructs Player object with specific name, description, and
    * honor.
    * @param n the player's name
    * @param q the player's honor*/
    public Player(String n, int q)
        this.name = n;
        this.honor = q;
        this.strength = this.calculateStrength();
        this.description = this.calculateDescription();

Similar Messages

  • Recently, U2 music appeared on my ipod without my requesting it or wanting it. I was able to delete all of the songs except for one. How do I delete the last one from my ipod? The song does not show up in iTunes when I plug my ipod into the computer.

    Recently, U2 music appeared on my ipod without my requesting it or wanting it. I was able to delete all of the songs except for one. How do I delete the last one from my ipod? The song does not show up in iTunes when I plug my ipod into the computer. The version installed on my ipod is 7.1.2(11D257).

    Hi donfrommars,
    Welcome to the Apple Support Communities!
    Please use the following article for information and instruction on deleting the U2 album from your devices and account.
    Remove iTunes gift album "Songs of Innocence" from your iTunes music library and purchases
    Have a great day,
    Joe

  • Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still us

    Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still use Flash Player...
    Is there anyo who can help me with this? I asked in the shop and I was told "yes of course" , but when I contacted Sony directly I was advised to check with Adobe as apparently in the recent months Adobe and Sony haven't been getting along anymore...

    You may be mixing up two entirely different Adobe products.
    1. Adobe Flash Player. Needed to view web pages designed with Flash. Not needed to view PDF files. Not available for Android (not just Sony).
    2. Adobe Reader. Reads PDF files. However, the Android can also read most PDF files without needing Adobe Reader.

  • Hello applecare  can you help with the macbook pro i did the update the last one and safari doesn't open anything .. what should i do ?

    hello applecare  can you help with the macbook pro i did the update the last one and safari doesn't open anything .. what should i do ?

    Hello John...
    You may have a Safari third party add on installed that was compatible with the previous version of Safari but not 5.1. Try troubleshooting > Safari: Unsupported third-party add-ons may cause Safari to unexpectedly quit or have performance issues
    FYI... this is a user to user forum. If you can't resolve the issue, information for contacting AppleCare  here.

  • How do I do to use the same appleid on all my devices, I want to use the last one I have on my Ipad mini, do I deleta the one I have on my Iphone and reeinstall it with the Id I use on my Ipad..?

    how do I do to use the same appleid on all my devices, I want to use the last one I have on my Ipad mini, do I deleta the one I have on my Iphone and reeinstall it with the Id I use on my Ipad..?

    Hi john,
    Yes, you would sign out of iTunes & App Store: Settings>iTunes & App Store, click on the Apple ID, click on Sign Out. Then sign back on with the new Apple ID. Also, if you have an iCloud account with the other Apple ID, you would delete that iCloud account, and then sign on with your new ID: Settings>iCloud>Delete Account.
    Cheers,
    GB

  • I am using iPhone 4 from the last one year and went dead and got it replaced by paying Rs.12500/- to Nyasa Sion Koliwada Mumbai Service Provider but now again after 38days the problem has started, what do i do? Is this is the quality & service we boost?

    I am using iPhone 4 from the last one year and went dead and got it replaced by paying Rs.12500/- to Nyasa Sion Koliwada Mumbai Service Provider but now again after 38days the problem has started, what do i do? Is this is the quality & service we boost? On visiting the store we get only one reply you may write to Apple directely. we have the similar kind of problem with iPad which is being used by my wife Mr.Neelam Vij and paid Rs.16000/- to get it replaced within a year & 6months use. so in totality we have paid Rs.28500/- + Rs. 3000/- diagnostic charges.
    1. iPhone 4 , 32 GB Black with Sr. No. 88******A4T
    2. iPad 2, 16GB White with Sr. No.DL*******KPH
    Moreover, we have no information to contact whom. even the replace set has a warranty of only three month which further confirm that Apple itself is not confident wheather product will last after replacement for more then three month. Such kind of happening do not encourage anyone to recomend this product to anyone. Would appriciate a faster response to our problem if someone from Apple is going to read this email.
    Thanks & Regards
    A K Vij
    <Personal Information Edited by Host>

    http://support.apple.com/kb/he57?viewlocale=de_de
    India
    (91) 1800 4250 744
    www.apple.com/in/support/
    hope it helps

  • My ipod touch 8gb will not sync ,computer is recognising camera wizard when i plug in but not for itunes,i have tried to de install then re install but to no avail this is a replacement ipod but the last one i had was ok syncing with the same computer

    my ipod touch will not sync to itunes when i plug it in to my pc it is recognising the camera wizard but not showing up in itunes i have tried de installing and re installing but to no avail it is a replacement ipod but the last one was ok with syncing on the same usb connections can anyone help me out please

    Try to disable the camera notification: http://support.apple.com/kb/TS1500
    and make sure that Apple Mobile Device Service is active on your computer: http://support.apple.com/kb/TS1567

  • Time Machine appears to be doing back-ups, but they do not appear on the external hard drive. The last one I can find is June 30.  I did a utility scan of the hard drive disk and it is fine.

    Time Machine appears to be doing back-ups, but they do not appear on the external hard drive. The last one I can find is June 30.  I did a utility scan of the hard drive disk and it is fine. What do I do?

    Click the Time Machine icon in the menu bar. The time of the last backup is shown in the drop down.

  • I got a new apple iD so when i try to update my apps it wont change the last one that i had so i cant update my apps. How do i fix this?

    I got a new apple iD so when i try to update my apps it wont change the last one that i had so i cant update my apps. How do i fix this?

    - Go to Settings>Store and sign out and sign into your account.
    - Apps are locked to the account that purchased them.
    - To update apps you have to sign into the account that purchased the apps. If you have apps that need updating purchased from more than one account you have to update them one at a time until the remaining apps were purchased from one account.

  • TS2988 I had to reset my phone and I only have one of my ringtones I had 4.. Why'd it delete 3 and not the last one and now I can't get em back without paying for them again!!! What the **** is up with that??

    I had to reset my phone and I only have one of my ringtones I had 4.. Why'd it delete 3 and not the last one and now I can't get em back without paying for them again!!! What the **** is up with that??

    Yup, your question and Diane's answer helped me also. Tho' I had had problems before getting into the iTunes store I always managed to find a way. Today they had me blocked cold with the "Update to 10" advert no matter what I did. Other questioners are being told, incorrectly as it turns out, that they have to update their OS to accomodate iTunes 10 and upgrade to iTunes 10. I did the download which did not take up much more room on my crowded old hard drive and now I'm back in business.

  • I can watch all of my old TV shows on iTunes, but the last one I downloaded jammed up after about one minute.  I tried quitting I-tunes and re-starting my computer to no avail.  iTunes won't even let me delete it so I can try downloading it again.

    I can watch all of my old TV shows on iTunes, but the last one I downloaded jammed up after about one minute.  I tried quitting I-tunes and re-starting my computer to no avail.  iTunes won't even let me delete it so I can try downloading it again. But it will let me delete other episodes.

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes for Mac forum.
    Regards.

  • I have been trying to reinstall iTunes but have been getting error messages. One says I need file MSVCR80, one says I have error 7 and the last one says I have windows error 126.

    I have been trying to reinstall iTunes but I have been getting error messages. One says I need a fileMSVCR80.dll, one says error 7 and the last one says windows error126.
    This problem started yesterday when I tried to download the newest iTune update.
    The error message suggested trying the download again and i have tried over ten times and i get the same messages and error numbers.

    iTunes 11.1.4 for Windows- Unable to install or open - MSVCR80 issue
    Solving MSVCR80 issue and Windows iTunes install issues.
    Thanks to user turingtest2 for this solution.
    Solving MSVCR80 issue and Windows iTunes install issues.
    If the above doesn’t do the trick entirely, then use the instructions in the following as it applies to the version of Windows you are using:
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    You may be required to boot into safe mode to complete the folder deletion process.

  • Overwrite mapping in design repository with the last one deployed

    Hi
    We have a Single Design Environment with 2 runtime environnment (Dev, Prod). When I log in the Dev Control Center, I see there is a mapping "changed". It has been changed by an employee who don't work here anymore and I have no clue what have been changed.
    There is no specific request or obvious reason for that change, and since it's a huge and conplex mapping, I would like to overwrite (or "rollback") the mapping in the design environnment with the last one deployed in Production.
    But I don't know how or if it's possible..! At least if I could compare the 2 version, I could tell if the change is good or not.
    To me, it's a showstopper for incoming modifications..
    There is no Snapshot and i'm using OWB 10gr2 since 1 month now, so all of these is new to me.
    I really need help on this one...!
    Thanks!

    one onerous way to do this is
    take the mdl exports of the mapping from both envs. Try opening them in an xml/html text editor(notepad++ for eg)
    If they look like they are encrypted, try renaming the .mdl file to .zip( I can do this in 11g and what this gives me is a .xml file and a .mdx file which can be viewed in an xml editor)
    You can then possibly do a text comparison to find if anything is obviously different.
    Another good option is something our friend Oleg developed.
    http://owbeg.blogspot.co.uk/2012/05/release-005-of-mapreconstruct-script.html
    This script extracts the mapping as an OMB script. You can then compare both mapping tcl outputs.

  • Moving a group of photos-leaves the last one

    Not always, but most of time, if I select a group of photos in a folder, then drag and drop them into another folder, it will move all but the last one.
    Window pops up saying "There was an error copying files to the destination you selected. The following files could not be copies:"
    It will list the last one in the string of files selected.
    So then I just  move it anyway by itself and it works fine.
    1-It doesn't do it every time.
    2-Whether I use Drag and Drop or right click the folder and select "Move Selected Photos to this folder" makes no difference.
    LR 5.6 Latest updates
    Using Nikon NEF files.
    Custom built fast computer with 32 gigs of ram
    Win 7 Pro
    This have been happening since version 4.
    What's going on?
    T.G.

    This bug has been around since at least LR 2 and was acknowledged by Adobe several years ago.   Please add your vote and your possible workaround to this thread in the official feedback forum:
    Lightroom: Multiple image move operation bug
    That thread reports that the problem was narrowed down to Windows, but I don't believe anyone had previously tied it to the Windows Search service.

  • How do I set up iTunes to automatically move on to play the next album after the last one has finished? (in Album view)

    How do I set up iTunes to automatically move on to / play the next album after the last one has finished? (in Album view).
    This used to happen automatically in Genre view.

    Hi Henryhippo,
    If you have questions about play order in iTunes, you may find the following article helpful; I believe you can use the Play Next or Add to Up Next to add albums as well as songs.
    iTunes 11 for Windows: Ways to play songs
    Regards,
    - Brenden

  • How can I set the hstry to keep 3 windows? Sometimes windows pop up behind the browsr, causing them to be the last ones I close- it forgets the main one!

    Sometimes windows pop up behind the browser and I don't know about them, causing them to be the last ones I close. So Mozilla remembers them and it forgets the main window with all the tabs that I thought was being saved! The history button only remembers 3 and that's not enough in these cases.

    If you wish to retain all the tabs for next time do not close down the Windows individually. Just minimise them if you need them out of the way.
    When you close Firefox use use the Firefox menu to quit the Firefox program.
    * Use New Button {three bar icon) -> Quit Firefox {off icon)
    * also see [[Restore previous session - Configure when Firefox shows your most recent tabs and windows]]
    ** [[How do I restore my tabs from last time?]]
    You may wish to set Firefox to always start with last session.
    (That does not stop you clicking the home icon to open your home page, or set of pages, at any-time you wish)

Maybe you are looking for

  • How can I get an album by an artist to join the rest of the same artist

    I occasionally have the problem where I have several albums by an artist under the one name IE Bruce Springsteen 15 albums all under Bruce Springsteen But for some reason 1 album comes up as seperate Bruce Springsteen album ? I have tried checking Ge

  • Inspire 5700 Dig. Subwoofer Issue

    Aparently, my subwoofer wont work if I dont unplug it from the decoder and plug it back again and some times that doesnt work so I have to try again till it get on. I know when it works because the times it doesnt I can hear the subwoofer making a li

  • J2ME Extension for Linux

    Sun has the J2ME Wireless Toolkit for Linux, and Nokia has recently released a Linux version of their Developer's Suite for J2ME. So why don't you have a Linux version of the J2ME Extension for JDeveloper? I don't want to have to run Windows just to

  • ITUNES 10 WILL NOT LOAD

    had i tunes it was working fine no problem got the upgrade to 10 lost i tunes can't get i tunes back on computer have tried to do repair 6 times nothing have completely uninstalled and re installed 6 times still nothing click on shortcut and i get no

  • Fail to install swedish advanced linguistics on FAST ESP 5.3 SP4

    Hi, I'm using the als-installer to install a swedish advanced linquistics pack on a FAST ESP 5.3 SP4 single-node server. FAST itself is up and running in all aspects, but when I run the following command from an administrative console window after se