Please! Need some help here!

public class NobleHouse
    private String names;
    private int maxno;
    private Knight[] knight;
    public NobleHouse(String names,int maxno)
        this.names=names;
        this.maxno=maxno;
        knight=new Knight[maxno];
    public String getHouseName()
        return names;
    public int getCurrentKnights()
        return maxno;
    public Knight getBestKnight()
        Knight max=knight[0];
        for(int i=1;i<getCurrentKnights();i++)
            if(knight.getSkill()>max.getSkill())
max=knight[i];
return null;
public Knight getKnightByName(String names)
for(int i=0;i<getCurrentKnights();i++)
if (knight[i].equals(names))
return knight[i];
return null;
public Knight getNextKnight()
int next=0;
next++;
if(getCurrentKnights() == next)
next=0;
return knight[next];
public void addKnight(Knight next)
int i;
for(i=0;i<getCurrentKnights();i++)
if(next!=null && i<getCurrentKnights())
next=new Knight(next.getName(),next.getJousts(),next.getVictories());
knight[i]=next;
next.setHouseName(names);
public void printKnights()
          if(knight[0]==null)
               System.out.println("Emty House");
else
for(int i=0;i<getCurrentKnights();i++)
System.out.println(knight[i].getName());
import java.util.*;
import java.text.*;
public class Knight
    private String name,type;
    private int joust,victories;
    public Knight(String name,int joust,int victories)
        type="Freelance";
        this.name=name;
        this.joust=joust;
        this.victories = victories;
    public String getHouseName()
        return type;
    public void setHouseName(String housename)
        type=housename;
    public String getName()
        return name;
    public int getJousts()
        return joust;
    public int getVictories()
        return victories;
    public String getRank()
        String a="Squire";
        String b="Knight";
        String c="Kings Chapion";
        if(joust<20 && joust>0)
            return a;
        else
            if(joust>20 && joust<40)
                return b;
        return c;
    public double getBaseSkill()
        double ratio;
        double totalvictory=getVictories()*getVictories();
        double totaljoust=getJousts()*getJousts();
        double total=totalvictory/totaljoust;
        ratio=Math.sqrt(total);
        return ratio;
    public int getSkill()
        int number=0;
        if(getRank()=="Squire")
          number=(int) (100*getBaseSkill()*1);
        else
            if(getRank()=="Knight")
               number=(int) (100*getBaseSkill()*1.5);
           else
                if(getRank()=="Kings Chapion")
                   number=(int) (100*getBaseSkill()*2);
        return number;
    public void incrementJousts(boolean won)
        joust++;
        if(won==true)
            victories++;
    public boolean joust(boolean won)
        Random no = new Random();
        won=false;
        int knit1=no.nextInt(250)+getSkill();
        int knit2=no.nextInt(250)+getSkill();
        if(knit1>knit2)
            won=true;
        incrementJousts(won);
        return won;
    public void print()
        DecimalFormat ft=new DecimalFormat("0.#");
        System.out.println("Knights name: "+getName());
        System.out.println("Knights rank: "+getRank());
        System.out.println("House name: "+getHouseName());
        System.out.println("Knights skill: "+ft.format(getSkill()));
