Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your challenge is to examine the code in the file named Proj 0 5 . java along with the output text shown below to deduce

Your challenge is to examine the code in the file named Proj05.java along with the output text shown below to deduce the algorithm required to produce that output and to implement that algorithm in a file named Proj05Runner.java.
The output text for any given run will depend on the input value provided as a command-line argument. The text shown below was produced by five consecutive runs of the program for input values of 1,2,3,4, and 5 respectively. I will test your program with a different undisclosed input value. You can test your program by running your version and my version side-by-side and comparing the results for any input value that you choose.
You must define a new class named Proj05Runner. For this assignment, you must submit a single source code file named Proj05Runner.java encapsulated in a zip file. It must contain the definition of a class named Proj05Runner and nothing else other than required import directives. If you fail to comply with this requirement, you will not get credit for the assignment. You may not modify the class definition for the class named Proj05.
Your program must not produce any output similar to the following
Note: Proj05Runner.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
The purpose of Asg04 through Asg08 is to assess your ability to apply generics. It is not sufficient to simply insert the following annotation in your code to hide the warnings.
@SuppressWarnings("unchecked")
Do not include this annotation in your code.
Sample output for different command-line argument values follows:(argument of 1)
NOTE:
Only one new class definition is allowed.
Unchecked operations are not allowed.
Input: chris Bill Chris Chris Don don don Bill
Output: don don chris Don Chris Chris Bill Bill
(argument of 2)
NOTE:
Only one new class definition is allowed.
Unchecked operations are not allowed.
Input: bill Don chris don don bill ann Ann
Output: don don chris bill bill ann Don Ann
(argument of 3)
NOTE:
Only one new class definition is allowed.
Unchecked operations are not allowed.
Input: Ann Chris chris don don chris chris Bill
Output: don don chris chris chris Chris Bill Ann
(argument of 4)
NOTE:
Only one new class definition is allowed.
Unchecked operations are not allowed.
Input: ann Ann Ann Don Don don Chris Chris
Output: don ann Don Don Chris Chris Ann Ann
(argument of 5)
NOTE:
Only one new class definition is allowed.
Unchecked operations are not allowed.
Input: Ann ann Ann Bill don bill Chris Ann
Output: don bill ann Chris Bill Ann Ann Ann Here are the contens of Proj05 to help:import java.util.*;
class Proj05{
static String[] names =
{"Don","don","Bill","bill","Ann","ann","Chris","chris"};
static String[] myArray = new String[8];
public static void main(String args[]){
if(args.length ==0){
System.out.println(
"You must provide a command-line argument");
System.exit(0);
}//end if
System.out.println();
System.out.println("NOTE:");
System.out.println("Only one new class definition is allowed.");
System.out.println("Unchecked operations are not allowed.");
System.out.println();
Proj05Runner runner = new Proj05Runner();
int seed = Integer.parseInt(args[0]);
Random generator = new Random(seed);
//Create and display the data for input to the class
// named Proj05Runner.
System.out.print("Input: ");
for(int cnt =0;cnt <8;cnt++){
int index =((byte)generator.nextInt())/16;
if(index <0){
index =-index;
}//end if
myArray[cnt]= names[index];
System.out.print(myArray[cnt]+"");
}//end for loop
System.out.println();//new line
//Process the data and display the results.
Collection collection = runner.getCollection(myArray);
System.out.print("Output: ");
Iterator iter = collection.iterator();
while(iter.hasNext()){
System.out.print(iter.next()+"");
}//end while loop
System.out.println();
}//end main()
//----------------------------------------------------//
}

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions