JAVA JAVA JAVA JAVA ONLY PLEASE PLEASE HELP FAST >>>>>>>>>>>>>>>>>>>>>>>>>><<<<<
ID: 3806094 • Letter: J
Question
JAVA JAVA JAVA JAVA ONLY PLEASE PLEASE HELP FAST
>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>><>
Please help and follow exactly what the directions are asking this shouldnt be hard!
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
JAVA JAVA JAVA JAVA ONLY PLEASE PLEASE HELP FAST
>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>><>
Please help and follow exactly what the directions are asking this shouldnt be hard!
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
JAVA JAVA JAVA JAVA ONLY PLEASE PLEASE HELP FAST
>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>><>
Please help and follow exactly what the directions are asking this shouldnt be hard!
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Spring 201 Due: Monday, April 3, 11:55p to our Canvas site String Problem For each numerical value 0, 1,2, ...9 (0 NUMBER 9), embedded in a sentence, convert that value to its equivalent English text. Print the converted sentence both to the screen and to an output file Your input file consists of a variable number of records. Each record is a sentence of length 80 characters. More than one numerical value in the given range may appear in a sentence. You must deal with upper and lower case issues. If a line begins with a single digit, write that digit as a word. starting with an uppercase letter. See the examples below Examples: Input Record 3 foxes were chasing 5 rabbits and 10 ducks output Record: Three foxes were chasing five rabbits and 10 ducks. Input Record: I used 3 eggs out of the 12 for the cake output Record: I used three eggs out of the 12 for the cake Input Record 1 picture is worth 1000 words. output Record: One picture is worth 1000 words Input Record There are 260 students enrolled in Java. output Record: There are 260 student enrolled in Java.Explanation / Answer
package myProject;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
//Class Sentence Change definition
public class SentenceChange
{
//Instance variable declaration
String data[] = new String[100];
String resultData[];
String da;
int c = 0;
//Method to red file contents
void readFile()
{
//Try block
try
{
//File Reader object created to read data from Popularity.txt file
FileReader reader = new FileReader("Sentence.txt");
BufferedReader br = new BufferedReader(reader);
br = new BufferedReader(new FileReader("Sentence.txt"));
System.out.println("Sentence Information");
//Loops till end of file and reads data from file
while ((da = br.readLine()) != null)
data[c++] = da;
//Closes the file
reader.close();
br.close();
} //End of try block
//Catch block
catch (IOException e)
{
e.printStackTrace();
}//End of catch
}//End of method
//Method to convert single digit number to character form
void convertData()
{
String result = "";
resultData = new String[c];
//Loops till end of sentence
for(int x = 0; x < c; x++)
{
//Loops till end of sentence
for(int y = 0; y < data[x].length()-1; y++)
{
//Extracts current position character
char ch = data[x].charAt(y);
//Extracts next position character
char chNext = data[x].charAt(y + 1);
//Checks if the current position and next position character is digit
if((Character.isDigit(ch)) && (Character.isDigit(chNext)))
{
//Store both the characters in the result without changing
result = result + ch + chNext + " ";
//Increment the counter by 2
y+=2;
//Transfers the control to inner loop
continue;
}//End of if
//Checks if the current position character is digit and next character is space
else if((Character.isDigit(ch)) && (chNext == ' '))
{
switch(ch)
{
//If the character is zero
case '0':
//If it is first character
if(y == 0)
//Upper case
result += "Zero";
//Otherwise lower case
else
result += "zero";
break;
//If the character is one
case '1':
if(y == 0)
result += "One";
else
result += "one";
break;
//If the character is two
case '2':
if(y == 0)
result += "Two";
else
result += "two";
break;
//If the character is three
case '3':
if(y == 0)
result += "Thre";
else
result += "three";
break;
//If the character is four
case '4':
if(y == 0)
result += "Four";
else
result += "four";
break;
//If the character is five
case '5':
if(y == 0)
result += "Five";
else
result += "five";
break;
//If the character is six
case '6':
if(y == 0)
result += "Six";
else
result += "six";
break;
//If the character is seven
case '7':
if(y == 0)
result += "Seven";
else
result += "seven";
break;
//If the character is eight
case '8':
if(y == 0)
result += "Eight";
else
result += "eight";
break;
//If the character is nine
case '9':
if(y == 0)
result += "Nine";
else
result += "nine";
break;
}//End of switch
}//End of if
//Otherwise concatenate the character to result without changing
else
{
result += ch;
}//End of else
}///End of inner loop
//Assign the result to result data array at x position
resultData[x] = result;
//Reset the result to null for next line
result = "";
}//End of output loop
}//End of method
//Method to display the converted sentence
void displaySentence()
{
//Loops through all sentences
for(int x = 0; x < c; x++)
{
//Displays the converted sentences
System.out.println(resultData[x]);
}//End of for loop
}//End of method
//Main method
public static void main(String ss[])
{
//Creates an object of class SentenceChange
SentenceChange sc = new SentenceChange();
//Calls the method to read sentences from file
sc.readFile();
//Calls the method to convert single digits to character form
sc.convertData();
//Calls the method to display the converted sentences
sc.displaySentence();
}//End of method
}//End of class
File Sentence.txt Contents
The 8 eggs were seperated into 3 groups.
5 boys and 7 girls were present.
He was 1 hour and 5 minutes late.
She ate 3 dozen doughnuts!
4 dogs were chasing 3 cats.
The captain said, "This is the 0 hour".
I tried to call you 9 times today; Anna tried 6 times!!
The 12 firemen worked quickly.
Output:
Sentence Information
The eight eggs were seperated into three groups
Five boys and seven girls were present
He was one hour and five minutes late
She ate three dozen doughnuts
Four dogs were chasing three cats
The captain said, "This is the zero hour"
I tried to call you nine times today; Anna tried six times!
The 12 firemen worked quickly
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.