Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:35:47+00:00 2026-06-16T01:35:47+00:00

I am working on some code for homework and for the life of me

  • 0

I am working on some code for homework and for the life of me can’t figure out why this won’t run. It ran until I added in the methods for file reading, which I know worked in another program. I took the code directly from some of my other work. So, can someone much better at Java than I tell me what I am doing wrong to have this problem? As this is homework please don’t tell me how to fix any other problems, but I wouldn’t discourage hints about them.

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class vowels_r_us {

//for file reading
private static FileInputStream inFile;
private static InputStreamReader inReader;
private static BufferedReader reader;

//pasrsing input from file
private static StringTokenizer strTkn;

public static void main(String[] args) 
{

    initFile(); //prepare file for reading

    while (reader.ready())//iterate as long as there is more avaliable data
    {
        String word, suffix, line;
        line = getWordSuffix();
        word = line.substring(0, line.indexOf(' '));
        suffix = line.substring(line.indexOf(' '));


    }
}

/*CONJUGATION METHODS*/
static String pluralize(String s)
{
    String pluralForm;
    switch (classifyEnding(s))
    {
        case 'c':
            pluralForm = s.concat("GH");
            break;
        case 'v':
            pluralForm = s.substring(0, s.length() - 1).concat("G");//drop last letter add G
            break;
        case 'd':
            pluralForm = s + s.charAt(s.length() - 1) +"H";//double last letter, then add H
            break;
        default:
            pluralForm = "If you are getting this something is broken, have fun debugging.";
            break;
    }
    return pluralForm;
}

static String addSuffix(String word, String suffix)
{
    String suffixAdded;
    switch (classifyEnding(word))
    {
        case 'c':
            suffixAdded = word + suffix;
            break;
        case 'v':
            if(isVowel(suffix.charAt(0)))
            {
                suffixAdded = word + suffix.substring(1);//word + drop first letter of suffix then add suffix
            }
            else
            {
                suffixAdded = word + suffix.charAt(0) + suffix;//word + first letter of suffix + suffix
            }
            break;
        case 'd':
            if(isVowel(suffix.charAt(0)))
            {
                suffixAdded = word + suffix.charAt(0) + suffix;//word + first letter of suffix + suffix
            }
            else
            {
                suffixAdded = trimRepeatSequence(word) + suffix;
            }
            break;
        default:
            suffixAdded = "If you are getting this something is broken, have fun debugging.";
            break;
    }
    return suffixAdded;
}
/*END CONJUGATION METHODS*/

/*STRING MODIFICATION AND TESTING METHODS*/
//removes lefmost vowel or consonant from sequence
static String trimRepeatSequence(String s)
{
    String editedString = "";
    boolean vBasedEnding = isVowel(s.charAt(s.length() - 1));

    for (int i = s.length() - 1; i >= 0; i--)
    {
        if (isVowel(s.charAt(i)) != vBasedEnding)
        {
            editedString = s.substring(0, i+1) + s.substring(i+2, s.length());
            break;
        }
    }

    return editedString;
}

/* classify endings in to three grammatical categories, single vowel ending 'v', single consonant ending 'c', double type ending 'd'
 */
static char classifyEnding(String s)
{
    char grammaticalClass;
    if (isVowel(s.charAt(s.length()- 1)) == isVowel(s.charAt(s.length()- 2)))
    {
        grammaticalClass = 'd';
    }
    else
    {
        grammaticalClass = isVowel(s.charAt(s.length()- 1)) == true? 'v' : 'c';
    }
    return grammaticalClass;
}

static boolean isVowel(char c)
{
    boolean b;//rename
    switch (Character.toLowerCase(c))
    {
        case 'a': case 'c':
        case 's': case 'l':
            b = true;
            break;

        default:
            b = false;
            break;
    }
    return b;
}
/*END STRING MODIFICATION AND TESTING METHODS*/

/*FILE READER METHODS*/
//read file for input
public static void initFile() throws IOException
{
    inFile = new FileInputStream ("C:\\Users\\Tom\\Dropbox\\!!VHSAPCSData\\VHSP35data.txt");
    inReader = new InputStreamReader(inFile);
    reader = new BufferedReader(inReader);
}

public static String getWordSuffix() throws IOException
{
    String line;

    line = reader.readLine();

    return line;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:35:49+00:00Added an answer on June 16, 2026 at 1:35 am

    You need to wrap your IO code in a try / catch:

    import java.io.*;
    import java.util.Scanner;
    
    public class ScanXan {
        public static void main(String[] args) throws IOException {
    
            Scanner s = null;
    
            try {
                s = new Scanner(new BufferedReader(new FileReader("xanadu.txt")));
    
                while (s.hasNext()) {
                    System.out.println(s.next());
                }
            } finally {
                if (s != null) {
                    s.close();
                }
            }
        }
    }
    

    taken from: http://docs.oracle.com/javase/tutorial/essential/io/scanning.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on homework and I won't post the full code but I'm stuck
I am working on some code that I inherited. This is my first try
I'm working some code that inserts csv rows into an SQLite database using Python.
I've been re-working some code due to a memory leak. The code is part
Working on some code for a machine problem; we've just started working with pointers,
I'm working on some code that reads from a socket, and it goes wrong
I'm working on some code to insert a link to a dupe in the
I am working on some code, basically I have a form. On that form
I'm working with some code that I've found online and I don't quite understand
I have been working on some code to submit an uploaded image to PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.