I need some help with a small Java assignment I am doing.
When I compile the code i get 2 errors they are
invalid method declaration: return type required
public CreateRandomFile() LINE 87
^
cannot resolve symbol
new CreateRandomFile(); LINE 112
^
Any help is greatly appreciated
**********CODE BEGINS HERE ***********************
import javax.swing.*;
import java.io.*;
import BreezySwing.*;
public class RandomTest extends GBFrame
{
JLabel accLabel = addLabel("Account Number",1,1,1,1);
IntegerField accField = addIntegerField(0,1,2,1,1);
JLabel firstLabel = addLabel("First Name",2,1,1,1);
JTextField firstField = addTextField("",2,2,1,1);
JLabel lastLabel = addLabel("Last Name",3,1,1,1);
JTextField lastField = addTextField("",3,2,1,1);
JTextArea resultArea = addTextArea("",4,1,2,3);
JButton acceptButton = addButton("Accept",7,1,2,1);
JButton accessButton = addButton("Access",8,1,2,1);
JButton clearButton = addButton("Clear",9,1,2,1);
private RandomAccessFile file;
public void buttonClicked(JButton buttonObj)
{
if (buttonObj == acceptButton)
{
}
else
if (buttonObj == accessButton)
{
}
else
{
accField.setNumber(0);
resultArea.setText(""
firstField.setText(""
lastField.setText(""
}
}
//---------------------------------------------------------------
private void openFile()
{
FileOutputStream foStream = new FileOutputStream ("acc.dat"
ObjectOutputStream doStream = new ObjectOutputStream (foStream);
if ("acc.dat" == null || "acc.dat".equals("")
System.out.println("Invalid File Name"
else
{
try{
file = new RandomAccessFile ("acc.dat","rw"
}
catch (IOException e)
{
System.out.println("File does not exist or Invalid File Name"
}
}
}
//---------------------------------------------------------------
private Record getRecord()
{
Record record = new Record();
int accountNumber;
try{
accountNumber = Integer.parseInt(accField.getText());
if (accountNumber <1 || accountNumber >100)
{
System.out.println("Account doesn't exist"
return null;
}
file.seek((accountNumber -1)*Record.size());
record.read(file);
}
catch (NumberFormatException nfe)
{
System.out.println("Account does not exist"
System.out.println("Invalid Number Format"
}
catch (IOException io)
{
System.out.println("Error reading file"
}
return record;
}
//---------------------------------------------------------------
public CreateRandomFile() // <----- ERROR HERE
{
Record blank = new Record();
openFile();
try{
file = new RandomAccessFile("acc.dat", "rw"
for (int i=0;i<100;i++)
blank.write(file);
System.exit(0);
}
catch (IOException e )
{
System.out.println("File doesn't exist"
System.out.println("Invalid File Name"
System.exit(1);
}
}
//----------------------------------------------------------------
public static void main(String args[])
{
JFrame tpo = new RandomTest();
tpo.setTitle("Assignment 1"
tpo.setSize(200,330);
tpo.setVisible(true);
new CreateRandomFile(); // <--- ERROR HERE
}
}
When I compile the code i get 2 errors they are
invalid method declaration: return type required
public CreateRandomFile() LINE 87
^
cannot resolve symbol
new CreateRandomFile(); LINE 112
^
Any help is greatly appreciated
**********CODE BEGINS HERE ***********************
import javax.swing.*;
import java.io.*;
import BreezySwing.*;
public class RandomTest extends GBFrame
{
JLabel accLabel = addLabel("Account Number",1,1,1,1);
IntegerField accField = addIntegerField(0,1,2,1,1);
JLabel firstLabel = addLabel("First Name",2,1,1,1);
JTextField firstField = addTextField("",2,2,1,1);
JLabel lastLabel = addLabel("Last Name",3,1,1,1);
JTextField lastField = addTextField("",3,2,1,1);
JTextArea resultArea = addTextArea("",4,1,2,3);
JButton acceptButton = addButton("Accept",7,1,2,1);
JButton accessButton = addButton("Access",8,1,2,1);
JButton clearButton = addButton("Clear",9,1,2,1);
private RandomAccessFile file;
public void buttonClicked(JButton buttonObj)
{
if (buttonObj == acceptButton)
{
}
else
if (buttonObj == accessButton)
{
}
else
{
accField.setNumber(0);
resultArea.setText(""
firstField.setText(""
lastField.setText(""
}
}
//---------------------------------------------------------------
private void openFile()
{
FileOutputStream foStream = new FileOutputStream ("acc.dat"
ObjectOutputStream doStream = new ObjectOutputStream (foStream);
if ("acc.dat" == null || "acc.dat".equals("")
System.out.println("Invalid File Name"
else
{
try{
file = new RandomAccessFile ("acc.dat","rw"
}
catch (IOException e)
{
System.out.println("File does not exist or Invalid File Name"
}
}
}
//---------------------------------------------------------------
private Record getRecord()
{
Record record = new Record();
int accountNumber;
try{
accountNumber = Integer.parseInt(accField.getText());
if (accountNumber <1 || accountNumber >100)
{
System.out.println("Account doesn't exist"
return null;
}
file.seek((accountNumber -1)*Record.size());
record.read(file);
}
catch (NumberFormatException nfe)
{
System.out.println("Account does not exist"
System.out.println("Invalid Number Format"
}
catch (IOException io)
{
System.out.println("Error reading file"
}
return record;
}
//---------------------------------------------------------------
public CreateRandomFile() // <----- ERROR HERE
{
Record blank = new Record();
openFile();
try{
file = new RandomAccessFile("acc.dat", "rw"
for (int i=0;i<100;i++)
blank.write(file);
System.exit(0);
}
catch (IOException e )
{
System.out.println("File doesn't exist"
System.out.println("Invalid File Name"
System.exit(1);
}
}
//----------------------------------------------------------------
public static void main(String args[])
{
JFrame tpo = new RandomTest();
tpo.setTitle("Assignment 1"
tpo.setSize(200,330);
tpo.setVisible(true);
new CreateRandomFile(); // <--- ERROR HERE
}
}