Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Java Task: Please help me to write a series of command line arguments that, when correctly specified, will cause the program to run to completion

Java Task:

Please help me to write a series of command line arguments that, when correctly specified, will cause the program to run to completion. This program is about a Puzzle.

The command line arguments must make the program to run to completion. Please read and help me. Thank you

Here is the task and example:

A Programming Puzzle

The file debugme/DebugMe.java is provided in the code pack and contains a puzzle. The main() method in this program accepts a series of command line arguments that, when correctly specified, will cause the program to run to completion. If the command line arguments are not specified correctly, the program will fail prematurely. The purpose of this problem is to determine the correct inputs to cause the program to run to completion.

DebugMe is arranged in "stages" and passing stages earns points. After each run the program prints the points earned based on the stages "passed". Example:

> java DebugMe userID(abc#) 0 0 0 Let the games... BEGIN! Phase One, let's have some fun! Double debugger burger, order up! oops! Game Over... >:( * Score: 0/55 pts * 

Notice that the first argument is always your UserID(abc#). DebugMe uses your UserID(abc#) to create a unique set of conditions which you must pass so that your experience with the program will likely be different from other students.

This task is actually kinder to you - if you fail one phase, you are able to continue to the next.

The stages in DebugMe are intentionally obscure. This is code that is meant to be a puzzle rather than easily readable and to that end, you are strongly encouraged to use a debugger while analyzing the program. Debuggers allow you to stop execution at any point and examine variables, step forward line by line, and ultimately identify which kinds of command line arguments will make it through a stage and which will cause the dreaded failure() method to be invoked ending the run. A primary goal of this problem is to gain experience with debuggers as they are incredibly useful tool for a programmer to have in their utility belt. Credit for the problem is entirely based on how many stages are passed.

Command Line Arguments

The only artifact of your efforts will be the specific command-line invocation of the program, as your only inputs are given as command-line arguments.

the first command-line argument must be your UserID. Many of the phases will use this to randomize and personalize the code for you - you've got your very own unique project!

each phase (method) will read the next few arguments (however many it needs), and use them in more and more quirky ways.

towards the end of each phase, there will be some check and a guarded call to failure(). Your goal is to figure out what command-line arguments will cause these failures to never happen.

if you need to include spaces in a single argument, please use double-quotes.

Running DebugMe through the Debugger

How can we use the debugger with command-line arguments? It's surprisingly easy in DrJava:

Compile DebugMe.java

Set a breakpoint in the phase you're working on

Turn on debugging mode under the debugging menu

In the Interactions Pane, run a command like this to launch DebugMe with command line arguments.

> java DebugMe UserID 0 0 0 Let the games... BEGIN! Phase One, let's have some fun! oops! Game Over... >:( error msg: Failure! Double debugger burger, order up! * Score: 0/55 pts. 

If you've turned on debugging, though, you get to step through and see what's happening.

Most IDEs have a means of running a program through a debugger. Learn about your tool if you are not using DrJava.

For the brave, there is also a command line debugger, command jdb which should be installed with every JDK. This is somewhat less convenient as it provides only limited source code display but can work with some classic unix tools.

Regardless of how you access the debugger, you will want to familiarize yourself with features such setting breakpoints to stop the running program, stepping forward line by line, and displaying the values of variables.

DebugMe is not a "real" program as it is intentionally obscure. However, as an exercise to learn how to analyze running programs it will provide invaluable experience. Happy bug squashing.

------Here is the java codes----

import java.util.*;

public class DebugMe { public static void main(String[] args){ int argsNeeded = 29; if (args.length:( "); } System.out.printf(" * Score: %s/%s pts * ",score,maxScore); } // 3 args public static void phase1(int hash, String[] args, int argStart){ int a = Integer.parseInt(args[argStart+0]); int b = Integer.parseInt(args[argStart+1]); int c = Integer.parseInt(args[argStart+2]); a += hash % 40; if (ac && a 4) { c += hash%13; } else { a *= hash%5 + 1; } int temp = 0; do { temp += a; temp *= b; } while (c --> 0); if (temp != d) failure("count around, products abound; what's that there - an arrow? uh-oh..."); } // 4 args public static void phase4(int hash, String[] args, int argStart){ String s = args[argStart+0]; int a = Integer.parseInt(args[argStart+1]); int b = Integer.parseInt(args[argStart+2]); int c = Integer.parseInt(args[argStart+3]); String temp1 = s.substring(a,b); String temp2 = s.substring(b,c); int temp3 = 0; while (temp320){ failure("uh-oh!"); } return z; } public static boolean prime(int n){ if (n<2) return false; for (int i=2; i stop) { return 0; } return start + (sumRange(start+1, stop)); } // 3 args public static void phase7(int hash, String[] args, int argStart){ int a = Integer.parseInt(args[argStart+0]); int b = Integer.parseInt(args[argStart+1]); int c = Integer.parseInt(args[argStart+2]); int d = sumRange(a,b); if (c!=d) { failure("round and round and round she goes, but where she stops, nobody knows!"); } } // With all this randomness, surely you want to step through with the // debugger, yes? // 3 args public static void phase8(int hash, String[] args, int argStart) { Random r = new Random(hash); int a = Integer.parseInt(args[argStart+0]); int b = Integer.parseInt(args[argStart+1]); int c = Integer.parseInt(args[argStart+2]); int s = 0; for (int i=0; i indexes = new ArrayList(); for (int i=0; i 1) DebugMe.failure("highlander rule: there can be only one (waldo)! "+indexes.size()); } public static String mutate(String s, int n, int seed){ debug(String.format("mutation(%s#): %s (hash=%s) ",n,s,seed)); Random r = new Random(seed); for (int i=0; i "+s); return s; } public static String attemptChange(String s, int seed){ debug(String.format("\tattempt(seed=%d): %s ",seed,s)); Random r = new Random(seed); int i = r.nextInt(s.length()+5); switch(r.nextInt(3)){ case 0: try{ debug(String.format("\t\t%s(%s)%s ",s.substring(0,i),letters.charAt(i),s.substring(i))); s = String.format("%s%s%s",s.substring(0,i),letters.charAt(i),s.substring(i)); } catch (StringIndexOutOfBoundsException e) { } break; case 1: try{ debug(String.format("\t\t%s(%s/%s)%s ",s.substring(0,i),letters.charAt(i),s.charAt(i),s.substring(i+1))); s = String.format("%s%s%s",s.substring(0,i),letters.charAt(i),s.substring(i+1)); } catch (StringIndexOutOfBoundsException e) { } break; case 2: try{ s = s.substring(0,i)+s.substring(i+1); } catch (StringIndexOutOfBoundsException e) { } break; default: debugln(" \t --> DEFAULT! "); } return s; } // any time the program has wandered into the wrong spot, we call this // to indicate the phase was not successfully passed. public static void failure(String msg){ throw new RuntimeException("Failure! "+msg); } }

Here is an additional link to the codes: https://paste.ee/p/RIDxP

Please help if you can. Thank you.

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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students explore these related Databases questions