Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need Java help. I am getting the following errors and do not know how to fix them: Project2.java:29: error: int cannot be dereferenced if

I need Java help. I am getting the following errors and do not know how to fix them:

Project2.java:29: error: int cannot be dereferenced if (wordCount.length() >= words.length) ^ Project2.java:44: error: bad operand types for binary operator '||' if ( x =='a' || x == 'o'|| x == 'i' || x == 'u'|| x = 'e') ^ first type: boolean second type: char Project2.java:97: error: cannot find symbol if (array[i].equals.array[j]) ^ symbol: variable equals location: class String 3 errors

Can you also let me know if I did the upSize and downSize method correctly? Thank you for the help

My Code:

import java.io.*; import java.util.*;

public class Project2 { static final int INITIAL_CAPACITY = 10; 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 Project2 "); // i.e. C:\> java Project2 dictionary.txt System.exit(0); }

String[] words = new String[INITIAL_CAPACITY]; int wordCount = 0; int vowelCount = 0;

BufferedReader infile = new BufferedReader( new FileReader(args[0]) ); while ( infile.ready() ) { String word = infile.readLine();

// # # # # # DO NOT WRITE/MODIFY ANYTHING ABOVE THIS LINE # # # # # //upsize the array if (wordCount.length() >= words.length) { words = upSize(words); System.out.println( "words.length after upSize: " + words.length ); // use this line words[wordCount] = word; wordCount++; } /*now append the word onto the end of the array and increment wordCount

now examine every char in the word and every time you detect an a e i o or u, increment vowelCount

*/ for ( int i = 0; i

// # # # # # DO NOT WRITE/MODIFY BELOW THIS LINE IN MAIN # # # # #

} //END WHILE INFILE READY infile.close();

words = downSize( words, wordCount ); System.out.println( "After downSize() words.length=" + words.length + " wordCount=" + wordCount + " vowelCount=" + vowelCount );

System.out.println( "The duplicate word is: " + findFirstDupe( words, wordCount ) );

} // END main

// RETURN AN ARRAY OF STRING 2X AS BIG AS ONE YOU PASSED IN // BE SURE TO COPY ALL THE OLD OWRDS OVER TO THE NEW ARRAY FIRST static String[] upSize( String[] fullArr ) { int length = fullArr.length; String[] newArr = new String[2*length]; // assign the size for(int i = 0; i < length; i++) { newArr[i] = fullArr[i]; // copy } return newArr; }

static String[] downSize( String[] arr, int count ) { String[] newArr = new String[count]; for(int i = 0; i

static String findFirstDupe( String[] array, int count ) { // write a pair of nested loops that compare every stinrg to every other string // as soon as you fond two that are .equals to each other, immediately return that string for(int i = 0; i < count-1; ++i) // skip the last word {

for(int j = i+1; j < count; ++j) { if (array[i].equals.array[j]) { return array[i]; // return string } } } return "NO DUPE FOUND IN ARRAY"; // LEAVE THIS HERE }

} // END CLASS PROJECT#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

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

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

=+6. What is the competition?

Answered: 1 week ago

Question

query to remove duplicates in a distinct value column SQL

Answered: 1 week ago