new to java

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony

    #1

    new to java

    I have written a basic program with 2 source code files demonstrating the
    new operator and basic method calls. On my computer at school, I receive an
    error on line 7 of the TestPizza.java file regarding the new operator. When
    I move the code to another computer, I do not receive the error and the
    program operates just fine. I am using Java2 1.4.2. I have checked the
    path in the System Variables and it is set up correctly. Other programs
    work just fine except for this particular program. Other people in my class
    were having the same problem and still others were not. All of us are using
    EDIT to write the programs, and compile via the command line "javac
    TestPizza.java" command.

    Any ideas why the PC is having a problem with the "new" operator?

    Thanks in advance for any responses.

    Tony

    *************** *** First Source Code File Pizza.java
    *************** ****

    //create a class to store info abouty a pizza


    class Pizza
    {
    // the private data members

    private int diameter;
    private double price;
    private String toppings;


    // the public get and set methods

    public void setDiameter(int amt)
    {
    diameter = amt;
    }

    public int getDiameter()
    {
    return diameter;
    }


    public void setPrice(double amt)
    {
    price = amt;
    }

    public double getPrice()
    {
    return price;
    }


    public void setToppings(Str ing str)
    {
    toppings = str;
    }

    public String getToppings()
    {
    return toppings;
    }


    }// end class Pizza



    ************** second source code file TestPizza.java
    *************** ****
    // client to test the Pizza class

    class TestPizza
    {
    public static void main(String args[])
    {
    Pizza pie = new Pizza();

    pie.setDiameter (15);

    pie.setPrice(8. 95);

    pie.setToppings ("Mushroom, Pepperoni");


    System.out.prin tln("You have ordered a pizza with "
    + pie.getToppings ()
    + " toppings,\nwith a diameter of "
    + pie.getDiameter ()
    + " and a price of "
    + pie.getPrice()) ;
    }




    }


  • Kenneth Stephen

    #2
    Re: new to java

    Tony wrote:
    [color=blue]
    > I have written a basic program with 2 source code files demonstrating the
    > new operator and basic method calls. On my computer at school, I receive an
    > error on line 7 of the TestPizza.java file regarding the new operator. When
    > I move the code to another computer, I do not receive the error and the
    > program operates just fine. I am using Java2 1.4.2. I have checked the
    > path in the System Variables and it is set up correctly. Other programs
    > work just fine except for this particular program. Other people in my class
    > were having the same problem and still others were not. All of us are using
    > EDIT to write the programs, and compile via the command line "javac
    > TestPizza.java" command.
    >[/color]
    Tony,

    Are the two source files located in the same directory? Have you
    compiled Pizza.java before the TestPizza.java file? Alternatively, if
    you specify :

    import Pizza;

    .....at the top of TestPizza.java, when compiling TestPizza.java, your
    compiler _may_ elect to invoke a compile on Pizza.java too. Give it a try.

    Regards,
    Kenneth

    Comment

    Working...