Need help

I am new at Java and i'am having trouble on my assigment. I have to create a file with set and get methods with an overloaded constructor. The second is a test class. This is the part im having trouble with I keep getting cannont find symbol errors when trying to complie

First class:

// Scott
// Java POS 406 Week 2 assingment "primary"

public class Primary

{ //start

private String var1;
private String var2;
private String var3;
private boolean var4;


public Primary () {}


public void Secondary (String vvar1) // set methods
{
var1 = vvar1;
}
public void Secondary (String vvar1, String vvar2, boolean vvar4)
{
var1 = vvar1;
var2 = vvar2;
var4 = vvar4;
}
public void Secondary (boolean vvar4)
{
var4 = vvar4;
}
public String gvar1 () //get methods
{
return var1;
}
public String gvar2 ()
{
return var2;
}
public String gvar3 ()
{
return var3;
}
public boolean gvar4 ()
{
return var4;
}
} //end


and the second class im having trouble with:

// Scott
// Java POS 406 Week 2 assingment "test primary"

public class Testprimary //class name
{ //start class

public static void main (String [] args) //default constructor

{ //start main

Primary prim1 = new Primary (); // calls Primary class

prim1.vvar1 ("bike");
// prim1 ("Nintendo", "games");
// prim1.vvar3 ("and some nintendo games");
// prim1.vvar4 (true);

// Primary prim2 = new primary ();

// prim2.vvar1 ("How about some chocolate");
// prim2.vvar2 ("How about some chocolate ice cream");
// prim2.vvar3 ("I love Vanilla");
// prim2.vvar4 (false);

System.out.println ("What would you like for Christmas?
" + prim1.gvar1); // () + prim1.gvar2 () + prim.gvar3);



} //end main
} //end class

Comments

  • : I am new at Java and i'am having trouble on my assigment. I have to create a file with set and get methods with an overloaded constructor. The second is a test class. This is the part im having trouble with I keep getting cannont find symbol errors when trying to complie
    :
    : First class:
    :
    : // Scott
    : // Java POS 406 Week 2 assingment "primary"
    :
    : public class Primary
    :
    : { //start
    :
    : private String var1;
    : private String var2;
    : private String var3;
    : private boolean var4;
    :
    :
    : public Primary () {}
    :
    :
    : public void Secondary (String vvar1) // set methods
    : {
    : var1 = vvar1;
    : }
    : public void Secondary (String vvar1, String vvar2, boolean vvar4)
    : {
    : var1 = vvar1;
    : var2 = vvar2;
    : var4 = vvar4;
    : }
    : public void Secondary (boolean vvar4)
    : {
    : var4 = vvar4;
    : }
    : public String gvar1 () //get methods
    : {
    : return var1;
    : }
    : public String gvar2 ()
    : {
    : return var2;
    : }
    : public String gvar3 ()
    : {
    : return var3;
    : }
    : public boolean gvar4 ()
    : {
    : return var4;
    : }
    : } //end
    :
    :
    : and the second class im having trouble with:
    :
    : // Scott
    : // Java POS 406 Week 2 assingment "test primary"
    :
    : public class Testprimary //class name
    : { //start class
    :
    : [b]public static void main (String [] args) //default constructor
    This is not a constructor, but a static method. Constructors never return types. This one does: void.
    [/b]
    :
    : { //start main
    :
    : Primary prim1 = new Primary (); // calls Primary class
    :
    : prim1.vvar1 ("bike");
    : // prim1 ("Nintendo", "games");
    : // prim1.vvar3 ("and some nintendo games");
    : // prim1.vvar4 (true);
    :
    : // Primary prim2 = new primary ();
    :
    : // prim2.vvar1 ("How about some chocolate");
    : // prim2.vvar2 ("How about some chocolate ice cream");
    : // prim2.vvar3 ("I love Vanilla");
    : // prim2.vvar4 (false);
    :
    : System.out.println ("What would you like for Christmas?
    " + prim1.gvar1); // () + prim1.gvar2 () + prim.gvar3);
    :
    :
    :
    : } //end main
    : } //end class
    :
    Your primary doesn't have an overloaded constructor, because only primary() is a constructor. Secondary() is a method. Getter methods always have the form: "getVariableName()". In your case getVar1(), Also notice the capitalization.
    Setter methods always have the form: "setVariableName()". In your case setVar1().
    Overloaded methods/constructors have the same name, but different method parameters. Example:
    [code]
    void setDate(Date value) // Set date using a Date object
    void setDate(String value) // Set date using a string
    void setDate(int year, int month, int day) // Set date using integers
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion