Tak jak w temacie. Napisałem program:
package coursework2;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class coursework2
{
public static void main(String[] args)throws FileNotFoundException
{
Scanner Readin = new Scanner(new FileReader("Textfile.txt"));
int ShipLenght;
int ShipWidth;
int ShipHeight;
int ContainerLenght;
int ContainerWidth;
int ContainerHeight;
int ContainerWeight;
int MaxWeight;
int ContainerVolume;
int CargoHoldVolume;
int ShipWeight;
ShipLenght = Readin.nextInt();
ShipWidth = Readin.nextInt();
ShipHeight = Readin.nextInt();
ContainerLenght = Readin.nextInt();
ContainerWidth = Readin.nextInt();
ContainerHeight = Readin.nextInt();
ContainerWeight = Readin.nextInt();
MaxWeight = Readin.nextInt();
JOptionPane.showMessageDialog(null, "Lenght of the Cargo hold is " +ShipLenght + "\nWidth of the Cargo hold is " + ShipWidth + "\nHeight of the Cargo hold is " + ShipHeight + "\nLenght of the container is " + ContainerLenght + "\nWidth of the container is " + ContainerWidth + "\nHeight of the container is " + ContainerHeight + "\nWeight of the container is " + ContainerWeight + "\nMaximmum weight of the Cargo is " + MaxWeight, "Ship Info", JOptionPane.INFORMATION_MESSAGE);
Readin.close();
ContainerVolume = (ContainerLenght * ContainerWidth * ContainerHeight);
CargoHoldVolume = (ShipLenght * ShipWidth * ShipHeight);
ShipWeight = (CargoHoldVolume/ContainerVolume)* ContainerWeight;
JOptionPane.showMessageDialog(null,"Maximum numbers of containers on the ship is " + (CargoHoldVolume/ContainerVolume),"Cargo Hold details", JOptionPane.INFORMATION_MESSAGE);
if (ShipWeight > MaxWeight)
{
JOptionPane.showMessageDialog(null,"The ship is overweight", null, JOptionPane.ERROR_MESSAGE);
}
else if (ShipWeight == MaxWeight)
{
JOptionPane.showMessageDialog(null,"Weight of Cargo ship is legal", null, JOptionPane.WARNING_MESSAGE, null);
}
}
}
Wychodzi mi owy error:
http://scr.hu/1x9c/kkta8
Problem w tym, że textfile znajduje się w tym samym folderze co projekt i ma prawidłową nazwę. Jakieś rady?