Question

import java.util.Scanner; import java.util.Random; public class ScoreDice { private Random r; public ScoreDice(long seed) { r...

import java.util.Scanner;
import java.util.Random;

public class ScoreDice {
private Random r;

public ScoreDice(long seed) {
r = new Random(seed);
}

public int rollD6() {
return r.nextInt(6) + 1;
}

public int score() {
int roll1 = rollD6();
int roll2 = rollD6();
return scoreWithNumbers(roll1, roll2);
}
  
// You will need to write a static method named scoreWithNumbers.
// scoreWithNumbers returns a score based on the values
// of its inputs, as such:
//
// - If both inputs are 1 or if both inputs are 6, then
// the returned score is 10
// - If both inputs are the same (but not 1 or 6), then
// the returned score is 8
// - If the inputs are different, the score is whatever the
// smaller value is (e.g., if given 3 and 4, it returns 3).
//
// TODO - write your code below this comment.
public static int scoreWithNumbers(int a, int b){
if ( a != b){
return Math.min(a,b);
}
if (( a == 1 && b == 1) || (a == 6 && b == 6)){
return 10;
}
else if ( a == b){
return 8;
}
return 0;
}
  

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter seed: ");
long seed = input.nextLong();
ScoreDice scoreDice = new ScoreDice(seed);
System.out.println("Score: " + scoreDice.score());
}
}

NEED HELP WITH TEST CODE

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class ScoreDiceTest {
    @Test
    public void testBoth6() {
        assertEquals(10, ScoreDice.scoreWithNumbers(6, 6));
    }
    
    // You must write at least FOUR more tests, one for each unique
    // behavior that scoreWithNumbers can show.  The test above
    // already tests for one of five possible behaviors; you must write
    // tests for the other four.  You may define redundant tests, but
    // you will receive no extra credit for them.
    //
    // If you're not sure you hit all the behaviors of interest, feel
    // free to ask us!
    //
    // TODO - write your code below this comment.
}

Homework Answers

Answer #1

Here are the 4 more test cases which will test for different cases.

Case 1: When both the inputs are 1, it should return 10.

Case 2: When both are equal but not 1 or 6, it should return 8.

Case 3: When inputs are not equal then function should return minimum input, in this case first argument is minimum.

Case 4: When inputs are not equal then function should return minimum input, in this case second argument is minimum.

Else everything in the program is correct.

Code:

  @Test

    public void testBoth1() {

        assertEquals(10, ScoreDice.scoreWithNumbers(1, 1));

    }

    @Test

    public void testBothEqualButNot6or1() {

        assertEquals(8, ScoreDice.scoreWithNumbers(2, 2));

    }

    @Test

    public void testFirstArgumentIsMin() {

        assertEquals(3, ScoreDice.scoreWithNumbers(3, 5));

    }

    @Test

    public void testSecondArgumentIsMin() {

        assertEquals(3, ScoreDice.scoreWithNumbers(5, 3));

    }

Code screenshot.

Know the answer?
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
Similar Questions
import java.util.Scanner; public class InRange { private int min; private int max; public InRange(int initialMin, int...
import java.util.Scanner; public class InRange { private int min; private int max; public InRange(int initialMin, int initialMax) { min = initialMin; max = initialMax; } // You need to write two instance methods: // 1.) A method named inRange, which takes an int. // This returns true if the int is within the given range // (inclusive), else false. // // 2.) A method named outOfRange which takes an int. // This returns false if the int is within the...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
Fix the program: what if the input is three? import java.util.Scanner public class Test { public...
Fix the program: what if the input is three? import java.util.Scanner public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); int m = in.nextInt(); System.out.print("Enter another integer: "); int n = in.nextInt(); System.out.println(m + " " + n); } }
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
import java.util.Scanner; public class ListDriver {    /*    * main    *    * An...
import java.util.Scanner; public class ListDriver {    /*    * main    *    * An array based list is populated with data that is stored    * in a string array. User input is retrieved from that std in.    * A text based menu is displayed that contains a number of options.    * The user is prompted to choose one of the available options:    * (1) Build List, (2) Add item, (3) Remove item, (4) Remove...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length();...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i].length() < minLength) minLength = array[i].length(); } return minLength; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] strings = new String[50]; for (int i = 0; i < strings.length; i++) { System.out.print("Enter string " + (i + 1) + ": "); strings[i] = in.nextLine(); } System.out.println("Length of smallest...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Stack2540Array import java .io .*; import java . util .*; public class Stack2540Array { int CAPACITY...
Stack2540Array import java .io .*; import java . util .*; public class Stack2540Array { int CAPACITY = 128; int top ; String [] stack ; public Stack2540Array () { stack = new String [ CAPACITY ]; top = -1; } 1 3.1 Implement the stack ADT using array 3 TASKS public int size () { return top + 1; } public boolean isEmpty () { return (top == -1); } public String top () { if ( top == -1)...
Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately....
Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately. Hint: Only one of the methods you create needs to be called from the main method. */ public class LandCalculation { public static void main(String[] args) { final int FEET_PER_ACRE = 43560; // Number of feet per acre double tract = 0.0, acres = 0.0; Scanner keyboard = new Scanner(System.in); System.out.print("Enter the tract size: "); tract = keyboard.nextDouble(); // Validate the user's input. while(tract...
Please solve this problem in java. import java.util.Arrays; public class PriorityQueue { /* This class is...
Please solve this problem in java. import java.util.Arrays; public class PriorityQueue { /* This class is finished for you. */ private static class Customer implements Comparable { private double donation; public Customer(double donation) { this.donation = donation; } public double getDonation() { return donation; } public void donate(double amount) { donation += amount; } public int compareTo(Customer other) { double diff = donation - other.donation; if (diff < 0) { return -1; } else if (diff > 0) { return...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT