Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Java program


ghost's Avatar
0 0

I have an assignment for java and I cant get it to compile and I dont know what is wrong, the script is:

import java.text.*;
import java.util.StringTokenizer.*;

public class d {
	public static void main (String [] args) throws IOException {
	double LOA;
	double LWL;
	double Beam;
	double Disp;
	double SailArea;
	String str;
	
        BufferedReader reader =
                new BufferedReader (new InputStreamReader (System.in));

        StringTokenizer tokenizer = new StringTokenizer (stdin.readLine ());

	System.out.println ("LOA: " + LOA);
        System.out.println ("LWL: " + LWL);
        System.out.println ("Displacement: " + Disp);
        System.out.println ("Beam: " + Beam);
        System.out.println ("Sail area: " + SailArea);
	System.out.print ("");
	System.out.println ("Hull Speed is: " + 1.34 * Math.pow(LWL , 0.5));
	System.out.println ("D/L: " + Disp  / (0.01 * (LWL  * LWL  * LWL ))); 
	System.out.println ("SA/D: " + SailArea  / Math.pow((Disp  / 64.0), 0.67));
	System.out.println ("Capsize index: " + Beam  / Math.pow((Disp  / 64.0), 0.33));
	System.out.println ("Comfort index: " + Disp  / (0.65 * ((0.7 * LWL ) + (0.3 * LOA )) * Math.pow(Beam , 1.33)));

	}
}```

and the errors I get back are:```markupd.java:17: cannot resolve symbol
symbol  : class StringTokenizer 
location: class d
        StringTokenizer tokenizer = new StringTokenizer (stdin.readLine ());
        ^
d.java:17: cannot resolve symbol
symbol  : class StringTokenizer 
location: class d
        StringTokenizer tokenizer = new StringTokenizer (stdin.readLine ());
                                        ^
d.java:17: cannot resolve symbol
symbol  : variable stdin 
location: class d
        StringTokenizer tokenizer = new StringTokenizer (stdin.readLine ());
                                                         ^
3 errors```
can anyone help me?

ghost's Avatar
0 0

Hi! You're code is not running since you're passing a parameter to the StringTokenizer class that is undeclared and uninitialized, it should be done this way…

BufferedReader reader = new BufferedReader(new InputStreamReader(
			System.in));

	StringTokenizer tokenizer = new StringTokenizer(reader.readLine());

…………. BUT …………….. you should be using the args String array variable to retrieve user inputs or arguments for this task instead of the BufferedReader. It is unnecessary…


ghost's Avatar
0 0

Try this out instead:

public static void main(String[] args) throws IOException {
	
	if (args != null && args.length <= 5) {
		double LOA = Double.parseDouble(args[0]);
		double LWL = Double.parseDouble(args[1]);
		double Beam = Double.parseDouble(args[2]);
		double Disp = Double.parseDouble(args[3]);
		double SailArea = Double.parseDouble(args[4]);
		String str = args[5];
		
		//do your other stuf here
		
	}
    }

ghost's Avatar
0 0

oh wait, change that condition I just gave in my last reply in main method with 'args.length <= 6' … sorry 4 that ;)

Cheers!


ghost's Avatar
0 0

just note that every java program needs to have a main method to operate so u need

public static void main(String[] args) {

}