public class HouseTest
     public static void main(String [] args)
        //Create teh NobleHouse object to test...
          NobleHouse nh = new NobleHouse("Round Table", 3);
          //Now test the methods...
          System.out.println("TEST : printKnight() on empty set...");
        System.out.println("TEST : (Should say that the house is empty)");
          nh.printKnights();
          System.out.println();
        System.out.println("TEST : addKnight() then calling printKnights()...");
        System.out.println("TEST : (Should print Gwain)");
          nh.addKnight(new Knight("Gwain", 10, 10));
          nh.printKnights();
          System.out.println();
        System.out.println("TEST : getKnightByName() on Gwain...");
        System.out.println("TEST : (Should print Gwains details again)");
        Knight k = nh.getKnightByName("Gwain");
        k.print();
        System.out.println();
          System.out.println("TEST : Adding another Knight...");
          nh.addKnight(new Knight("Lancalot", 40, 40));
        nh.printKnights();
        System.out.println();
        System.out.println("TEST :  getNextKnight()...");
        System.out.println("TEST : (Should print \"gwain, lanc, gwain, lanc\")");
        k = nh.getNextKnight();
        k.print();
        k = nh.getNextKnight();
        k.print();
        k = nh.getNextKnight();
        k.print();
        k = nh.getNextKnight();
        k.print();
        System.out.println();
        System.out.println();
        System.out.println("TEST : Adding one more Knight...");
        nh.addKnight(new Knight("Friday", 25, 20));
        nh.printKnights();
        System.out.println();
        System.out.println("TEST : getBestKnight() (should be Lancelot)...");
          k = nh.getBestKnight();
        k.print();
}I have no error when compiled but when i run the program don't give me the correct result ! (Exception in thread "main" java.lang.NullPointerException)
I think something is wrong at the addKnight() method of the NobleHouse class!
Any idear how to fix it and what is wrong in there????! sothe program will give me the correct result! Thank

see if this works
import java.util.*;
import java.text.*;
class NobleHouse
    int next = 0;
    private String names;
    private int maxno;
    private Knight[] knight;
    int currentKnights = 0;
    public NobleHouse(String names,int maxno)
        this.names=names;
        this.maxno=maxno;
        knight=new Knight[maxno];
    public String getHouseName(){return names;}
    public int getCurrentKnights(){return currentKnights;}
    public Knight getBestKnight()
        Knight max=knight[0];
        for(int i=1;i<getCurrentKnights();i++)
            if(knight.getSkill()>max.getSkill())
max=knight[i];
return max;
public Knight getKnightByName(String names)
for(int i=0;i<getCurrentKnights();i++)
if (knight[i].getName().equals(names))
return knight[i];
return null;
public Knight getNextKnight()
next++;
if(getCurrentKnights() == next)
next=0;
return knight[next];
public void addKnight(Knight next)
int i;
for(i=0;i<maxno;i++)
if(knight[i] == null)
knight[i]=new Knight(next.getName(),next.getJousts(),next.getVictories());
knight[i].setHouseName(names);
currentKnights++;
break;
public void printKnights()
if(knight[0]==null) System.out.println("Emty House");
else for(int i=0;i<getCurrentKnights();i++) System.out.println(knight[i].getName());
class Knight
private String name,type;
private int joust,victories;
public Knight(String name,int joust,int victories)
type="Freelance";
this.name=name;
this.joust=joust;
this.victories = victories;
public String getHouseName(){return type;}
public void setHouseName(String housename){type=housename;}
public String getName(){return name;}
public int getJousts(){return joust;}
public int getVictories(){return victories;}
public String getRank()
String a="Squire";
String b="Knight";
String c="Kings Chapion";
if(joust<20 && joust>0) return a;
else if(joust>20 && joust<40) return b;
return c;
public double getBaseSkill()
double ratio;
double totalvictory=getVictories()*getVictories();
double totaljoust=getJousts()*getJousts();
double total=totalvictory/totaljoust;
ratio=Math.sqrt(total);
return ratio;
public int getSkill()
int number=0;
if(getRank()=="Squire")
number=(int) (100*getBaseSkill()*1);
else
if(getRank()=="Knight") number=(int) (100*getBaseSkill()*1.5);
else if(getRank()=="Kings Chapion") number=(int) (100*getBaseSkill()*2);
return number;
public void incrementJousts(boolean won)
joust++;
if(won==true) victories++;
public boolean joust(boolean won)
Random no = new Random();
won=false;
int knit1=no.nextInt(250)+getSkill();
int knit2=no.nextInt(250)+getSkill();
if(knit1>knit2) won=true;
incrementJousts(won);
return won;
public void print()
DecimalFormat ft=new DecimalFormat("0.#");
System.out.println("Knights name: "+getName());
System.out.println("Knights rank: "+getRank());
System.out.println("House name: "+getHouseName());
System.out.println("Knights skill: "+ft.format(getSkill()));
class HouseTest
public static void main(String [] args)
NobleHouse nh = new NobleHouse("Round Table", 3);
System.out.println("TEST : printKnight() on empty set...");
System.out.println("TEST : (Should say that the house is empty)");
nh.printKnights();
System.out.println();
System.out.println("TEST : addKnight() then calling printKnights()...");
System.out.println("TEST : (Should print Gwain)");
nh.addKnight(new Knight("Gwain", 10, 10));
nh.printKnights();
System.out.println();
System.out.println("TEST : getKnightByName() on Gwain...");
System.out.println("TEST : (Should print Gwains details again)");
Knight k = nh.getKnightByName("Gwain");
k.print();
System.out.println();
System.out.println("TEST : Adding another Knight...");
nh.addKnight(new Knight("Lancalot", 40, 40));
nh.printKnights();
System.out.println();
System.out.println("TEST : getNextKnight()...");
System.out.println("TEST : (Should print \"gwain, lanc, gwain, lanc\")");
k = nh.getNextKnight();
k.print();
k = nh.getNextKnight();
k.print();
k = nh.getNextKnight();
k.print();
k = nh.getNextKnight();
k.print();
System.out.println();
System.out.println();
System.out.println("TEST : Adding one more Knight...");
nh.addKnight(new Knight("Friday", 25, 20));
nh.printKnights();
System.out.println();
System.out.println("TEST : getBestKnight() (should be Lancelot)...");
k = nh.getBestKnight();
k.print();

