Question

I have a text file that this project needs to read from that has every possible...

I have a text file that this project needs to read from that has every possible combination of words but I am unsure how to do it. Also I'm pretty sure this program could use a program called "myArraylist" to sort through the text file but I am unsure how to implement this. I am unsure how to show the text file because it is massive, and I don't think it is possible to upload a text file to chegg. In this project you will develop a program which will find all the corresponding English words given any specific telephone number. Here are the detailed requirements:

Standard telephone keypads contain the digits zero through nine. The numbers two through nine each have 3~4 letters (case insensitive) associated with them. Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might remember it as "NUMBERS."

a.In the Project2 class you will create a static void test() method.

b.The test method will first ask the user to type in through keyboard a 7-digit telephone number.

c.If the number typed in by the user is not 7 digits or the number contains some number of the digit ‘0’ or ‘1’, then your program reports an error and asks to type in another number.

d.If the number typed in by the user is a 7-digit telephone number made up of the digits ‘2’ through ‘9’, then your program will print out all the possible English words corresponding to the telephone number (and the total number of them), using the given English word library in the “EnglishWordList.txt”.

e.The “EnglishWordList.txt” file should be located in the folder where your project folder is located (i.e. this file and your project folder are sitting next to each other). This way when you zip your project folder to submit “EnglishWordList.txt” file will not be zipped into the zip file.

f.NOTE: When you open files for read or write you cannot use an absolute file path but have to use a relative file path.

Digit Letters:

2 A B C

3 D E F

4 G H I

5 J K L

6 M N O

7 P Q R S

8 T U V

9 W X Y Z

import java.util.Scanner;

public class Project2{
// all a, b, c parts are done here
public static void test() {
Scanner in = new Scanner(System.in);
int length=0, flag=0;
while(length!=7 || flag==0) {
int a = in.nextInt();
String num = String.valueOf(a);
System.out.println("You entered integer "+a);
length = num.length();
if(length!=7) {
System.out.println("Not Valid");
} else {
int zero = num.indexOf('0');
int one = num.indexOf('1');
System.out.println("one " + one);
System.out.println("zero " + zero);
  
if(zero+one==-2) {
flag=1;
System.out.println("Valid");
} else {
System.out.println("Not valid");
flag=0;
}
}
}
}

public static void main(String []args) {

test2();
  
// part d start here
Scanner sc = new Scanner(new File("EnglishWordList.txt"));
List dataList = new ArrayList();
while(sc.hasNextLine()) {
dataList.add(sc.nextLine());
}
}
}

MyArrayList

package collection;

