Results 1 to 2 of 2
- 03-25-2011, 04:34 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
Learning Generics in Java. Need Assistance
I am working on a project that can help me get more familiar with using generic classes in Java.
I am trying to send different objects to class StackTPT so that they can be put into arrays using the putinarray() method.
But I am receiving the following errors:
putinarray() in StackTPT cannot be applied to (StackTPT<Bed>)
putinarray() in StackTPT cannot be applied to (StackTPT<Table>)
-
-(and so on for all five different types objects I try to use the putinarray() method on.)
cannot find symbol constructor Table(java.lang.String,java.lang.String,java.lang. String,java.lang.String)
cannot find symbol constructor Desk(java.lang.String,java.lang.String,java.lang.S tring)
cannot find symbol constructor Bookshelf(java.lang.String,java.lang.String,java.l ang.String,java.lang.String,java.lang.String)
-------------------------------------------------------------------------
The code is as follows:
Since I am still unfamiliar with generics, I am still unsure of what direction I should go to remedy this.Java Code:import java.io.*; import java.util.*; import java.lang.*; public class FurnishTPT { static Stack beds = new Stack(); static Stack tables = new Stack(); static Stack chairs = new Stack(); static Stack desks = new Stack(); static Stack bookshelves = new Stack(); static Bed [] bedarray = new Bed [50]; static Table [] tablearray = new Table [50]; static Chair [] chairarray = new Chair [50]; static Desk [] deskarray = new Desk [50]; static Bookshelf [] bookshelfarray = new Bookshelf [50]; static int a=0; static int x=0; public static void main(String[]Args) throws IOException, FileNotFoundException{ boolean halt = false; String [] parsefurniturearray = new String [] {"Bed", "Table", "Chair", "Desk", "Bookshelf"}; int y = 0; while (halt==false){ File furniture = new File("Furniture.dat"); Scanner scan = new Scanner(furniture); while (scan.hasNextLine()){ if(scan.next()==parsefurniturearray[x]){ if(x==0){ Bed bedobject = new Bed(scan.next(),scan.next()); StackTPT<Bed> tempbed = new StackTPT(bedobject); StackTPT.putinarray(tempbed); } else if(x==1){ Table tableobject = new Table(scan.next(),scan.next(),scan.next(),scan.next()); StackTPT<Table> temptable = new StackTPT(tableobject); StackTPT.putinarray(temptable); } else if(x==2){ Chair chairobject = new Chair(scan.next(),scan.next()); StackTPT<Chair> tempchair = new StackTPT(chairobject); StackTPT.putinarray(tempchair); } else if(x==3){ Desk deskobject = new Desk(scan.next(),scan.next(),scan.next()); StackTPT<Desk> tempdesk = new StackTPT(deskobject); StackTPT.putinarray(tempdesk); } else { Bookshelf bookshelfobject = new Bookshelf(scan.next(),scan.next(),scan.next(),scan.next(),scan.next()); StackTPT<Bookshelf> tempbookshelf = new StackTPT(bookshelfobject); StackTPT.putinarray(tempbookshelf); } } else{scan.nextLine();} } if(x<5){x++; a=0; scan.close();} else{halt=true; scan.close();} } } } class StackTPT <E> extends FurnishTPT { private E stackobj; public StackTPT(){ stackobj = null;} public StackTPT(E one){ stackobj = one; } public void putinarray () { if (x==0){ bedarray [a] = stackobj; a++; } else if(x==1){ tablearray [a] = stackobj; a++; } else if(x==2){ chairarray [a] = stackobj; a++; } else if(x==3){ deskarray [a] = stackobj; a++; } else if(x==4){ bookshelfarray [a] = stackobj; a++; } } public void putinstack(){ } // method to place in an array // method to take array and put it into a stack } class Bed extends FurnishTPT { private String size; private String color; Bed(){ } Bed(String one, String two){ size=one; color=two; } public String getcolor(){return (color);} public String bedsize(){return (size);} } class Table extends FurnishTPT { private int height; private int width; private int depth; private String color; Table(){ } Table(int one, int two, int three, String four){ height=one; width=two; depth=three; color=four; } public String getcolor(){return (color);} public String tableheight(){return Integer.toString(height);} public String tablewidth(){return Integer.toString(width);} public String tabledepth(){return Integer.toString(depth);} } class Chair extends FurnishTPT { private String style; private String color; Chair(){ } Chair(String one, String two){ style=one; color=two; } public String getcolor(){return (color);} public String chairstyle(){return (style);} } class Desk extends FurnishTPT { private String style; private String color; private int numberdrawers; private int height; Desk(){ } Desk(String one, String two, int three, int four){ style=one; color=two; numberdrawers=three; height=four; } public String getcolor(){return (color);} public String deskstyle(){return (style);} public String deskdrawers(){return Integer.toString(numberdrawers);} public String deskheight(){return Integer.toString(height);} } class Bookshelf extends FurnishTPT { private int height; private int width; private int depth; private int numbershelves; private String color; Bookshelf(){ } Bookshelf(int one, int two, int three, int four, String five){ height=one; width=two; depth=three; numbershelves=four; color=five; } public String getcolor(){return (color);} public String bookshelfheight(){return Integer.toString(height);} public String bookshelfwidth(){return Integer.toString(width);} public String bookshelfdepth(){return Integer.toString(depth);} public String bookshelfnumbershelves(){return Integer.toString(numbershelves);} }
Any help would be greatly appreciated.
Thanks!
Codex
- 03-25-2011, 05:00 PM #2
it will be the more useful if you explain that you want make it. Because it's the code which you showed it's a very hardly for reading.
Skype: petrarsentev
http://TrackStudio.com
Similar Threads
-
Java Generics assistance and confusion
By sideswipe091976 in forum Advanced JavaReplies: 9Last Post: 03-30-2011, 08:24 AM -
Learning Java...
By Learning Java in forum New To JavaReplies: 2Last Post: 09-24-2010, 09:03 PM -
Pls Help me in learning Java
By SimranK in forum New To JavaReplies: 6Last Post: 06-24-2010, 07:44 PM -
Learning Java
By jjoshua2 in forum New To JavaReplies: 2Last Post: 12-20-2008, 02:46 AM -
Java N00B - Remote Assistance Invitations
By victimist in forum Java AppletsReplies: 6Last Post: 10-25-2008, 01:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks