SlideShare a Scribd company logo
I need help with this program for java.
The program you are given to start with: Lab4.java
The input file of ints:10,000ints.txt
The input file of words:172,822words.txt
Execute your program like this: C:> java Lab4 10000ints.txt 172822words.txt
Be sure to put the ints filename before the words filename. The starter file will be expecting them
in that order.
Lab#4's main method is completely written. Do not modify main. Just fill in the methods. Main
will load a large arrays of int, and then load a large array of Strings. As usual the read loops for
each file will be calling a resize method as needed. Once the arrays are loaded, each array will be
tested for the presence of duplicates via calls to indexOfFirstDuplicate(). Do not do any trim
operation.
Here are the rules:
In your methods that look for the first occurrence of a duplicate in each array, you must sort the
arrays before looking for the dupe. Do not search the array for the dupe until it is sorted. We
require this because an unsorted array would require a quadratic algorithm (N squared via nested
loops). If you sort you array first you will only incur an O(n*Log2n) cost for the sort with an
additional O(n) for the search. This is the best that can be done without using a technology such
as hashing which you will use for your next lab.
Inside your method to find the dupe you must sort the array first.
Do not define/use any new type or data structure that we have not covered yet.
Your traversal of the array looking for the dupe should require no more than one pass.
Be as efficient as you can without breaking rule #2.
Assuming the array below, the 1st occurrence of a duplicate is at index 4, not 3, since the
element at [4] is the first index position where that value was seen for a second time. Be sure you
understand this. Do not report the index of the first occurrence of a value as being the index
where the duplicate occurred.
Your job will be to fill in the definitions of these methods below main
static int[] upSizeArr( int[] fullArray ); // incoming array is FULL. It needs it's capacity doubled
static String[] upSizeArr( String[] fullArray ); // incoming array is FULL. It needs it's capacity
doubled
static int indexOfFirstDupe( int[] arr, int count ); // returns ind of 1st occurrence of duplicate
value
static int indexOfFirstDupe( String[] arr, int count ); // returns ind of 1st occurrence of duplicate
value
Here is the starting file!
Solution
HI, Please find my implementation of all required methods.
Please let me know in case of any issue.
/* Lab4.java Reads two files into two arrays then checks both arrays for dupes */
import java.io.*;
import java.util.*;
public class Lab4
{
static final int INITIAL_CAPACITY = 10;
static final int NOT_FOUND = -1; // indexOfFirstDupe returns this value if no dupes found
public static void main (String[] args) throws Exception
{
// ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON
THE COMMAND LINE
if (args.length < 1 )
{
System.out.println(" usage: C:> java Lab4   "); // i.e. C:> java Lab4 10000ints.txt
172822words.txt
System.exit(0);
}
String[] wordList = new String[INITIAL_CAPACITY];
int[] intList = new int[INITIAL_CAPACITY];
int wordCount = 0, intCount=0;
Scanner intFile = new Scanner( new File(args[0]) );
BufferedReader wordFile = new BufferedReader( new FileReader(args[1]) );
// P R O C E S S I N T F I L E
while ( intFile.hasNextInt() ) // i.e. while there are more ints in the file
{ if ( intCount == intList.length )
intList = upSizeArr( intList );
intList[intCount++] = intFile.nextInt();
} //END WHILE intFile
intFile.close();
System.out.format( "%s loaded into intList array. size=%d, count=%d
",args[0],intList.length,intCount );
int dupeIndex = indexOfFirstDupe( intList, intCount );
if ( dupeIndex == NOT_FOUND )
System.out.format("No duplicate values found in intList ");
else
System.out.format("First duplicate value in intList found at index %d ",dupeIndex);
// P R O C E S S S T R I N G F I L E
while ( wordFile.ready() ) // i.e. while there is another line (word) in the file
{ if ( wordCount == wordList.length )
wordList = upSizeArr( wordList );
wordList[wordCount++] = wordFile.readLine();
} //END WHILE wordFile
wordFile.close();
System.out.format( "%s loaded into word array. size=%d, count=%d
",args[1],wordList.length,wordCount );
dupeIndex = indexOfFirstDupe( wordList, wordCount );
if ( dupeIndex == NOT_FOUND )
System.out.format("No duplicate values found in wordList ");
else
System.out.format("First duplicate value in wordList found at index %d ",dupeIndex);
} // END MAIN
//############################################################################
######################
// FYI. Methods that don't say private are by default, private.
// copy/adapt your working code from lab3 || project3
static String[] upSizeArr( String[] fullArr )
{
/* Y O U R C O D E H E R E */
int currentSize = fullArr.length;
int newSize = currentSize*2;
// creating an array
String[] newArr = new String[newSize];
// copying valus from fullArr to newArr
for(int i=0; i

More Related Content

Similar to I need help with this program for java.The program you are given t.pdf

Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And AnswersH2Kinfosys
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programmingTaseerRao
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfQalandarBux2
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdfadinathassociates
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyworldchannel
 
Provide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docxProvide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docxtodd921
 
Programming in Python
Programming in Python Programming in Python
Programming in Python Tiji Thomas
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfRAJATCHUGH12
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxvannagoforth
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
 
Java căn bản - Chapter10
Java căn bản - Chapter10Java căn bản - Chapter10
Java căn bản - Chapter10Vince Vo
 
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01Abdul Samee
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 

Similar to I need help with this program for java.The program you are given t.pdf (20)

Week6.ppt
Week6.pptWeek6.ppt
Week6.ppt
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Provide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docxProvide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docx
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
set.pptx
set.pptxset.pptx
set.pptx
 
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdfI am stuck on parts E and FExercise 1      NumberListTester.java.pdf
I am stuck on parts E and FExercise 1      NumberListTester.java.pdf
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
Java căn bản - Chapter10
Java căn bản - Chapter10Java căn bản - Chapter10
Java căn bản - Chapter10
 
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 

More from fonecomp

write a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdfwrite a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdffonecomp
 
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdfwrite 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdffonecomp
 
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdfWhy do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdffonecomp
 
What was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdfWhat was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdffonecomp
 
Who are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdfWho are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdffonecomp
 
What sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdfWhat sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdffonecomp
 
What are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdfWhat are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdffonecomp
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
Sharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdfSharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdffonecomp
 
Quantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdfQuantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdffonecomp
 
Neeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdfNeeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdffonecomp
 
Describe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdfDescribe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdffonecomp
 
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdfHarrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdffonecomp
 
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdfHi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdffonecomp
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdfHow do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdffonecomp
 
General question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdfGeneral question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdffonecomp
 
Describe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdfDescribe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdffonecomp
 
4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdf4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdffonecomp
 
A single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdfA single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdffonecomp
 

More from fonecomp (20)

write a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdfwrite a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdf
 
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdfwrite 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
 
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdfWhy do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdf
 
What was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdfWhat was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdf
 
Who are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdfWho are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdf
 
What sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdfWhat sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdf
 
What are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdfWhat are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Sharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdfSharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdf
 
Quantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdfQuantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdf
 
Neeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdfNeeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdf
 
Describe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdfDescribe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdf
 
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdfHarrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
 
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdfHi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdfHow do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
 
General question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdfGeneral question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdf
 
Describe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdfDescribe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdf
 
4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdf4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdf
 
A single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdfA single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdf
 

Recently uploaded

Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17Celine George
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...sanghavirahi2
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Abhinav Gaur Kaptaan
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTechSoup
 

Recently uploaded (20)

Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 

I need help with this program for java.The program you are given t.pdf

  • 1. I need help with this program for java. The program you are given to start with: Lab4.java The input file of ints:10,000ints.txt The input file of words:172,822words.txt Execute your program like this: C:> java Lab4 10000ints.txt 172822words.txt Be sure to put the ints filename before the words filename. The starter file will be expecting them in that order. Lab#4's main method is completely written. Do not modify main. Just fill in the methods. Main will load a large arrays of int, and then load a large array of Strings. As usual the read loops for each file will be calling a resize method as needed. Once the arrays are loaded, each array will be tested for the presence of duplicates via calls to indexOfFirstDuplicate(). Do not do any trim operation. Here are the rules: In your methods that look for the first occurrence of a duplicate in each array, you must sort the arrays before looking for the dupe. Do not search the array for the dupe until it is sorted. We require this because an unsorted array would require a quadratic algorithm (N squared via nested loops). If you sort you array first you will only incur an O(n*Log2n) cost for the sort with an additional O(n) for the search. This is the best that can be done without using a technology such as hashing which you will use for your next lab. Inside your method to find the dupe you must sort the array first. Do not define/use any new type or data structure that we have not covered yet. Your traversal of the array looking for the dupe should require no more than one pass. Be as efficient as you can without breaking rule #2. Assuming the array below, the 1st occurrence of a duplicate is at index 4, not 3, since the element at [4] is the first index position where that value was seen for a second time. Be sure you understand this. Do not report the index of the first occurrence of a value as being the index where the duplicate occurred. Your job will be to fill in the definitions of these methods below main static int[] upSizeArr( int[] fullArray ); // incoming array is FULL. It needs it's capacity doubled static String[] upSizeArr( String[] fullArray ); // incoming array is FULL. It needs it's capacity doubled static int indexOfFirstDupe( int[] arr, int count ); // returns ind of 1st occurrence of duplicate value static int indexOfFirstDupe( String[] arr, int count ); // returns ind of 1st occurrence of duplicate
  • 2. value Here is the starting file! Solution HI, Please find my implementation of all required methods. Please let me know in case of any issue. /* Lab4.java Reads two files into two arrays then checks both arrays for dupes */ import java.io.*; import java.util.*; public class Lab4 { static final int INITIAL_CAPACITY = 10; static final int NOT_FOUND = -1; // indexOfFirstDupe returns this value if no dupes found public static void main (String[] args) throws Exception { // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println(" usage: C:> java Lab4 "); // i.e. C:> java Lab4 10000ints.txt 172822words.txt System.exit(0); } String[] wordList = new String[INITIAL_CAPACITY]; int[] intList = new int[INITIAL_CAPACITY]; int wordCount = 0, intCount=0; Scanner intFile = new Scanner( new File(args[0]) ); BufferedReader wordFile = new BufferedReader( new FileReader(args[1]) ); // P R O C E S S I N T F I L E while ( intFile.hasNextInt() ) // i.e. while there are more ints in the file { if ( intCount == intList.length ) intList = upSizeArr( intList ); intList[intCount++] = intFile.nextInt(); } //END WHILE intFile intFile.close();
  • 3. System.out.format( "%s loaded into intList array. size=%d, count=%d ",args[0],intList.length,intCount ); int dupeIndex = indexOfFirstDupe( intList, intCount ); if ( dupeIndex == NOT_FOUND ) System.out.format("No duplicate values found in intList "); else System.out.format("First duplicate value in intList found at index %d ",dupeIndex); // P R O C E S S S T R I N G F I L E while ( wordFile.ready() ) // i.e. while there is another line (word) in the file { if ( wordCount == wordList.length ) wordList = upSizeArr( wordList ); wordList[wordCount++] = wordFile.readLine(); } //END WHILE wordFile wordFile.close(); System.out.format( "%s loaded into word array. size=%d, count=%d ",args[1],wordList.length,wordCount ); dupeIndex = indexOfFirstDupe( wordList, wordCount ); if ( dupeIndex == NOT_FOUND ) System.out.format("No duplicate values found in wordList "); else System.out.format("First duplicate value in wordList found at index %d ",dupeIndex); } // END MAIN //############################################################################ ###################### // FYI. Methods that don't say private are by default, private. // copy/adapt your working code from lab3 || project3 static String[] upSizeArr( String[] fullArr ) { /* Y O U R C O D E H E R E */ int currentSize = fullArr.length; int newSize = currentSize*2; // creating an array String[] newArr = new String[newSize]; // copying valus from fullArr to newArr for(int i=0; i