public class MyArrayList implements Cloneable {
public Object[] obj;
public int maxsize = 1000, initialsize = 0;
  
public MyArrayList() {
obj = new Object[maxsize];
}
  
public void append(Object element) {
if (initialsize < maxsize)
obj[initialsize++] = element;
else
System.out.println("Full");
}

public void clear() {
obj = new Object[maxsize];
}

public boolean contains(Object element) {
for (int i = 0; i < initialsize; i++) {
if (obj[i] == element) {
return true;
}
}
return false;
}

public Object elementAt(int index) {
return obj[index];
}

public int indexOf(Object element) {
for (int i = 0; i < initialsize; i++) {
if (obj[i] == element)
return i;
}
return -1;
}

public void insertAt(int index, Object element) {
for (int i = initialsize; i > index; i--) {
obj[i] = obj[i - 1];
}
obj[index] = element;
initialsize++; //this is important
}
  
public boolean isEmpty() {
return initialsize == 0;
}

public void removed(int index) {
for (int i = index; i < initialsize - 1; i++) {
obj[i] = obj[i + 1];
}
initialsize--;
}

public void remove(Object element) {
for (int i = 0; i < initialsize; i++) {
if (obj[i] == element) {
removed(i);
break;
}
}
}

public void replace(int index, Object element) {
obj[index] = element;
}

public int size() {
return initialsize;
}

public boolean ensureCapacity(int minCapacity) {
return initialsize >= minCapacity;
}

public Object clone() throws CloneNotSupportedException {
return super.clone();
}

public void removeRange(int fromIndex, int toIndex) {
for (int i = fromIndex; i < toIndex; i++) {
removed(i);
}
}
  
public String toString() {
StringBuilder builder = new StringBuilder(" ");
for (int i = 0; i < initialsize; i++) {
builder.append(obj[i]);
}
return builder.toString();
}

public void reverse() {
int last = initialsize - 1;
for (int i = 0; i < (initialsize - 1) / 2; i++) {
Object temp = obj[i];
obj[i] = obj[last];
obj[last] = temp;
last--;
}
}

public void merge(MyArrayList arraylist2) {
for (int i = 0; i < arraylist2.size(); i++) {
obj[initialsize++] = arraylist2.elementAt(i);
}
}

public void print() {
for (int i = 0; i < initialsize; i++) {
if (i > 0 && (i % 10 == 0)) {
System.out.println();
}
System.out.print(obj[i] + " ");
}
}

public void removedAt(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Project2{

// all a, b, c parts are done here

public static void test() {

Scanner in = new Scanner(System.in);

int length=0, flag=0;

while(length!=7 || flag==0) {

int a = in.nextInt();

String num = String.valueOf(a);

System.out.println("You entered integer "+a);

length = num.length();

if(length!=7) {

System.out.println("Not Valid");

} else {

int zero = num.indexOf('0');

int one = num.indexOf('1');

System.out.println("one " + one);

System.out.println("zero " + zero);

  

if(zero+one==-2) {

flag=1;

System.out.println("Valid");

} else {

System.out.println("Not valid");

flag=0;

}

}

}

}

public static void main(String []args) {

test2();

  

// part d start here

Scanner sc = new Scanner(new File("EnglishWordList.txt"));

List<String> dataList = new ArrayList<String>();

while(sc.hasNextLine()) {

dataList.add(sc.nextLine());

}

// taking out the data from the calss goes here

// I don't know how the data is present in the EnglishWordList.txt file

// That's why I am unable to help more, hope it will help

// Please hit upvote button, to keep me motivated

}

}

Add a comment
Know the answer?
Add Answer to:
I have a text file that this project needs to read from that has every possible...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I've previously completed a Java assignment where I wrote a program that reads a given text...

    I've previously completed a Java assignment where I wrote a program that reads a given text file and creates an index that stores the line numbers for where individual words occur. I've been given a new assignment where I need to modify some of my old code. I need to replace the indexer in my Index class with a NavigableMap<String, Word> and update my Word class with NavigableSet<Integer> lines. The instantiated objects should be TreeMap() and TreeSet(). I have below...

  • JAVA: Rewrite the following code to where the inputs are from a file. The file name...

    JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; }    public static void main(String[] args) { int n, i, k; System.out.println("Enter...

  • JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year...

    JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data 2004/Ali/1212/1219/1 2003/Bob/1123/1222/3 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2001/Jim/1101/1201/3 Text file Class storm{ private String nameStorm; private int yearStorm; private int startStorm; private int endStorm; private int magStorm; public storm(String name, int year, int start, int end, int mag){ nameStorm = name; yearStorm = year; startStorm...

  • I have a program that reads a file and then creates objects from the contents of...

    I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • I am trying to read from a file with with text as follows and I am...

    I am trying to read from a file with with text as follows and I am not sure why my code is not working. DHH-2180 110.25 TOB-6851 -258.45 JNO-1438 375.95 CS 145 Computer Science II IPO-5410 834.15 PWV-5792 793.00 Here is a description of what the class must do: AccountFileIO 1. Create a class called AccountFileIO in the uwstout.cs145.labs.lab02 package. (This is a capital i then a capital o for input/output.) a. This class will read data from a file...

  • I wrote two java classes. One is main and other one is getter and setter. I...

    I wrote two java classes. One is main and other one is getter and setter. I brought methods from Digit class to Main class to print result. However, for some reason, only welcome print statement got printed and others got ignored. On the output screen, only welcome statement appear. nDigit should be input from user. import java.util.Scanner; public class Main {    public static void main(String[] args)    {        Digit digitGet = new Digit();              ...

  • composed the following java code to read a string from a text file but receiving compiling...

    composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main {   public static void main(String[] args) {     System.out.print("Enter the...

  • The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements...

    The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects. 1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT