Endless Paradigm

Full Version: Help With Java
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Spoiler:

Code:
import java.io.*;

public class SpeedCam
{
	private static final String FILE_SPEC0 = "C://camera0_test1.dat";
	private static final String FILE_SPEC1 = "C://camera0_test2.dat";
	private static final int SPEED_LIMIT = 50;

	public static void processData()
	{
		FileInputStream fis;
		DataInputStream dis;
		FileOutputStream fos;
		DataOutputStream dos;
		String regNum;
		int Time1;
		int Time2;
		int Time3;
		String VehicleType;
		
		try
		{
			fis = new FileInputStream(FILE_SPEC0);
			dis = new DataInputStream(fis);
			fos = new FileOutputStream(FILE_SPEC1);
			dos = new DataOutputStream(fos);

			while(true)
			{
				try
				{
					regNum = dis.readUTF();
					Time1 = dis.readInt();
					Time2 = dis.readInt();
					Time3 = dis.readInt();
					VehicleType = dis.readUTF();
					System.out.print(regNum+"\t"+Time1+"\t"+Time2+"\t"+Time3+"\t"+VehicleType);
					
				}
				catch(Exception e)
				{
					fis.close();
					fos.close();
				}
			}
		}
		catch(Exception e)
		{
		}
	}

	public static void main(String[] args)
	{
		processData();
	}
}

I don't have even the vaugest idea what's wrong with this, but its flat out refusing to print. The file exists, and supposedly contains relevant information, although i can't confirm this. Does anyone have enough experience to be able to guide me down the right path so i can get started on this application
Ignore this, Time3 didnt exist and removing it solved the issues. Crappy programming lecturer
lolz .. couldnt help anyway :p .. lost all my java knowledge :p
boogschd Wrote:lolz .. couldnt help anyway :p .. lost all my java knowledge :p

lol. unfortunately I pretty much did too. :p
java is the evilsauce. it exists soley to make my life miserable.
Like I said, CS = my worst enemy
./xitherun.sh Wrote:
boogschd Wrote:lolz .. couldnt help anyway :p .. lost all my java knowledge :p

lol. unfortunately I pretty much did too. :p

I never had any, but i have to write a confusing program, so expect a couple of these XD
Lulz, same here. Though I am not as far as you are. I have to write a Tic-tac-toe program within the next week for homework XD

Hardcore!
MOAR HALP TIEM!!!!


Im screwed. i can't make this program output index, and its absolutely killing me. Not supposed to fix any errors unless theyre syntax, so that's not what needs sorting...just a couple of lines to make it run

Anyone can help
Spoiler:
import java.util.Scanner;

public class Annex1 {


	
    private static String calcIndex(int gr, int wo, int con)
    {
	
String index = "";
	
boolean ok = true;
	
String index1;
	
String index2;
	
String index3;

	


	
if(gr < 1 || gr > 8)
	
{
	
    ok = false;
	
}
	
if(con < 1 || con > 4)
	
{
	
    ok = false;
	
}
	
if(!ok)
	
{
	
    index = "ZZZZ";
	
}
	
else
	
{
	
    index1 = g_value(gr);
	
    index2 = w_value(wo);
	
    index3 = r_value(con);
	
    index = index1 + index2 + index3;
	
}
	
return index.toString();
	
}

	
    
	
    
    private static String g_value(int gr)
    {
	
Integer i = new Integer(gr);
	
return i.toString();
    }

    private static String w_value(int wo)
    {
	
int val;
	
Integer i;

	
if(wo < 500)
	
{
	
    val = 0;
	
}
	
else if(wo ≤ 1000)
	
{
	
    val = 1;
	
}
	
else if(wo < 2500)
	
{
	
    val = 2;
	
}
	
else
	
{
	
    val = 4;
	
}
	
i = new Integer(val);
	
return i.toString();
    }

    private static String r_value(int con)
    {
	
Integer i = new Integer(con);
	
return i.toString();
    }
    
	


    
	
/**
	
* @param args
	
*/
	
public static void main(String[] args) {
	
	
Scanner scanner = new Scanner(System.in);
	
	
int gr = scanner.nextInt();
	
	
int con = scanner.nextInt();
	
	
int wo = scanner.nextInt();
	
	
calcIndex(gr,con,wo);
	
	

	
}

}
Output, as in, display the result of calcIndex to the console?
If so, you should change

Java Code
calcIndex(gr,con,wo);

to

Java Code
System.out.println(calcIndex(gr,con,wo));

or whatever the proper Java functions are.

Reference URL's