Philip Burgwin

Greenhorn
+ Follow
since Mar 20, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Philip Burgwin

Well to be honest its my my first Java assignment. Ive got 2 months to do it but I know bugger all about Java @ moment.
The Java I/O is the main part of it really. If I can get Java file I/O working (just creating files on local hard drive/reading em back) then as I say the rest is just putting the I/O code into a Java user interface. I dont even have to send any files across net/intranet or anything - for the demo I need to give just on a standalone PC will do.
Im working thru the book 'core java 1.2 - Fundamentals' but nothing seems to work in chap12 (the one relavent for me!).
I figure everything needed is in the java.io class but Ive no idea were to begin and I cant find any SIMPLE java I/O examples similar to what I need on net anywhere.
Regards,
Phil.
22 years ago
Hi,
Could anybody please supply me (or let me know) the full .java source code to do the following:
Open up a simple text area window where the user is asked to type in there name. The user types there name in, clicks an 'ok' button and there name is then written to the file 'name.txt' on the local c:\.
Its for part of a coursework Im doing at college. I would be grateful if someone could let me know the code or even better email me the .java file(s). Im using Java Developement Kit Ver 1.1.8 (the 9mb one u get free from from javasoft).
Regards,
Phil,
HiOnMaiden@FreeNet.co.uk
22 years ago
Hi all,
Im not sure if Im in the correct catagory but I am certainly a beginner.
OK, here goes ... I need to use JAVA to simulate a kind of database - to simply write text/numeric data (say 'Joe', 'bloggs', 50) into a text file. Ive got the code below but, put simply, it doesnt work.
Errors I get: 1 saying 'package corejava not found in import' and 7 about 'class day not found'.
Any ideas (well could someone please tell me the correct source code)? Code Ive got (that gets the 8 errors):
import java.io.*;
import java.util.*;
import corejava.*;
public class DataFileTest
{static void writeData(Employee[] e, PrintWriter out)
throws IOException
{out.println(e.length);
int i;
for (i = 0; i < e.length; i++)
e[i].writeData(out);
}
static Employee[] readData(BufferedReader in)
throws IOException
{int n = Integer.parseInt(in.readLine());
Employee[] e = new Employee[n];
int i;
for (i = 0; i < n; i++)
{e[i] = new Employee();
e[i].readData(in);
}
return e;
}

public static void main(String[] args)
{Employee[] staff = new Employee[3];

staff[0] = new Employee("Harry Hacker", 35500,
new Day(1989,10,1));
staff[1] = new Employee("Carl Cracker", 75000,
new Day(1987,12,15));
staff[2] = new Employee("Tony Tester", 38000,
new Day(1990,3,15));
int i;
for (i = 0; i < staff.length; i++)
staff[i].raiseSalary(5.25);
try
{PrintWriter out = new PrintWriter(new
FileWriter("employee.dat"));
writeData(staff, out);
out.close();
}
catch(IOException e)
{System.out.print("error: " + e);
System.exit(1);
}
try
{BufferedReader in = new BufferedReader(new
FileReader("employee.dat"));
Employee[] e = readData(in);
for (i = 0; i < e.length; i++) e[i].print();
in.close();
}
catch(IOException e)
{System.out.print("Error: " + e);
System.exit(1);
}
}
}
class Employee
{public Employee(String n, double s, Day d)
{name = n;
salary = s;
hireDay = d;
}
public Employee() {}
public void print()
{System.out.println(name + " " + salary
+ " " + hireYear());
}
public void raiseSalary(double byPercent)
{salary *= 1 + byPercent / 100;
}
public int hireYear()
{return hireDay.getYear();
}
public void witeData(PrintWriter out) throws IOException
{out.println(name + "|"
+ salary + "|"
+ hireDay.getYear() + "|"
+ hireDay.getMonth() + "|"
+ hireDay.getDay());
}
public void readData(BufferedReader in) throws IOException
{String s = in.readLine();
StringTokenizer t = new StringTokenizer(s, "|");
name = t.nextToken();
salary = Double.parseDouble(t.nextToken());
int y = Integer.parseInt(t.nextToken());
int m = Integer.parseInt(t.nextToken());
int d = Integer.parseInt(t.nextToken());
hireDay = new Day(y, m, d);
}
private String name;
private double salary;
private Day hireDay;
}
23 years ago