Question

This is the code I have written for a BingoBall program, I'd appreciate it if someone...

This is the code I have written for a BingoBall program, I'd appreciate it if someone could help me fix this

public class BingoBall {

private char letter;

private int number;

// NOTE TO STUDENT

// We challenge you to use this constant array as a lookup table to convert a number

// value to its appropriate letter.

// HINT: It can be done with with a single expression that converts the number

// to an index position in the following array.

private static char[] bingo = {'B','I','N','G','O'};

/**

* Creates a BingoBall with the given value.

* The appropriate letter is assigned.

* @param value between 1 and 75.

* @throws IllegalArgumentException if the

* number is not correct.

*/

public BingoBall(int value) {

number=value;

if(value<=15){

letter = 'B';

}

else

if (value<=30){

letter='I';

}

else

if (value<=45){

letter='N';

}

else

if(value<=60){

letter='G';

}

else

letter='O';

}

/**

* @return number value of BingoBall

*/

public int getValue() {

return number;

}

/**

* @return letter value of BingoBall

*/

public char getLetter() {

return letter;

}

/**

* Updates the number of BingoBall.

* The letter is automatically adjusted to the new value.

* @param The new value.

* @throws IllegalArgumentException if the

* value is not in between 1 and 75

*/

public void setValue(int value) {

number=value;

}//throw new IllegalArgumentException();

/*Determines if this BingoBall is equivalent to another BingoBall.

* Two BingoBalls are equivalent if their number value is the same.

* @param The BingoBall that is compared to this one.

* @return True if the balls are equivalent.

*/

public boolean equals(BingoBall other) {

return number.equals(other.number);

}

/* method returns a string that "textually represents" this object.

* @return a String representation of the ball as a letter immediately followed by an integer.

*/

public String toString() {

String str= getLetter()+" "+getValue()+" ";

return str;

}

// NOTE TO STUDENT:

// The following code is provided as an example of the testing

// that is required in each class that is created.

// Since this testing is done internally, any private methods you

// create can also be tested.

public static void main(String[] args) {

BingoBall b = new BingoBall(42);

System.out.println("Created a BingoBall: "+b);

System.out.println("The number is "+b.getValue());

System.out.println("The letter is "+b.getLetter());

BingoBall c = null;

try {

c = new BingoBall(76);

} catch (Exception e) {

System.out.println("Correctly caught the exception");

}

System.out.println("Created a second BingoBall: "+c);

c = new BingoBall(14);

if (!b.equals(c)) {

System.out.println("The two balls are not equivalent");

}

c.setValue(42);

System.out.println("The second ball has been changed to "+c);

if (b.equals(c)) {

System.out.println("They are now equivalent");

}

c.setValue(74);

System.out.println("The second bingo ball has been changed to "+c);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I hav fixed the Error


public class BingoBall {

   private char letter;

   private int number;

   // NOTE TO STUDENT

   // We challenge you to use this constant array as a lookup table to convert

   // a number

   // value to its appropriate letter.

   // HINT: It can be done with with a single expression that converts the

   // number

   // to an index position in the following array.

   private static char[] bingo = { 'B', 'I', 'N', 'G', 'O' };

   /**

   *

   * Creates a BingoBall with the given value.

   *

   * The appropriate letter is assigned.

   *

   * @param value

   * between 1 and 75.

   *

   * @throws IllegalArgumentException

   * if the

   *

   * number is not correct.

   *

   */

   public BingoBall(int value) {

       number = value;

       if (value <= 15) {

           letter = 'B';

       }

       else

       if (value <= 30) {

           letter = 'I';

       }

       else

       if (value <= 45) {

           letter = 'N';

       }

       else

       if (value <= 60) {

           letter = 'G';

       }

       else

           letter = 'O';

   }

   /**

   *

   * @return number value of BingoBall

   *

   */

   public int getValue() {

       return number;

   }

   /**

   *

   * @return letter value of BingoBall

   *

   */

   public char getLetter() {

       return letter;

   }

   /**

   *

   * Updates the number of BingoBall.

   *

   * The letter is automatically adjusted to the new value.

   *

   * @param The

   * new value.

   *

   * @throws IllegalArgumentException

   * if the

   *

   * value is not in between 1 and 75

   *

   */

   public void setValue(int value) {

       number = value;

   }// throw new IllegalArgumentException();

   /*

   * Determines if this BingoBall is equivalent to another BingoBall.

   *

   * Two BingoBalls are equivalent if their number value is the same.

   *

   * @param The BingoBall that is compared to this one.

   *

   * @return True if the balls are equivalent.

   *

   */

   public boolean equals(BingoBall other) {

       return number == other.number;

   }

   /*

   * method returns a string that "textually represents" this object.

   *

   * @return a String representation of the ball as a letter immediately

   * followed by an integer.

   *

   */

   public String toString() {

       String str = getLetter() + " " + getValue() + " ";

       return str;

   }

   // NOTE TO STUDENT:

   // The following code is provided as an example of the testing

   // that is required in each class that is created.

   // Since this testing is done internally, any private methods you

   // create can also be tested.

   public static void main(String[] args) {

       BingoBall b = new BingoBall(42);

       System.out.println("Created a BingoBall: " + b);

       System.out.println("The number is " + b.getValue());

       System.out.println("The letter is " + b.getLetter());

       BingoBall c = null;

       try {

           c = new BingoBall(76);

       } catch (Exception e) {

           System.out.println("Correctly caught the exception");

       }

       System.out.println("Created a second BingoBall: " + c);

       c = new BingoBall(14);

       if (!b.equals(c)) {

           System.out.println("The two balls are not equivalent");

       }

       c.setValue(42);

       System.out.println("The second ball has been changed to " + c);

       if (b.equals(c)) {

           System.out.println("They are now equivalent");

       }

       c.setValue(74);

       System.out.println("The second bingo ball has been changed to " + c);

   }

}




==========================
See Output



Thanks, PLEASE UPVOTE if helpful

Add a comment
Know the answer?
Add Answer to:
This is the code I have written for a BingoBall program, I'd appreciate it if someone...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • What is wrong with my code, when I pass in 4 It will not run, without...

    What is wrong with my code, when I pass in 4 It will not run, without the 4 it will run, but throw and error. I am getting the error   required: no arguments found: int reason: actual and formal argument lists differ in length where T is a type-variable: T extends Object declared in class LinkedDropOutStack public class Help { /** * Program entry point for drop-out stack testing. * @param args Argument list. */ public static void main(String[] args)...

  • PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test...

    PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test case for the below prompt using the provided java programs Use the setString() function in MyCustomStringInterface to set the value to “Peter Piper picked a peck of pickled peppers.”. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srep.”)....

  • This task involves constructing a Java program that supports interaction via a graphical user interface.The object...

    This task involves constructing a Java program that supports interaction via a graphical user interface.The object is to implement a Scrabble graphical game. The basis for the game is quite simple. Presented with a 6x6 grid of Scrabble tiles, the challenge is for the player(s) to form as many high scoring words as possible.  Words may only be formed from sequences of adjacent tiles.  Two tiles are adjacent if their edges or corners meet.  A tile may...

  • Need help with this Java. I need help with the "to do" sections. Theres two parts...

    Need help with this Java. I need help with the "to do" sections. Theres two parts to this and I added the photos with the entire question Lab14 Part 1: 1) change the XXX to a number in the list, and YYY to a number // not in the list 2.code a call to linearSearch with the item number (XXX) // that is in the list; store the return in the variable result 3. change both XXX numbers to the...

  • I need help fixing my java code for some reason it will not let me run...

    I need help fixing my java code for some reason it will not let me run it can someone pls help me fix it. class LinearProbingHashTable1 { private int keyname; private int valuename; LinearProbingHashTable1(int keyname, int valuename) { this.keyname = keyname; this.valuename = valuename; } public int getKey() { return keyname; } public int getValue() { return valuename; } } class LinearProbingHashTable2 { private final static int SIZE = 128; LinearProbingHashTable2[] table; LinearProbingHashTable2() { table = new LinearProbingHashTable2[SIZE]; for (int...

  • Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed...

    Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed from block-letters of size 7. Each block-letter is composed of 7 horizontal line-segments of width 7 (spaces included): SOLID                        as in block-letters F, I, U, M, A, S and the blurb RThere are six distinct line-segment types: TRIPLE                      as in block-letter M DOUBLE                   as in block-letters U, M, A LEFT_DOT                as in block-letters F, S CENTER_DOT          as in block-letter...

  • *JAVA* Can somebody take a look at my current challenge? I need to throw a different...

    *JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> {    private int top, size;    private E arrS[];    private static final int MAX_STACK_SIZE = 10;    public ArrayStack() {        this.arrS = (E[]) new Object[MAX_STACK_SIZE];        this.top = size;        this.size = 0;...

  • Can anyone helps to create a Test.java for the following classes please? Where the Test.java will...

    Can anyone helps to create a Test.java for the following classes please? Where the Test.java will have a Scanner roster = new Scanner(new FileReader(“roster.txt”); will be needed in this main method to read the roster.txt. public interface List {    public int size();    public boolean isEmpty();    public Object get(int i) throws OutOfRangeException;    public void set(int i, Object e) throws OutOfRangeException;    public void add(int i, Object e) throws OutOfRangeException; public Object remove(int i) throws OutOfRangeException;    } public class ArrayList implements List {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT