Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This need to fill in the blank in order to pass the test class. This is multiplication tables: This is the Scorable.class: import java.lang.annotation.ElementType; import

This need to fill in the blank in order to pass the test class.

image text in transcribed

This is multiplication tables:

image text in transcribed

image text in transcribed

This is the Scorable.class:

import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;

/** * This defines a method annotation that will enable test code to define specific scoring options and not just rely on * the percentage of tests passed. * * @author Matthew Hertz */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE }) public @interface Scorable { public double points() default 100.0; public String problem() default "Score"; }

This is the MultiplicationTableTest.class:

import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue;

import java.util.Random;

import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout;

import edu.buffalo.correctness.Scorable;

/* * Homework test cases
* (C) 2018 by Matthew Hertz
* Posting this file to a website without the explicit written permission of the author is a violation of their * copyright. */ @Scorable(problem = "Homework04Problem2") public class MultiplicationTableTest {

@Test public void testGenerateTableLength0() { int[] actual = MultiplicationTable.generateTable(3, 0); assertNotNull("generateTable() should always instantiate and return an array", actual); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 0, actual.length); int[] actual2 = MultiplicationTable.generateTable(7, 0); assertNotNull("generateTable() should always instantiate and return an array", actual2); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 0, actual2.length); int[] actual3 = MultiplicationTable.generateTable(-1, 0); assertNotNull("generateTable() should always instantiate and return an array", actual3); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 0, actual3.length); }

@Test public void testGenerateTableLength1() { int[] actual = MultiplicationTable.generateTable(3, 1); assertNotNull("generateTable() should always instantiate and return an array", actual); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 1, actual.length); assertEquals("The value of the entry at index 0 in the returned array is incorrect", 0, actual[0]); int[] actual2 = MultiplicationTable.generateTable(7, 1); assertNotNull("generateTable() should always instantiate and return an array", actual2); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 1, actual2.length); assertEquals("The value of the entry at index 0 in the returned array is incorrect", 0, actual2[0]);

int[] actual3 = MultiplicationTable.generateTable(-1, 1); assertNotNull("generateTable() should always instantiate and return an array", actual3); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 1, actual3.length); assertEquals("The value of the entry at index 0 in the returned array is incorrect", 0, actual3[0]); } @Test public void testGenerateTableLength3() { int[] actual = MultiplicationTable.generateTable(3, 3); assertNotNull("generateTable() should always instantiate and return an array", actual); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 3, actual.length); assertEquals("The value of the entry at index 0 in the returned array is incorrect", 0, actual[0]); assertEquals("The value of the entry at index 1 in the returned array is incorrect", 3, actual[1]); assertEquals("The value of the entry at index 2 in the returned array is incorrect", 6, actual[2]); int[] actual2 = MultiplicationTable.generateTable(7, 3); assertNotNull("generateTable() should always instantiate and return an array", actual2); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 3, actual2.length); assertEquals("The value of the entry at index 0 in the returned array is incorrect", 0, actual2[0]); assertEquals("The value of the entry at index 1 in the returned array is incorrect", 7, actual2[1]); assertEquals("The value of the entry at index 2 in the returned array is incorrect", 14, actual2[2]); int[] actual3 = MultiplicationTable.generateTable(-1, 3); assertNotNull("generateTable() should always instantiate and return an array", actual3); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", 3, actual3.length); assertEquals("The value of the entry at index 0 in the returned array is incorrect", 0, actual3[0]); assertEquals("The value of the entry at index 1 in the returned array is incorrect", -1, actual3[1]); assertEquals("The value of the entry at index 2 in the returned array is incorrect", -2, actual3[2]); } @Test public void testGenerateTableLengthBig() { int length = new Random().nextInt(100) + 60; int[] actual = MultiplicationTable.generateTable(3, length); assertNotNull("generateTable() should always instantiate and return an array", actual); assertEquals("generateTable() should always instantiate and return an array whose length is equal to numEntries", length, actual.length); int current = 0; int limit = length * 3; int idx = 0; while (current limit3) { assertEquals("The value of the entry at index " + idx3 + " in the returned array is incorrect", current3, actual3[idx3]); idx3 += 1; current3 += -1; } }

Problem #2-Multiplication Tables While learning multiplication in primary school, kids often have to write their times tables, When filled in correctly, each item in the array has the value of multiplying a number by the index for that entry. So if the constant were 3, we would need to return an array whose entries are 0,3, 6, 9, 12, etc. This is neither interesting nor exciting, but it is a proven way to help children learn how multiplication works AND help CSE students learn how arrays work. Download the itinliatilass do to work. You can check your solution orrer t code on your own I have started. You will need to complete this class's venerateTable) and checkTable methods. Each method's Javadoc describes what the method will need to ubleQ using the Nul i li t n. lest class included n this JAR file. The test cases for t are on y on AutoLab, so you will want to test this Submit your completed file to Autolab for Homework 04 Problem 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions

Question

2. Name the three catecholamine neurotransmitters.

Answered: 1 week ago