Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FixFaculty.java TestFixFaculty.java 1 Problem description This is a story about a faulty robot, named Faultie. It forgets many things occasionally and makes all kinds of

image text in transcribedimage text in transcribed

FixFaculty.javaimage text in transcribedTestFixFaculty.java

image text in transcribed

image text in transcribed

1 Problem description This is a story about a faulty robot, named Faultie. It forgets many things occasionally and makes all kinds of mistakes. Among the kinds of mistakes it commits, a funny one is erroneous counting. Say you give an integer n to it and ask it to count from 1 to n. Assume that 1 sn s 5000. It will try to count the integers for you but the integer ordering may get scrambled and further, it may miss some of the integers. Here is an example. Say n = 10. Faultie may count the integers like this: 9,8,5,1,2. But we were expecting 1,2,3,4,5,6,7,8,9,10 from it. So as you have seen, not only it scrambled the ordering but also forgot quite a few numbers. But one assurance is that Faultie never repeats an integer; it says an integer exactly once. Your task is to write a program that will find out the numbers Faultie has missed and put them in sorted order. So, for the above example, your program should obtain the following sequence: 3,4,6,7,10. Observe that not only the missing numbers are obtained but also they are put in sorted order. Hint: there is an O(n) algorithm for this problem. Although your algorithm may have a worse time complexity, thinking about a O(n) time algorithm should be fun! No extra points for this though. This coding problem does not require any kind of file handling. This project has two classes only: HelpFaulty and TestHelpFaulty. For more information and sample tests, refer to the code outline. Make sure you understand the sample inputs and outputs well before you start coding. ** @author Type your full name (as it appears in Canvas) */ package exam1; public class FixFaulty { public static int[] findMissingIntegers(int n, int[] faultysoutput) { int[] answer = new int[n-faultysoutput. length]; ***/ // Your code goes right here. You may use helper methods if you want to. // You are not allowed to use any built-in Java data structures such as LinkedList, ArrayList, etc. // However, you can use arrays, as you did in your previous programming courses. **/ /** return answer; } } package exami; test: import java.util.Arrays; public class TestFixfaulty { // Please do not touch this method. // This method is just trying to match the expected output with the actual output. public static void match( int[] test, int[] expectedoutput, int[] actua loutput ) { if( Arrays.equals(expectedoutput, actualoutput ) ) System.out.println("Congratulations! Your code has passed the + Arrays.tostring(test) + ", "); else { System.out.println("Oops! Your code has failed the test: " + Arrays.toString(test) ); System.out.println("Expected output: " + Arrays.tostring(expectedoutput)); System.out.println("Actual output (output from you code): " + Arrays.tostring(actualoutput) + " "); } public static void main(String[] args) { int n; // Changes with every test input. M/Test 1/11 int[] testi - (9,8,5,1,2}; n = 10; int[] expectedOutput1 = {3,4,6,7,10); int i actualOutput1 = FixFaulty.findmissingIntegers(n, test1); match(testi, expectedoutputi, actualoutputi); //////Test 2/////// int[] test2 = {2,4,5,7,8,9,10,11,13}; n = 13; int[] expectedOutput2 = (1,3,6,12}; intij actualOutput2 = FixFaulty.findMissingIntegers(n, test2); match(test2, expectedOutput2, actualOutput2): /Test 3/11 int[] test3 = {10,9, 8, 7, 6,5}; n = 10; int[expectedoutput3 = {1,2,3,4}; int[] actualOutput 3 = FixFaulty.findMissingIntegers(n, test3); match(test3, expectedoutputs, actualoutput3); /////Test int[] test4 = {7}; n = 15; int[] expectedoutput 4 = {1,2,3,4,5,6,8, 9, 10, 11, 12, 13, 14, 15); intii actualOutput 4 = FixFaulty.findMissing Integers(n, test4); match(test4, expectedOutput4, actualOutput 4); M/Test 5/7 int[] test5 = {1,3,5,7,9); n = 11; int[] expectedoutputs = {2,4,6,8,10,11}; int[] actualoutput 5 = FixFaulty.findMissing Integers(n, test5); match(tests, expectedOutputs, actualOutput 5); tests."); System.out.println("*** Reminder *** for grading, we may use different System.out.println("So, use other tests too for testing your code."); } }

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

Step: 3

blur-text-image

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions