Help with class

hello, I am having trouble with the following code I get the following errors. I have no idea how to fix this, if anyone could help I would greatly appriciate it.
StudentAddress.java:12: StudentAddress(java.lang.String) is already defined in StudentAddress
public StudentAddress(String city){
^
StudentAddress.java:16: StudentAddress(java.lang.String) is already defined in StudentAddress
public StudentAddress(String state){
^
StudentAddress.java:24: StudentAddress(int) is already defined in StudentAddress
public StudentAddress(int zipCode){
//Data represents GPA/hours
public class StudentAddress {
     //Declare Variables
     private String streetAddress, city, state;
     private int addressNumber, zipCode;
     public StudentAddress(String streetAddress){
          this.streetAddress = streetAddress;
     public StudentAddress(String city){
          this.city = city;     
     public StudentAddress(String state){
          this.state = state;
     public StudentAddress(int addressNumber){
          this.addressNumber = addressNumber;
     public StudentAddress(int zipCode){
          this.zipCode = zipCode;
          //this will return a string representation of this object so that
          //we can print it to the console easily
     public String toString(){
          return streetAddress + "\n" + "#" +addressNumber +"\n" + city + "," + state + zipCode;
}

when you create an instance of StudentAddress class, you will either pass a String or an int irrespective of whether it is city, state, streetAddress, addressNumber or zipCode. Suppose you create an instance of StudentAddress by passing a string, which constructor it will invoke? The JVM will get confused on which constructor to invoke since it has three constructors with the same String as the parameter type. What you have written is not 'Constructor Overloading'. Read some tutorial about constructors and constructor overloading and try coding.
You can write this class as follows, Assuming that it will fulfill your requirement
public class StudentAddress {
     //Declare Variables
     private String streetAddress, city, state;
     private int addressNumber, zipCode;
     public StudentAddress(String streetAddress,String city,String state,int addressNumber,int zipCode){
          this.streetAddress = streetAddress;
                                this.city = city;
                                this.state = state;
                                this.addressNumber = addressNumber;
                                this.zipCode = zipCode;
                              //this will return a string representation of this object so that
          //we can print it to the console easily
     public String toString(){
          return streetAddress + "\n" + "#" +addressNumber +"\n" + city + "," + state + zipCode;
}you can also try this website
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter03/constructors.html
All the best. Have a Nice Day.

Similar Messages

  • Need help with classes

    I''ve just started out with Java and I need help with my latest program.
    The program looks someting like this:
    public class MultiServer {
       public static void main(Straing[] args) {
          ServerGUI GUI = new ServerGUI();
    public class ServerGUI extends JFrame implements ActionListener {
       private TextArea textArea;
       public ServerGUI() {
          //setting up the JFrame and stuff like that
       public void actionPerformed(ActionEvent event) {
          if(button == addButton) {
             addGUI add = new addGUI();
    public class addGUI extends JFrame implements ActionListener {
        private TextField t1 = new TextField(25);
        public addGUI() {
          //setting up the JFrame and stuff like that
       public void actionPerformed(ActionEvent event) {
          if(button == printButton) {
             textArea.append("THIS DOES NOT WORK!");
    }   The problem is as follows: I want to be able to write text in the textArea in class ServerGUI from the class addGUI, but I can't. I hope you understand what I mean.
    How is this fixed? Please help me!

    public void actionPerformed(ActionEvent event) {
          if(button == addButton) {
             addGUI add = new addGUI(textArea);
    public class addGUI extends JFrame implements ActionListener {
        private TextArea textArea;
        public addGUI(TextArea textArea) {
            this.textArea = textArea;
        }/Kaj

  • Need help with class design

    I want to design and use one or more classes for a particular project I am working on.
    I need some advice hopefully from someone who has experience in this area. Basically,
    for this particular problem I have two database tables. I want the first class to
    represent the first database table and the second class to represent the second
    database table. An object of the first class will be created first, and then if certain
    criteria are met then an object of the second class will be created.
    Question:
    Should I use classical inheritance and let the first class inherit from the second class?
    Or should I use the containment delegation model and embed an object of the second
    class in the first class?
    ----Tables------
    For example, my first table ET_UserData looks something like this:
    ET_UserData
    (PK)UserName
    Password
    FirstName
    LastName
    My second table ET_DetailedUserData looks like this
    ET_DetailedUserData
    (FK)UserName
    WorkAddress
    WorkPhoneNumber
    CityWhereEmployed
    SocialSecurityNumber
    City
    State
    StreetAdress
    PrimaryTelephoneNumber
    AlternatePhoneNumber
    HasRegistered
    RegistrationDate
    RegistrationTime
    CreditCardNumber
    NameOfPrimaryContact
    DateOfBirth
    Weight
    EyeColor
    Height
    Member
    Here is are some pseudo classes for the two classes.
    Class UserData
    string UserName
    string FirstName
    string LastName
    Class DetailedUserData /* For a classical approach, sub class off of class UserData */
    /* UserData ThisUser --> Containment delegation model */
    string (FK)UserName
    string WorkAddress
    string WorkPhoneNumber
    string CityWhereEmployed
    string SocialSecurityNumber
    string City
    string State
    string StreetAdress
    Int PrimaryTelephoneNumber
    Int AlternatePhoneNumber
    Bool HasRegistered
    Int RegistrationDate
    Int RegistrationTime
    Int CreditCardNumber
    String NameOfPrimaryContact
    Int DateOfBirth
    Int Weight
    Int EyeColor
    Int Height
    bool Member
    }

    Thank you for your help. If you can continue to help me I would appreciate it.
    I and another developer did the database design. Pretty solid design. Plus we have all of the requirements
    which are very good too.
    Originally I wanted just one table to contain all of the data associated with a user. Instead of ET_UserData and ET_Detailed user data I wanted just one table. But I decided to break this table up into the two tables for the following reason.
    1.) This is a web application where each user logs into a web form. At a minimum, in order to use the website the session associated with each user needs the UserName, Password, First and last name.
    This is the data in the first table.
    If they choose to do more specialized functions on this website, then they will need all of the information (Attributes) that are located in the second table. In general 40% of the time all users will need information located in the second table.
    My reasoning for breaking the table into two seperate tables is that I wanted to minimize the amount of data involved in a result set, created from the sql query. The math tells me that 60% of the time most of the data in the result set will not be used.
    2.) If I create one class to represent all of the data/attributes in both tables, then my reasoning is that their will be alot of overhead in the single class because 60% of the time, a majority of the attributes are not needed and used.
    I would deeply appreciate your help with this. You seem to have great insight and advice. Please help me as I increase the duke dollars Sir.

  • Need help with class info and cannot find symbol error.

    I having problems with a cannot find symbol error. I cant seem to figure it out.
    I have about 12 of them in a program I am trying to do. I was wondering if anyone could help me out?
    Here is some code I am working on:
    // This will test the invoice class application.
    // This program involves a hardware store's invoice.
    //import java.util.*;
    public class InvoiceTest
         public static void main( String args[] )
         Invoice invoice1 = new Invoice( "1234", "Hammer", 2, 14.95 );
    // display invoice1
         System.out.println("Original invoice information" );
         System.out.println("Part number: ", invoice1.getPartNumber() );
         System.out.println("Description: ", invoice1.getPartDescription() );
         System.out.println("Quantity: ", invoice1.getQuantity() );
         System.out.println("Price: ", invoice1.getPricePerItem() );
         System.out.println("Invoice amount: ", invoice1.getInvoiceAmount() );
    // change invoice1's data
         invoice1.setPartNumber( "001234" );
         invoice1.setPartDescription( "Yellow Hammer" );
         invoice1.setQuantity( 3 );
         invoice1.setPricePerItem( 19.49 );
    // display invoice1 with new data
         System.out.println("Updated invoice information" );
         System.out.println("Part number: ", invoice1.getPartNumber() );
         System.out.println("Description: ", invoice1.getPartDescription() );
         System.out.println("Quantity: ", invoice1.getQuantity() );
         System.out.println("Price: ", invoice1.getPricePerItem() );
         System.out.println("Invoice amount: ", invoice1.getInvoiceAmount() );
    and that uses this class file:
    public class Invoice
    private String partNumber;
    private String partDescription;
    private int quantityPurchased;
    private double pricePerItem;
         public Invoice( String ID, String desc, int purchased, double price )
              partNumber = ID;
         partDescription = desc;
         if ( purchased >= 0 )
         quantityPurchased = purchased;
         if ( price > 0 )
         pricePerItem = price;
    public double getInvoiceAmount()
         return quantityPurchased * pricePerItem;
    public void setPartNumber( String newNumber )
         partNumber = newNumber;
         System.out.println(partDescription+" has changed to part "+newNumber);
    public String getPartNumber()
         return partNumber;
    public void setDescription( String newDescription )
         System.out.printf("%s now refers to %s, not %s.\n",
    partNumber, newDescription, partDescription);
         partDescription = newDescription;
    public String getDescription()
         return partDescription;
    public void setPricePerItem( double newPrice )
         if ( newPrice > 0 )
    pricePerItem = newPrice;
    public double getPricePerItem()
    return pricePerItem;
    Any tips for helping me out?

    System.out.println("Part number:
    "+invoice1.getPartNumber;
    The + sign will concatenate invoice1.getPartNumber()
    after "Part number: " forming only one String.I added the plus sign and it gives me more errors:
    C:\>javac InvoiceTest.java
    InvoiceTest.java:16: operator + cannot be applied to java.lang.String
            System.out.println("Part number: ",   + invoice1.getPartNumber() );
                                                  ^
    InvoiceTest.java:17: cannot find symbol
    symbol  : method getPartDescription()
    location: class Invoice
            System.out.println("Description: ", + invoice1.getPartDescription() );
                                                          ^
    InvoiceTest.java:17: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Description: ", + invoice1.getPartDescription() );
                      ^
    InvoiceTest.java:18: cannot find symbol
    symbol  : method getQuantity()
    location: class Invoice
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                                                       ^
    InvoiceTest.java:18: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                      ^
    InvoiceTest.java:19: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Price: ", + invoice1.getPricePerItem() );
                      ^
    InvoiceTest.java:20: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Invoice amount: ", + invoice1.getInvoiceAmount() );
                      ^
    InvoiceTest.java:24: cannot find symbol
    symbol  : method setPartDescription(java.lang.String)
    location: class Invoice
            invoice1.setPartDescription( "Yellow Hammer" );
                    ^
    InvoiceTest.java:25: cannot find symbol
    symbol  : method setQuantity(int)
    location: class Invoice
            invoice1.setQuantity( 3 );
                    ^
    InvoiceTest.java:30: operator + cannot be applied to java.lang.String
            System.out.println("Part number: ", + invoice1.getPartNumber() );
                                                ^
    InvoiceTest.java:31: cannot find symbol
    symbol  : method getPartDescription()
    location: class Invoice
            System.out.println("Description: ", + invoice1.getPartDescription() );
                                                          ^
    InvoiceTest.java:31: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Description: ", + invoice1.getPartDescription() );
                      ^
    InvoiceTest.java:32: cannot find symbol
    symbol  : method getQuantity()
    location: class Invoice
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                                                       ^
    InvoiceTest.java:32: cannot find symbol
    symbol  : method println(java.lang.String,int)
    location: class java.io.PrintStream
            System.out.println("Quantity: ", + invoice1.getQuantity() );
                      ^
    InvoiceTest.java:33: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Price: ", + invoice1.getPricePerItem() );
                      ^
    InvoiceTest.java:34: cannot find symbol
    symbol  : method println(java.lang.String,double)
    location: class java.io.PrintStream
            System.out.println("Invoice amount: ", + invoice1.getInvoiceAmount() );
                      ^
    16 errors

  • Help with Class-map configuration - ZBFW

    Hello,
    I need some clarification regarding the class-map configuration in a ZBFW. I need to allow https,http,ftp & rdp traffic from Internet to few of the servers inside our LAN. So I put the below configuration to accomplish the task (example shows class-map for only https protocol) :
    a.)
    class-map type inspect match-all HTTPS-ACCESS
    match protocol https
    match access-group name HTTPS-SERVER-ACCESS
    ip access-list extended HTTPS-SERVER-ACCESS
    permit tcp any host 172.17.0.55 eq 443
    permit tcp any host 172.17.0.56 eq 443
    permit tcp any host 172.17.0.36 eq 443
    permit tcp any host 172.17.0.45 eq 443
    permit tcp any host 172.17.0.60 eq 443
    Where 55,56,36,45,60 are the servers inside the LAN (12 more servers are there) that need to be accessed via https,http,ftp & rdp from Internet.
    Is it a correct approach? or do I need to change my configuation so that I have to match ACL with my class-map like below:
    b.)
    ip access-list extended OUTSIDE-TO-INSIDE-ACL
    permit tcp any host 172.17.0.55 eq 443
    permit tcp any host 172.17.0.55 eq www
    permit tcp any host 172.17.0.55 eq 21
    permit tcp any host 172.17.0.55 eq 3389
    permit tcp any host 172.17.0.56 eq 443
    permit tcp any host 172.17.0.56 eq www
    permit tcp any host 172.17.0.56 eq 21
    permit tcp any host 172.17.0.56 eq 3389
    permit tcp any host 172.17.0.36 eq 443
    permit tcp any host 172.17.0.36 eq www
    permit tcp any host 172.17.0.36 eq 21
    permit tcp any host 172.17.0.36 eq 3389
    permit tcp any host 172.17.0.45 eq 443
    permit tcp any host 172.17.0.45 eq www
    permit tcp any host 172.17.0.45 eq 21
    permit tcp any host 172.17.0.45 eq 3389
    class-map type inspect match-all OUT-IN-CLASS
    match access-group name OUTSIDE-TO-INSIDE-ACL
    Which one is the correct approach when we consider the performance of the firewall ? Please help me.
    Regards,
    Yadhu

    Hey
    I do not agree with Varun, I think the first approach is the best one.
    Why? Because when you issue the "match protocol ..." you are usig NBAR wich is an application inspection software, which means that https or whatever protocol is inspected at layer 7, not layer 3 and 4 which the seconds approach does (IP and port-number).
    Lets say you use the second approach and an attacker uses some malicious protocol that runs over port 443 or whatever (a port that you opened).  That attack would be successfull because all you say, you are going to IP-address 172.17.0.56 over port 443 so go ahead.
    But if you are using NBAR, this would not work because NBAR will look at layer 7, inside the protocol itself and look if this really is HTTPS (or whatever protocol).
    That's my two cents. Hope it helped!

  • Need help with class I'm trying to write for school

    Hi,I'm taking my first Java class, and we're learning how to write classes. I've got MOST of the program and class to work, but I'm still having trouble with it.
    In the class I wrote, if I delete the "getWindTempF(strAlt)" the program runs fine, other than not doing the conversion to Fahrenheit. So, I'm guessing that there's a problem with my getWindTempF method. However, it is almost exactly a duplicate of my getWindTempC method, so I can't figure out what I'm doing wrong. The errors I get when I keep the "getWindTempF(strAlt)" in the prtWindInfo method are:
    java.lang.NumberFormatException: For input string: " "
         at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
         at java.lang.Integer.parseInt(Integer.java:426)
         at java.lang.Integer.parseInt(Integer.java:476)
         at NWSFD.getWindTempF(NWSFD.java:94)
         at NWSFD.prtWindInfo(NWSFD.java:162)
         at a19004.main(a19004.java:30)
    Exception in thread "main"
    ----jGRASP wedge2: exit code for process is 1.
    Again, the program and class work perfectly except for the getWindTempF. Any ideas would be greatly appreciated, and sorry for such a long post
    Here is the main program:
    import cs1.Keyboard;
    import java.text.NumberFormat;
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    import java.util.Date;
    public class a19004
         // Instantiates the windsAloft object by using the NWSFD class
         public static void main (String[] args)
              final String FAA_FD="SAN 1405 2908+26 2911+19 2809+11 1307-09 0308-20 " +
              "032433 012543 352853";
              NWSFD windsAloft = new NWSFD(FAA_FD);     //Instantiate the NWSFD object
              System.out.println ("Winds Aloft");
              System.out.println ("as of " + windsAloft.getDate());
              System.out.println ("");
              System.out.println ("STA Alt Dir Speed TempC TempF");
              System.out.println ("");
              System.out.println (windsAloft.prtWindInfo("03"));
              System.out.println (windsAloft.prtWindInfo("06"));
              System.out.println (windsAloft.prtWindInfo("09"));
              System.out.println (windsAloft.prtWindInfo("12"));
              System.out.println (windsAloft.prtWindInfo("18"));
              System.out.println (windsAloft.prtWindInfo("24"));
              System.out.println (windsAloft.prtWindInfo("30"));
              System.out.println (windsAloft.prtWindInfo("34"));
              System.out.println (windsAloft.prtWindInfo("39"));
    And for the sake of brevity, just a part of the NWSFD class:
    import java.text.*;
    import java.util.Date;
    public class NWSFD
         // Set up variables
         private String strWea;
         // 3.a. Constructor
         public NWSFD (String strVar)
              strWea=strVar + " ";
         // 3.d.
         public String getWindTempC (String strAlt)
              String strVar;
              strVar = strWea.substring(getPos(strAlt) + 4, getPos(strAlt) + 7);
              if (strAlt.equals("03"))
                   strVar = strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 5);
              if (strAlt.equals("30"))
                   strVar = "-" + strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 6);
              if (strAlt.equals("34"))
                   strVar = "-" + strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 6);
              if (strAlt.equals("39"))
                   strVar = "-" + strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 6);
              if (strVar.equals(" "))
                   strVar = "N/A";
              return strVar;
         // 3.ed.
         public String getWindTempF (String strAlt)
              String strVar;
              String strFar;
              int intRet;
              int intFar;
              strFar = strWea.substring(getPos(strAlt) + 5, getPos(strAlt) + 7);
              if (strAlt.equals("03"))
                   strFar = strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 5);
              if (strAlt.equals("30"))
                   strFar = "-" + strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 6);
              if (strAlt.equals("34"))
                   strFar = "-" + strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 6);
              if (strAlt.equals("39"))
                   strFar = "-" + strWea.substring(getPos(strAlt) +4, getPos(strAlt) + 6);
              if (strFar.equals(" "))
                   strVar = "N/A";
              intRet = Integer.parseInt(strFar);
              intFar = intRet * (9/5) + 32;
              strVar = Integer.toString(intRet++);
              return strVar;
         // 3.h.
         public String prtWindInfo (String strAlt)
              String strRet;
              strRet = strWea.substring(0,3) + " " + strAlt + "000" + " " +
                   getWindDir(strAlt) + " " + getWindSpeed(strAlt) + " " +
                   getWindTempC(strAlt) + "C " + getWindTempF(strAlt) + "F";
              return strRet;
    }

    Thank you for the reply, soni29. here is the code:
    public int getPos(String strAlt)
              int intAlt;
              int intRet;
              intAlt = Integer.parseInt(strAlt);
              switch (intAlt)
                   case 3:
                        intRet = 4;
                        break;
                   case 6:
                        intRet = 9;
                        break;
                   case 9:
                        intRet = 17;
                        break;
                   case 12:
                        intRet = 25;
                        break;
                   case 18:
                        intRet = 33;
                        break;
                   case 24:
                        intRet = 41;
                        break;
                   case 30:
                        intRet = 49;
                        break;
                   case 34:
                        intRet = 56;
                        break;
                   default:
                        intRet = 63;
              } //     Close switch
              return intRet;
    However, I really don't think there's a problem with any of the coding there. The only times I have problems with the program is when I'm trying to display the data from getWindTempF. If I omit that method, the program works perfectly. Basically, what the program is supposed to do, is hand a string (FAA_FD) to the NWSFD class, which then extracts data from it. Thank you again for the help...any other advice?

  • Help with Classes, Objects and their relationship.

    Alright, I've got this assignment from a computer science class that won't stop annoying me and I need some help. This is the complete assignment: http://zebra0.com/Tarraga/CS103/Project4.php
    What I'm having issues with is the course specifications. It says:
    ? Create a course class. It will contain the course name, 5 Student objects, the number of Students, etc. It will contain an addStudent(), printRoll() and average() methods. You may add methods as needed. The average method computes the average of all students test score averages.
    I'm not sure what my instructor means by 5 student objects. I'm assuming that addStudent() would create a new student() object (from the class which I've already created here: http://zebra0.com/Tarraga/CS103/studentP4.php) and printRoll() will print the existing objects, average() I think I know.
    So...wth am I supposed to create 5 student objects for? Or what are they referring to? I'd assume that the student objects are created only when the user inputs the student data, not internally.
    My question is what I'm assuming to be extremely newb-ish, and to be honest I am a complete newbie, but if anyone can help please do so.
    Edit: Another question I had regarded my student class would be, do I need to write getters/setters for every value in there? My instructor wouldn't stop raving about how we need getters/setters, but at this point I'm not exactly sure what they do.

    to didittoday:
    You could say that, yes. But honestly...I've been paying plenty of attention. What I've learned so far about an object in Java is the following:
    An object in programming is like an object in real life. It makes up the program. Just like a wheel is part(object) of a card, an object is part of the program.
    That's what my teacher has taught me, with pictures even. I've written about two GUI and one non GUI projects so far that I had to look to the book to actually finish. And that's her general answer to all our questions, "read the book!" She doesn't ever take time from showing us her precious powerpoints to actually teach us. And not once has she actually given us examples of coding. She instead directs us to the programs in our book which may or may not be of relevance.
    And all the tutors who could actually help me aren't on campus. If you'd like to redirect me to a link that may hold useful (and RELEVANT) information, please do so.
    Also: I do understand that a student object would hold student information (I.E.:
    public student (String firstname, String lastname, double score1, double score2, double score3, double score4)but I don't understand why 5 student objects should be created in the other class...is it that they have to be initialized and then once the user inputs the information, they are updated? I'm grasping at straws here.
    Edited by: Valkyrio on Mar 5, 2008 3:28 PM

  • Help with class in applet

    So im just starting java, about 12 weeks in.
    So in my class we are getting started with objects. What i want to do is create a class called car, and have it create a new car and draw images loaded, and then have the tires rotate, there are 2 images,
    the car base and the tires.
    I know how to display images in applets, but i dont know how to define the images in the objects class and then draw them from the class.

    I get errors with this code from my car class
    import java.applet.*;
    public class car extends Applet{
          * @param args
         private String model;
         private int passangers;
         private double gas,speed;
         private Image tire;
         private MediaTracker tr;
         tr = new MediaTracker(this);
         tire = getImage(getCodeBase(), "tire.png");
         tr.addImage(tire,0);
         public car(String id, int pass, double tank)
              model=id;
              passangers=pass;
              gas=tank;
         public car()
              model="";
              passangers=0;
              gas=0;
         }I get errors on these lines
         private Image tire;
         private MediaTracker tr;
         tr = new MediaTracker(this);
         tire = getImage(getCodeBase(), "tire.png");
         tr.addImage(tire,0);errors
    Severity and Description     Path     Resource     Location     Creation Time     Id
    Image cannot be resolved to a type     Car Game     car.java     line 13     1197077768237     1745
    MediaTracker cannot be resolved to a type     Car Game     car.java     line 14     1197077768238     1746
    Return type for the method is missing     Car Game     car.java     line 16     1197077768239     1750
    Syntax error on token ";", { expected after this token     Car Game     car.java     line 14     1197077768238     1747
    Syntax error on token "(", delete this token     Car Game     car.java     line 17     1197077768239     1752
    Syntax error on token "0", invalid FormalParameter     Car Game     car.java     line 17     1197077768239     1753
    Syntax error on token(s), misplaced construct(s)     Car Game     car.java     line 15     1197077768238     1748
    Syntax error on token(s), misplaced construct(s)     Car Game     car.java     line 16     1197077768239     1749
    Syntax error on tokens, delete these tokens     Car Game     car.java     line 16     1197077768239     1751
    The serializable class car does not declare a static final serialVersionUID field of type long     Car Game     car.java     line 4     1197077768237     1744
    The serializable class main does not declare a static final serialVersionUID field of type long     Applet     main.java     line 5     1196990860997     1682
    The serializable class main does not declare a static final serialVersionUID field of type long     Car Game     main.java     line 5     1197077768196     1743
    The serializable class ShowImage does not declare a static final serialVersionUID field of type long     Display JPEG/src     ShowImage.java     line 4     1196488911896     1393Edited by: jasonpeinko on Dec 7, 2007 5:42 PM

  • Need help with classes in Applets and drawing buildings.

    I'm trying to create an Applet that draws a starfield (I got that right) and then searches for any parameters in the Applet tag. The Applet then draws as many buldings as there are parameters in the Applet tag, and uses the number in the parameter as the height. I have it working OK, but it won't draw the buildings. Here is me code:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    public class Skyline extends Applet {
    public void init() {
    setBackground(Color.black);
    public void paint(Graphics g) {
    Graphics2D pen = (Graphics2D) g;
    Random generator = new Random();
    Stars starField = new Stars();
    starField.drawStars(pen, getWidth(), getHeight());
    int n = 1;
    String param = null;
    while((param = getParameter("param" + n)) != null) {
    n++;
    int startX = 0;
    int startY = getHeight();
    int height = 0;
    int width = getWidth() / (n + 2);
    Building structure = new Building();
    structure.drawBuilding(pen, height, width, startX, startY, n);
    class Stars {
    public void drawStars(Graphics2D pen, int Width, int Height) {
    Random generator = new Random();
    int runs = 1;
    while (runs <= 1000) {
    int Xcord = generator.nextInt(Width - 3);
    int Ycord = generator.nextInt(Height - 3);
    Ellipse2D.Double star
    = new Ellipse2D.Double(Xcord, Ycord, 3, 3);
    pen.setColor(Color.white);
    pen.fill(star);
    runs++;
    class Building {
    public void drawBuilding(Graphics2D pen, int height, int width, int startX, int startY, int n) {
    Random generator = new Random();
    int n2 = 1;
    int runs = 1;
    String input = "";
    int red = generator.nextInt(100),
    green = generator.nextInt(100),
    blue = generator.nextInt(100);
    pen.setColor(new Color(red, green, blue));
    while (runs <= n) {
    input = getParameter("building" + n2);
    height = Integer.parseInt(input);
    height = startY - height;
    Rectangle building = new Rectangle(startX, startY, height, width);
    pen.fill(building);
    startY = startY + width;
    n2++;
    runs++;
    Can anyone help me?

    That didn't work, so I looked at the code again and found some errors. I decided to rewrite it, here is the updated code...
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    public class Skyline extends Applet {
    public void init() {
    setBackground(Color.black);
    public void paint(Graphics g) {
    Graphics2D pen = (Graphics2D) g;
    Random generator = new Random();
    Stars starField = new Stars();
    starField.drawStars(pen, getWidth(), getHeight());
    Building structure = new Building();
    structure.drawBuilding(pen);
    class Stars {
    public void drawStars(Graphics2D pen, int Width, int Height) {
    Random generator = new Random();
    int runs = 1;
    while (runs <= 1000) {
    int Xcord = generator.nextInt(Width - 3);
    int Ycord = generator.nextInt(Height - 3);
    Ellipse2D.Double star
    = new Ellipse2D.Double(Xcord, Ycord, 3, 3);
    pen.setColor(Color.white);
    pen.fill(star);
    runs++;
    class Building {
    public void drawBuilding(Graphics2D pen) {
    Random generator = new Random();
    int n = 1;
    int n2 = 1;
    int runs = 1;
    String input = "";
    String param = "";
    while ((param = getParameter("building" + n)) != null) {
    n++;
    int height = getHeight();
    int width = getWidth();
    int startX = 0;
    int startY = height;
    int red = generator.nextInt(100),
    green = generator.nextInt(100),
    blue = generator.nextInt(100);
    pen.setColor(new Color(red, green, blue));
    while (runs <= n) {
    height = getHeight();
    input = getParameter("building" + n2);
    height = Integer.parseInt(input);
    height = startY - height;
    Rectangle building = new Rectangle(startY, startX, height, width);
    pen.fill(building);
    startX = startX + width;
    n2++;
    runs++;
    I can get it to draw one large black building, but that's it.

  • Where to start? Need help with classes

    My question involves those classes he wants us to make. I don't really get the concept of classes, so could someone tell me what they think he wants us to do? And try to explain it to me in terms I might be able to understand. Does that mean for us to use subclasses or use separate files for each class? Or could I do either? I'm so confused :(
    Assignment: Write a program that consists of the classes listed below.
    Player Class: The Player Class consists of at least two elements -- the player name and a list of scores for
    games. The score attribute is not used in Program #3 but will be needed in Program #4. Include in the
    class appropriate accessor and mutator methods for each element in the class. You may have other
    attributes if needed.
    Team Class: The Team class consists of at least 6 elements -- the name of the team and five players from
    the Player class. Include in the class appropriate accessor and mutator methods for each element in the
    class. You may have other attributes if needed.
    Course Syllabus Page 3
    Input3 class: The Input3 class is provided for you. The Input3 class supplies data for your program. The
    Input3 class has a public method called getNextString, which returns a string with the input for your
    program, one after the other. You must use this class to get the data for your program. See Input3.java on
    WebCT to understand the class construction.
    Your program should display the roster of each team in alphabetical order by last name.
    This is the Input3 that he gave us to work with if anyone needs to see it:
    public class Input3
         private String[] input = new String[40];
         private static int StringNum = -1;
         public static final int NUMBER_OF_TEAMS = 3;
         public static final int NUMBER_OF_PLAYERS = 5;
         public Input3()
              //The first six inputs will be for the first team
              input[0] = "LAKERS";
              input[1] = "Kobe Bryant";
              input[2] = "Derek Fisher";
              input[3] = "Shaquille O'Neal";     
              input[4] = "Karl Malone";
              input[5] = "Brian Cook";
              //The next six inputs will be for the second team
              input[6] = "MAVERICKS";
              input[7] = "Antoine Walker";
              input[8] = "Dirk Nowitzki";
              input[9] = "Tony Delk";
              input[10] = "Shawn Bradley";
              input[11] = "Travis Best";
              //The next six inputs will be for the third team
              input[12] = "KNICKS";
              input[13] = "Mike Sweetney";
              input[14] = "Allan Houston";
              input[15] = "Howard Eisley";
              input[16] = "Kurt Thomas";
              input[17] = "Shanon Anderson";
         //This method returns the strings one after the other.
         public String getNextString()
              StringNum++;
              return input[StringNum];
    }<br>
    <br>
    <br>
    Thanks

    You could put the classes in separate files, but it's not necessary. They wouldn't be called 'subclasses' here, as that word is specific to inheritance, which you don't need here. Here's an example of using multiple classes:
    public class MainClass {
        public static void main(String [] args) {
         OtherClass1 oc1 = new OtherClass1(3);
         OtherClass2 oc2 = new OtherClass2("hello");
         System.out.println("" + oc1.getInt());
         System.out.println(oc2.getString());
    class OtherClass1 {
        int someInt;
        public OtherClass1(int i) {
            someInt = i;
        public getInt() {
         return someInt;
    class OtherClass2 {
        String someString;
        public OtherClass2(String s) {
            someString = s;
        public getString() {
            return someString;
    }and like BDLH said above, it's preferred to put them in separate files. Just make sure the file name is EXACTLY the same as the class name, followed by .java

  • Need help with class object? Please somoen

    hey guys,
    It's been few days since i'm working on making a small bingogame program but i'm getting stuck frequantly.
    I've different classes, in the main class i'm asking the user to input number of players who would like to play then i'm asking the player's name and how many bingoCards each player wants.
    I'm stroing all that info in a BingoPlayer class's array object. But for some reason when i get out from the loop and try to retrive the info from that array it only gives me the last input entry (player's name & number of cards) at any index of the array.
    Can please someone tell me how i can store the given information for each player in that object array on different indices of the array?
    I'm providing the code where i've the problems:
    public class BingoGame
        public static BingoPlayer players[] = new BingoPlayer[5];
        public static void main() throws IOException {
            int numPlayers = 0;
            int numCards [] = new int [5];
            String name [] = new String[4];
            BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); //allows input
    // ask for the number players who wants to play
            System.out.print("Please enter the number of players in this game (2-5): ");
            numPlayers = Integer.parseInt(input.readLine());
    // make sure the entered value is within range
            while (numPlayers < 2 || numPlayers > 5) {
                System.out.println("Invalid number of players ");
                System.out.print("Please enter the number of players in this game (2-5): ");
                numPlayers = Integer.parseInt(input.readLine());
            System.out.println();
    //ask for the names and numebr of cards for entered number of players
    // and make sure the number of cards are within the range,
    //and assign the players that many cards using the BingoPlayer object 
            for (int i = 1; i <= numPlayers; i++) {
                System.out.print("Please enter name of player " + i + " : ");
                name[i] = input.readLine();
                System.out.println();
                System.out.print("Please enter the number of cards (1-5) for player " + i + " : ");
                numCards[i] = Integer.parseInt(input.readLine());
                while (numCards[i] < 1 || numCards[i] > 5) {
                    System.out.println("Invalid number of cards for the player " + i);
                    System.out.print("Please enter the number of cards (1-5) for player " + i + " : ");
                    numCards[i] = Integer.parseInt(input.readLine());
                System.out.println();
                players[i] = new BingoPlayer(name, numCards[i]);
    * here it only prints out the information for the last player, instead it should return the information for both of the player
    for (int k = 1; k <= numPlayers; k ++) {
    System.out.println(players[k]);
    //players[k].genCards();
    for example if i enter 2 players:
    Player1: name: Jami, number of cards 1
    Player2: name: Joey, number of cards 2
    in the last loop it just prints out :"Joey, 2" 2 times instead of printing out: "Jami, 1" & "Joey, 2"
    Please someone help! i really need to complete this within 2 days. Thanks in advance

    Without seeing BingoPlayer's implementation, all it
    would be would be a guess.
    My guess: The name and numCards members of that class
    are declared as static, so all instances share the
    same values.Thanks it worked, declaring them static was the main probelm..thank you very much

  • Need help with class inheritance

    I've got a class called jemAccount and i need to create a savings account class and a checking account class that inherit from it.
    Here is the jemAccount:
    public class jemAccount
    protected String myName;
    protected double myBalance;
    protected double[] withdrawls = new double [50];
    protected double[] deposits = new double [50];
    protected int withIndex = 0;
    protected int depIndex = 0;
    public jemAccount ()
    myBalance = 0;
    public jemAccount (String newName)
    myName = newName;
    myBalance = 0;
    public jemAccount (String newName, double newBal)
    myName = newName;
    myBalance = newBal;
    public void setName(String newName)
    myName = newName;
    public double balance()
    return myBalance;
    public void withdrawl (double amount)
    if (amount < 0)
    myBalance += amount;
    else
    myBalance -= amount;
    if (withIndex < 50)
    withdrawls[withIndex] = amount;
    withIndex++;
    public void deposit (double amount)
    if (amount > 0)
    myBalance += amount;
    if (depIndex < 50)
    deposits[depIndex] = amount;
    depIndex++;
    public void printAccount()
    System.out.println("Owner of account: " + myName);
    System.out.println("Balance of account: " + myBalance);
    System.out.println("Deposits: ");
    for (int i = 0; i < depIndex; i++)
    System.out.println(" " + deposits);
    System.out.println("");
    System.out.println("Withdrawls: ");
    for (int i = 0; i < withIndex; i++)
    System.out.println(" " + withdrawls[i]);
    System.out.println("");
    System.out.println("");
    } // end of class jemAccount
    Here are my requirements for the savings account class:
    � Call the class "abcSaveAccount".
    � Have this class inherit from "jemAccount"
    � Add a float for keeping track of the yearly interest rate of the checking account. Call this class variable "interest" Make it protected.
    � Add a public constructor for the savings account class. It should have one parameter, a float that initializes the new savings account class variable. This constructor should also call the parent class constructor with no arguments.
    � Add a public method for calculating interest. Call it "calcInterest". Have it take one parameter, an integer which represents the number of months to calculate the interest for. This method should return a float, the result of the interest calculation. For example, if 30 months are entered as a parameter of 30, then 2 and one/half years of interest on the balance are calculated and returned.
    Here are the requirements for the checking account class:
    � Call the class "abcCheckAccount"
    � Have this class inherit from "jemAccount"
    � Add an array for keeping track of the checks you write. For now, just make this an array of 100 doubles, very similar to withdrawals
    � Add a public constructor for the checking account class. It should have zero parameters. This constructor should also call the parent class constructor with no arguments.
    � Add a new public method to your checking account class. Call it "writeCheck". This should take one double parameter. If the value of the parameter is positive, subtract the parameter from the balance, and copy the value into the "checks" array. (Keep the checks and withdrawals separate.) Else do nothing.
    � Override the "printAccount" method. Have the checking account "printAccount" run its parent "class printAccount", then print out a list of the checks, after the list of the withdrawals.
    Here's what i have so far for the savings account class:
    public class abcSaveAccount extends jemAccount
    protected float interest;
    public void abcSaveAccount (float newSavings)
    super ();
    public calcInterest (int numberMonths)
    return interest;
    And here's what i have so far for the checking account class:
    public class abcCheckAccount extends jemAccount
    double[] checks = new doulbe[100];
    public abcCheckAccount ()
    super ();
    public writeCheck (double value)
    if (value >= 0)
    balance = balance - value;

    Few changes,
    public class abcCheckAccount extends jemAccount {
         private double[] checks = new double[100];
         private int checkIndex;
         public abcCheckAccount() {
              super ();
              checkIndex=0;
         public void writeCheck (double value) {
              if ( value >= 0) {
                   withdrawl(value);
                   checks[checkIndex++]=value;
         public void printAccount() {
              super.printAccount();
              System.out.println("Checks:");
              for (int i = 0; i < checkIndex; i++) System.out.println("     "+checks[ i ]);
              System.out.println("");
              System.out.println("");
    } // end of abcCheckAccount classand
    public class abcprog {
       public static void main (String args[]) {
              abcCheckAccount check = new abcCheckAccount();
              check.setName("Sudha");
              check.deposit(1000.0);
              check.deposit(200.0);
              check.withdrawl(112.0);
              check.writeCheck(300.0);
              check.printAccount();
              abcSaveAccount save = new abcSaveAccount(6);
              save.setName("Mike");
              save.deposit(1000.0);
              save.withdrawl(112.0);
              save.printAccount();
              System.out.println("Calculated Interest : "+save.calcInterest(120));
    }U can use this program to test your classes.
    Sudha

  • Need help with "class file contains wrong class"

    I have a dbUtil package as
    package dbUtil;
    public class dbConfig {
    public String getHost(String db) {
    This file called dbConfig.java has been compiled with -d option and rthe class files resides in dir <install_dir>/webapps/test/WEB-INF/classes/eb/dbUtil/
    I have a jsp file in <install_dir>/webapps/test/test.jsp which imports the dbUtil package
    <%@ page import="eb.dbUtil.dbConfig" %>
    and I am getting this error:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: -1 in the jsp file: null
    Generated servlet error:
    [javac] Compiling 1 source file
    /opt/hpws/tomcat/work/Standalone/localhost/test/test_jsp.java:12: cannot access eb.dbUtil.dbConfig
    bad class file: /opt/hpws/tomcat/webapps/test/WEB-INF/classes/eb/dbUtil/dbConfig.class
    class file contains wrong class: dbUtil.dbConfig
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    import eb.dbUtil.dbConfig;
    ^
    1 error
    Can anyone tell me what am I doing wrong? I am using tomcat 4.1
    Thanks!
    L.

    Given your java file, the fully qualified name of the class is dbUtil.dbConfig.
    What you are importing is eb.dbUtil.dbConfig
    These things are not the same.
    The root of the classpath for the webapp is the classes directory.
    So either
    1 - specify dbConfig.java to be in package eb.dbUtil
    2 - move the class file into web-inf/classes/dbUtil/dbConfig.class, and import dbUtil.dbConfig.
    Also, by convention, classnames should start with a capital letter ie dbUtil.DbConfig.
    Cheers,
    evnafets

  • Help with Class CL_BCS

    I am pasting a part of the code which I am working on now...
    This is related to sending an e-mail using class CL_BCS.. I am trying to send an e-mail with subject line more than 50 characters in it.
    The e-mail is already working, i get an e-mail immediately but with a shortened subject line.....
    We can use the set_message_subject method to get the subject line longer but it doesnt work still due to some strange reason...
    I know that the problem is with the bolded part.. when i went into the debugger mode i see that it compares the subject line which is passed on to the i_subject.
    Points are guaranteed.........
    -------- create persistent send request ------------------------
    send_request = cl_bcs=>create_persistent( ).
    clear i_subject.
    -------- create and set document with attachment ---------------
    create document from internal table with text
    document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = text
    i_length = '12'
    i_subject = '' ).
    *changing the content of the attachment
    binary_content[] = l_iobjbin[].
    *change the name of the PDF attachment
    concatenate 'Build ID' s_buildid_i 'Rev' v_buildid_rev
    into i_att_sub separated by space.
    add attachment to document
    CALL METHOD document->add_attachment
    EXPORTING i_attachment_type = 'PDF'
    i_attachment_subject = i_att_sub
    i_att_content_hex = binary_content.
    *subject line more than 50 chars
    t_sub = '[ D01 TEST] CCS0000096 NJ 8A7192 21 CONSTITUTION AVE'.
    <b>
    CALL METHOD send_request->set_message_subject
    EXPORTING
    ip_subject = t_sub.
    </b>
    add document to send request
    CALL METHOD send_request->set_document( document ).

    Try this way
    data : subject type SOTR_TXT.
    subject = '[ D01 TEST] CCS0000096 NJ 8A7192 21 CONSTITUTION AVE'.
    document = cl_document_bcs=>create_document(
                         i_type    = 'RAW'
                         i_text = text
                         i_length = '12'
                         i_subject = subject ).
    aRs

  • Need help with Class-Path and NCDFE

    This isn't a new issue, but I'm getting a variation of a problem a lot of people seem to have had. I was hoping someone out there can help me out.
    I have a jar file (imex.jar) sitting in c:\temp\imextest. I also have another jar file, commons-cli-1.0.jar sitting in c:\temp\imextest\lib.
    I want to run the jar in a standalone manner. My manifest has the following entries.
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.5.3
    Created-By: 1.4.2_01-b06 (Sun Microsystems Inc.)
    Main-Class: com.foo.imex.DirectoryImportExport
    Class-Path: lib/commons-cli-1.0.jar
    I am invoking it using the following command (from c:\temp\imextest)
    java -jar imex.jar -i -f c:\matt\RRBus\jiyun.xml -v
    I get this result:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
    It seems to me that I have my directory structure and manifest set up correctly, but maybe I don't (as it's not working). Does anyone see what I'm doing wrong here? (the "missing" class is in commons-cli-1.0.jar).
    Thanks,
    Matt

    perhaps jar file needed for parsing is not there in classpath...set it...in the classpath..

Maybe you are looking for

  • Did anybody know about the OMR(Optical mark reader) tools.

    I have to read a image file using OMR(Optical mark reader).Did any third party tools for java r available in market? Plz help me....

  • Trash folder in Iphoto is not holding the pictures.

    When I move photos to the trash folder in Iphoto, they completely dissappear without me emptying the trash, they are not in the system trash either. Why is this happening? Why is this happening? I want to be able to check them again before they are g

  • More than 10 cards in a Snapshot Query

    Can the 5.0 UI be changed to allow more than 10 cards to appear in a Snapshot Query? 10 is currently the largest value available in the dropdown.

  • Passing parameter value back from Child region [BTF] to Parent

    Hello, I am using Jdev 11.1.1.6. I have a use-case where I need to pass value back from child taskflow to parent. Let me elaborate the use-case: I have a main page which is implemented as BTF with fragment. This main page contains a child region [aga

  • Home hub 3 problem

    Had the home hub 3 only 2 weeks now and the hub was working great, then it suddenly drops totally and only the openzone and btfon appear. Once you reset the hub it appears again. None of our laptops pick it up until you switch the hub off and on agai