Menu
support@authoritypapers.com
+1(805) 568 7317

this is a question regarding a java programming project every time i try to print th 5189096

This is a question regarding a Java programming project. Every time I try to print the following hashmap it prints the memory location (e.g., @Roster.class2923u3), rather than the actual values that are being passed into the map from another class. The toString method does not work, because I have tried that already. Also, I am using an iterator to go through the hashmap, which you will see below. NOTE: I have included the “Roster” class below the PitchCount class, if needed. Any help would be greatly appreciated.

public class PitchCount extends Roster

{

   private int pstrike;

   private int pball;

   private int count = 0;

private int outs = 0;

   private int runsScored = 0;

boolean hit = true;

public PitchCount()

   {

   }

   private static final HashMap myMap = new HashMap<>();

   static

   {

       final HashMap hm = myMap;

       hm.put(1, new Roster(“Robinson”, “Brooks”, 24));

       hm.put(2, new Roster(“Sheffield”, “Gary”, 34));

       hm.put(3, new Roster(“Smoltz”, “John”, 12));

       hm.put(4, new Roster(“Gant”, “Ronnie”, 35));

       hm.put(5, new Roster(“Ortiz”, “David”, 26));

       hm.put(6, new Roster(“Cabrera”, “Miguel”, 17));

       hm.put(7, new Roster(“Nixon”, “Trop”, 81));

       hm.put(8, new Roster(“Wakefield”, “Tim”, 12));

       hm.put(9, new Roster(“McCann”, “Brian”, 10));

       hm.put(10, new Roster(“Pedroa”, “Dustin”, 90));

   }

   public void loopUntilThree()

   {

       Set entrySet = myMap.entrySet();

       Iterator iter = entrySet.iterator();

       while (outs

       {

           Random randThrows = new Random();

           int mix;

           mix = randThrows.nextInt(3);

           switch (mix) {

           case 0:

               strike();

               break;

           case 1:

               ball();

               break;

           case 2:

               shuffleHits();

               break;

           }

/////////////This is where the code is printing out memory location and not the actual values//////////

           for (Entry entry : myMap.entrySet())

           {

               if (outs

               {

                   System.out.println(“Batter: ” + iter.next());

                   iter.remove();

                   System.out.println(displayPitches());

                   break;

               }

               if (outs == 2 && hit)

               {

                   System.out.println(“Batter: ” + iter.next().toString());

                   iter.remove();

                   System.out.println(displayPitches());

                   break;

               }

               else if (outs

               {

                   System.out.println(“Stay: ” + entry.getKey() + “, Name: ” + entry.getValue());

                   System.out.println(displayPitches());

                   break;

               }

           }

       }

   }

/////////////////Roster class/////////////

public class Roster

{

   String lname;

   String fname;

   int number;

   public Roster()

   {

       lname = “”;

       fname = “”;

       number = 0;

   }

   public Roster(String lname, String fname, int number)

   {

       this.lname = lname;

       this.fname = fname;

       this.number = number;

   }

   public void setLastName(String lname)

   {

       this.lname = lname;

   }

   public String getLastName()

   {

       return lname.toString();

   }

   public void setFirstName(String fname)

   {

       this.fname = fname.toString();;

   }

   public String getFirstName()

   {

       return fname;

   }

   public void setNumber(int number)

   {

       this.number = number;

   }

   public int getNumber()

   {

       return number;

   }

}

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now