Similar Messages

  • Hi, Someone Know why my charger is not working properly but always it was been working good but now when conect my iphone (3gs) shows a yellow triangle saying : Charging is not supported with this accessory. Please I need some help here. Thanks =D

    Hi Someone Know why my charger is not working properly but always it was been working good but now when conect my iphone (3gs) appears a golden triangle saying :Charging is not Supported with this accessory. Please I Need Some Help Here. Thanks =D

    sounds like the cable or the iphone connector are somehow damaged

  • Need some help here on the proper settings for quicktime exporting from imovie that won't degredate the footage from my handycam

    need some help here on the proper setting for quicktime exporting that won't denegrate my footage from handycam canon fs200

    What are the existing settings iMovie?
    Al

  • Cannot get slide show in full screen mode to come up on secondary monitor regardless of how I set up show it always opens on primary screen.  Need some help here.

    Slide show in PowerPosint for mac 2011 on iMac will not open full screen mode on secondary monitor.  Regardless of how I set the slide show preferences it always opens on primary monior with secondardy monitor having totally balck screen.  Need some help if anyone else has run into this problem.

    You should contact Microsoft for Mac Support  and/or post in their forums.

  • Need Some Help Here From The Pros....

    Hi all...Im new here you see. I have some questions here..
    1) May I ask if anyone could just tell me how to actually create a partition like Windows do in Mac OS? I need the partition to do my backups and save some of my important documents.
    2) Can we actually create a password to secure certain of my files so that anyone wants to browse it will have to enter the password? Is it possible to do that?
    3) Im also trying to use Visor(i cant remember the name, it's a software to enable Mac to run windows without the boot camp) but i tried on my friend's Macbook, I cant use the MSN camera function... Anybody have any idea??? Or it's not compatible with the camera built-in.
    4) I want to use "3D Studio Max", its it compatible with Mac OS??? and will it be laggish if i uses macbook 13" white?
    Please help....

    Hi!
    1) May I ask if anyone could just tell me how to actually create a partition like Windows do in Mac OS? I need the partition to do my backups and save some of my important documents.
    With your external drive attached, open Disk Utility, found in Applications/Utilities. Choose your drive on the left, and use the Partition tab to set up the number and type of partitions. Partitioning will delete all data on the drive.
    2) Can we actually create a password to secure certain of my files so that anyone wants to browse it will have to enter the password? Is it possible to do that?
    Don't forget that the Mac, just like Windows, is multi-user. You can set up a user for yourself and one for guests or specific people. Nobody can see anybody else's files. You can lock your computer when you go away from the desk if you want absolute privacy.
    Or, you can create an encrypted disk image (also using Disk Utility) to store private files if you really want to stick with one user account.
    3) Im also trying to use Visor(i cant remember the name, it's a software to enable Mac to run windows without the boot camp) but i tried on my friend's Macbook, I cant use the MSN camera function... Anybody have any idea??? Or it's not compatible with the camera built-in.
    Do you mean VMWare Fusion? I believe iSight support is included in the VMWare Tools - when you're running Fusion, there's a menu option to install/update those tools.
    4) I want to use "3D Studio Max", its it compatible with Mac OS??? and will it be laggish if i uses macbook 13" white?
    I believe it's Mac only, so you should check the Windows specs (RAM requirements, graphic card VRAM, etc) to see if you can run it within a virtual Windows on your Macbook.
    Matt

  • My new K7N2-Delta need some help here!

    Recently i bought a brand new k7n2 delta L and i need some advice on how to overclock with this new mobo, with the km2m it was piece of cake but this is a little bit more complete. I will appreciate the help and tips in this matter more over because my first attempt resulted on a non responsive system :P no post to be more clear.
    Thanks in advance.
    By the way my cpu is an athlon xp 2000+ tbred (i don't know if it is unlocked)

    read all this first
    https://forum-en.msi.com/index.php?threadid=40413&sid=
    https://forum-en.msi.com/index.php?threadid=32088&sid=
    https://forum-en.msi.com/index.php?threadid=38822&sid=

  • Need some help here re: E63 CONTACTS

    Please have some time to reply on my concerns listed below:
    1. Can I change the view of my contact list from phone contacts to sim contacts?
        - Supporting question is that, can i view my sim contacts permanently without going to Options then Sim Contacts?
    2. Can i delete multiple duplicate contacts in just a single time?
    Hoping to receive feedback from nokia service team the soonest.

    Just a heads up, my friend was asking me these things because he's planning to buy a Nokia Eseries unit (chossing between e63 and e71). Well thanks anyway.
    Really appreciate your prompt response. Hope to receive this kind of service the next time.

  • I need some help here please!

    i am working on a website thats going to be a friend loop
    such as facebook myspace classmate etc. im in the proccess of
    making the site now and i was wondering what i need to to to enable
    useres to be able to login and create a profile page on my site?
    how can i do this using DW2004 what am i looking at here? also
    anyone who would be interested in helping e-mail
    [email protected] we have the site up on a server but we are
    far from done

    > such as facebook
    > myspace classmate etc. im in the proccess of making the
    site now and i was
    > wondering what i need to to to enable useres to be able
    to login and create a
    > profile page on my site?
    hire a team of skilled programmers, put them in a cage and
    toss money at
    them.
    or spend a lot of time learning how to do it yourself.
    or try a free or commercial pre-written application
    http://www.hotscripts.com/search/?q=myspace&cat=All&page=1&sort=&license_typ
    e=free
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • I need some help here. someone please respond with some type of idea.

    okay, here's the deal
    when i take the Ipod out of the usb, i cut it on, and it's just a constant green light in the front that wont go away. it wont play, and wont have any affect on the buttons or anything. it's just a steady green light.
    it wont show my battery life until it's cut off.
    do you have any idea what's going on?
    i'm so uber angry it isn't funny.
    P.S.- I've had this ipod for like, almost a year.

    okay, here's the deal
    when i take the Ipod out of the usb, i cut it on, and
    it's just a constant green light in the front that
    wont go away. it wont play, and wont have any affect
    on the buttons or anything. it's just a steady green
    light.
    it wont show my battery life until it's cut off.
    do you have any idea what's going on?
    i'm so uber angry it isn't funny.
    P.S.- I've had this ipod for like, almost a year.
    See if this helps:
    http://docs.info.apple.com/article.html?artnum=303332

  • [VIA] Need some help here ... anyone please ?

    Hello,
             I'm new here, just wanna ask for some solution for my pc problem.
    I'm currently using Athlon XP 2.4, MSI KT400 (MS-6712AV) Mainboard, just bought for 3 months, but today when i start my pc, it comes out on the screen " Checking NVRAM ", than it stop, the system just hanged there, even that i kept restarting. Can anyone tell me what's the problem ? Does anything to do with my motherboard ? Thank you.

    emm, you reminded me Dr.Stu, i did remove my PS once yesterday to test on my other PC. this problem occured since i switched back. I did take out the cards and rams one by one, but same result.
    Now i unplugged one of the ide cable, i can successfully start my pc to windows, but in roughly few minutes, it'll auto restart. Same problem ?
    Thank you
    My Specs:
    AMD Athlon XP 2.4Ghz
    MSI KT4V MS-6712 MotherBoard
    MSI GeForce FX-5700 256mb Display Card
    768mb DDR Rams ( Apacer 256mb X2 , Kingston 256 X1 ) 
    ASUS 52X CD / 52X24X52 CD-R / Pioneer DVD-R A-109B/W 16X4X16 +-
    Creative SB Audigy 2 ZS Value SoundCard
    Eagle Aluminium ATX Casing with iCute 450Watt 2Fan PSU
    80Gb Western D HDD 8mb Buffer
    3 com 10/100 N/Card and Samsung 710v LCD Monitor

  • ITunes Match is driving me nuts! I need some help here please!

    iTunes Match hast been stuck in the Step 2 forever, 17286 out of 17287 Songs Checked, it will always get stuck there, and this is everything I've tried so far to solve the issue:
    1) Stopping the process, and turning it back on again.
    2) Updating iTunes Match in the Store Menu.
    3) Signing out of the iTunes Store and signing back in.
    4) Quiting iTunes and restaring the application.
    5) Restarting the Mac.
    6) Converting all the "Waiting" iCloud Status songs to ACC 256 VRB kbps Version, deleting the originals, keeping just the converted ones.
    But nothing seems to work, it will just stay there and do nothing.
    I've managed to Match 13193 songs and Upload another 2964 songs, but once it has stopped uploading and here I am.
    Guys, if something similar has happened to you, and you've figured it out by doing something I haven't tried yet, please let me know, it will be much appreciated.

    Try the dedicated iTunes Match forum: https://discussions.apple.com/community/itunes/itunes_match

  • I really need some help here....Please?

    Hey guys i have posted numerous threads regarding this issue but to no avail so im going to try one last time.
    Basically, Itunes works fine UNTIL i start to sync, Then it freezes up for a while then starts to sync a little bit...Then freezes and syncs a little bit..And so on..
    It took me 2 WHOLE days to sync 15 episodes of southpark.
    I transfered some movies and songs to my wifes laptop and it sync'd everything in around 50 seconds flat, So its now obvious that it must be my PC.
    I have USB 2 and i have 6 slots, I have tried ALL the different USB slots and it stays the same.
    Does anyone have ANY idea what this could be?
    I spoke to the guy who built my PC and he is changing the USB ports, He also said if that doesn't work he will change my motherboard..
    Is there a simple solution to this? Am i going to have to change Motherboard? ANY help would really be greatful.

    Hold your horses....
    Have you done some "rule out" testing? How do you know that the USBs are bad? How do you know that the MB is bad?
    1/ do all ports work when you plug a mouse in them?
    2/ what is a throughput when you plug a flash drive into these USBs (try 1 at a time) and copy a large file onto it? Test all the ports and compare speeds - are they at least 5-10 MB per sec? If yeah, then they are OK - system wise.
    If the USBs don't work and it's a PCI card, look for drivers and if no luck, buy a new card.
    If the USBs are built into the MB, then you have no other choice but to replace it, but only as the very last resort. Seems to me that he's trying ot hose you, my friend.....
    IN any case, it could be the drivers! Or..iTunes. Did you try to remove & reinstall?

  • Need some help here.. pretty please..!

    Im just wondering how to add contacts, calendar and notes to my ipod mini. coz i tried the instructions there but it didnt work. my ipod is already in disk use and im using microsoft outlook.. pls help me.. thanx soo much..!!!

    Hudgie, "How do I get my Contacts and Calendars onto m", 01:52am Feb 2, 2005 CDT

  • Hey fellows...need some help here....please..!!!

    OK, this is what I have....;javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Interface extends JFrame implements ActionListener{
    Queue queue;
    JButton QButton;
    JLable QLabel;
    public Interface(){
    window = new JFrame("practice");
    window.setBounds(0,0,250,200);
    window.getContentPane().setLayout(null);
    queue = new Queue(); The error I get is:
    java.awt.Queue is not public in java.awt; cannot be accessed from outside package
    Any ideas!!!

    Okay, first point I notice is that the first line should be "import javax.swing.*" not "javax.swing.*"
    The reason for the error is that you are using your own 'Queue' class (I presume), and yet there is a Queue class also in the awt package (which is not intended for developer use). This means the compiler does not know which Queue class to pick. Removing the 'import java.awt.*' should get rid of this error. However, if you are using any of the classes in the awt package (such as Button, BorderLayout, etc), you will need to import them individually (e.g. import java.awt.Button;).

  • Need some help here please

    My computer was sent away for repairs and among other things (it was a very sick computer) it was reformatted. When I got my computer back I downloaded iTunes and plugged my iphone in. It recognised that i had a iphone and an account but I cannot do anything with it on itunes - I cant move the apps around, I cant put music on - nothing. If anyone knows how to fix this little it would be greatly appreciated.
    P.S I am about as far from computer savvy as you can get so step by step instructions would be a bonus lol

    By design, the iphone will sync itunes content with one computer at a time. Any attempt to sync such content with a second computer will result in ALL itunes content being first erased from your phone & then replaced with the content from the second computer. This is a design feature and cannot be overridden. The itunes content sync is one way: computer to phone. If you have photos that were synced to your phone or music ripped on your own that were not backed up, you will first have to extract them from your phone using third party software:
    http://www.wideanglesoftware.com/touchcopy/index.php
    Once you've done that, do the following in the order specified:
    1. Disable auto sync when an ipod/iphone is connected under preferences in itunes, which in windows is under the edit menu.
    2. Make sure you have one contact & one event in whatever programs you use for that purpose on your computer. The entries can be fake, doesn't matter, the important point is that these programs not be empty.
    3. Connect your phone, itunes running, do not sync at this point.
    4. Store>Authorize this computer.
    5. File>Transfer Purchases(To make sure all purchased content on your phone will be in your itunes library).
    6. Right click in the device pane & select reset warnings.
    7. Right click again and select backup.
    8. Right click again & select restore from backup, select the backup you just made. When prompted to create another backup, decline.
    9. This MUST be followed by a sync to restore your itunes content, which you select from the various tabs, You'll get a popup regarding your contacts & calendars asking to merge or replace, select merge.
    That's as good as it gets without a backup of your itunes library.

Maybe you are looking for

  • I can no longer turn off programs after ios7 update

    I just upgraded my iPhone 5 to iOS 7 and can  I longer turn off apps to conserve battery. (Double-tap home, touch & hold on the app to close and then touch the   X to close it). I just end up in the app I want to close. Has anyone else figured out ho

  • Minact-scn errors in Alert and Trace Files

    we have enabled trace for one session (  where select query is running ) and we seen this error in trace file can any one suggest me to resolve this issue. --------------------------------------------------------------Trace File----------------------

  • How to run weblogic 8.1 and weblogic 9.2 simultaneously

    I have data service platform installed on Weblogic 8.1 platform and Aqualogic service bus installed with Weblogic 9.2.And I want to start both the servers at the same time. I have configured Weblogic server 8.1 domain to listen on 7771 port while web

  • Any plug in to create a 3D charts and graphs?

    I've been creating them from scratch. It has got to be something like that exist, surely? Thanks in Advance.

  • Converting spool of line width more than 850 char to PDF format in ECC 6.0.

    Hello Experts. I am facing problem while trying to convert a spool (generated from background scheduling of an ALV ) to PDF format in ECC 6.0. The ALV has 45 columns. Using SAP note no 1226758 I am able to increase the spool width but when I am conve