java - How to use ArrayList while adding something to another Class's constructor ? -
i'm try create 1 simple reservation system, we'll read file, we'll add train, bus, etc., we'll writer output.
import java.io.*; import java.util.*; public class company { private static arraylist<bus> bus = new arraylist<bus>(); static int buscount = 0, traincount = 0; public static void main (string[] args) throws ioexception { fileparser(); } public company() { } public static void fileparser() { try { file file = new file(); //i fill later file file2 = new file(); // fill later fileinputstream fis = new fileinputstream(file); fileoutputstream fos = new fileoutputstream(file2); bufferedreader br = new bufferedreader(new inputstreamreader(fis)); bufferedwriter bw = new bufferedwriter(new outputstreamwriter(fos)); string line; while ((line = br.readline()) != null) { string[] splitted = line.split(","); if(splitted[0].equals("addbus")) { bus.add(buscount) = bus(splitted[0],splitted[1],splitted[2],splitted[3],splitted[4],splitted[5]); } } } catch (filenotfoundexception fnfe) { } catch (ioexception ioe) { } } }
i try read file line line. example 1 of line "addbus,78kl311,10,140,54" split line "," try add every pieces of array bus' class' constructor couldn't figured out.
my bus class ` public class bus extends vehicle{
private string command; private string busname; private string busplate; private string busage; private string busspeed; private string busseat; public bus(string command, string busname, string busplate, string busage, string busspeed, string busseat) { this.command = command; this.busname = busname; this.busplate = busplate; this.busage = busage; this.busspeed = busspeed; this.busseat = busseat; } public string getbusname() { return busname; } public void setbusname(string busname) { this.busname = busname; } public string getbusplate() { return busplate; } public void setbusplate(string busplate) { this.busplate = busplate; } public string getbusage() { return busage; } public void setbusage(string busage) { this.busage = busage; } public string getbusspeed() { return busspeed; } public void setbusspeed(string busspeed) { this.busspeed = busspeed; } public string getbusseat() { return busseat; } public void setbusseat(string busseat) { this.busseat = busseat; } public string getcommand() { return command; } public void setcommand(string command) { this.command = command; } }
can show me way solve problem?
thank you,
you missing keyword new
create new instance of class:
bus.add(new bus(...));
Comments
Post a Comment