Constructors, Instance Variables, and Parameters

Double and Char won't compile properly

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 3795 Views - Last Post: 23 April 2007 - 05:07 AM Rate Topic: -----

#1 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Constructors, Instance Variables, and Parameters

Post icon  Posted 20 April 2007 - 02:33 PM

Coding project file should have two classes.

The program class is named StudentStart and the object class is named Student.

The Student class should be used to create three student objects.

Each student object should be instantiated with five arguments using a constructor to initialize the instance variables.

The instance variables should contain the student's name, their student number and the scores they received on each of three tests worth 100 points if they received all the possible points.

The average grade for the three test scores should be calculated and a letter grade determined for the average grade in the constructor when the student object is instantiated.

The Student class should also contain the writeOutput method used to display on the monitor the student name, student number, test scores receive, average grade for the three test scores and the letter grade the student will receive.


(Here is what I have below for this project. It does not compile or recognize the double or char. What am I doing wrong?)

/* The Student class contains four constructors that

are used to initialize variables when Student objects

are created.  It also contains the output method

used by the program StudentStart.java to output information

about the object to the monitor Constructors are used

to initialize variables.  A constructor does not use

a return type in the heading. Also a constructor's name

is identical to the class name.  Constructors cannot be

invoked except when a new object is created. */



public class Student

{



			/* String, double, and char variables declared but not initialized.*/



			private String stName;

			private String stStudentid;

	 		private double Testone;

			  private double Testtwo;

			private double Testthree;

			private char Letter;




			/*

			   This constructor is called the default constructor

			   because it has no parameters and receives no arguments.

			   */



			public Student()



			{



			stName  = "Student Name: ";

			stStudentid = "Student #: ";

			Testone = "TESTING: ";

			Testtwo = "TESTING: ";

			Testthree = "TESTING: ";

			Letter = "TESTING: ";









			} /* end of Student default constructor -*/





			/* This constructor is used when new objects are created

			   with one String argument. */
















			/* The first line of the method is called the method

			   heading. The statements between the {  } curly braces

			   are considered the body of the method. Together they

			   are called the method definition. The writeOutput

			   method return type void because it returns no values to

			   the computer.  It is public so any program can access

			   it. This method is used in this program to print the

			   current values of the instance variables in each

			   object when the respective object calls the writeOutput

			   method.*/

public Student(String stName, String stStudentid, double Testone, double Testtwo, double Testthree)

{
		   				stName = "Student Name: " + stName + "";

		   				stStudentid = "Student #: " + stStudentid + "";

		   				Testone = "Grades: " + Testone + Testtwo + Testthree + "";

		   				Letter = "Letter Grade: " + Letter + "\n\n";
}




		   public void writeOutput()



			{

			System.out.println(stName);

			System.out.println(stStudentid);

			System.out.println(Testone);

			System.out.println(Testtwo);

			System.out.println(Testthree);

			System.out.println(Letter);


			}	/* end of writeOutput method */









}	 /*end of class Student*/






and StudentStart

/* This is a simple program to demonstrate

  how java can create three student objects from a

  class called Student using four constructors

  in the Student class.



  A Student constructor is called for each of the

  objects you create.  However a different

  constructor is called for each object since

  a different number of arguments is sent to

  the constructor each time. The constructor

  is used if the constructors parameters match

  the arguments sent in type and number.

  The three objects we create are named StudentA,

  StudentB and StudentC. We are using two class

  files in this project. They are Student

  in the StudentStart.java file and Student in the

  Student.java file. StudentStart is the program

  file because it contains the method named:

  public static void main(String[] args)

  */



public class StudentStart

{



			public static void main(String[] args)

			{





			/* Each of the following statements creates

			a Student object by making a copy of the class

			named Student.  It then assigns them different

			names. These objects are named StudentA, StudentB and

			StudentC. We refer to this as instantiating

			(making an instant copy of the class)

			We initialize variables in these objects using

			constructors. The arguments in the parentheses

			are used by the constructor to initialize the

			instance variables in the object in accordance with

			the method definition for the constructor.

			In this example the new objects are enclosed in

			quotation marks as literal strings because the

			constructors use type String parameters.*/





			Student studentA = new Student("Ugly Betty", "789", "100", "80", "90", "C");



			Student studentB = new Student("Mary Jane", "123", "80", "75", "65", "B");



			Student studentC = new Student("Luke Sky", "456", "70", "65", "86", "A");










	/* The following statements call the output

	method in each of the objects as indicated.

	The name to the left of the period is the

	object name and the name to the right of the

	period is the output method. Remember you

	cannot call any of the constructor methods

	after the object has been created.  The

	output method illustrates displays information

	showing a different constructor was used

	to initialize the variables in each object.*/





			studentA.writeOutput();



			studentB.writeOutput();



			studentC.writeOutput();








			}		/*end of main method*/



}		   /*end of class StudentStart*/





Is This A Good Question/Topic? 0
  • +

Replies To: Constructors, Instance Variables, and Parameters

#2 beef   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 141
  • Joined: 02-November 06

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 03:01 PM

For one, you are trying to put strings in your double variables. That won't work.

//Bad
Testone = "TESTING";

//Better (the little d tells java this is a double instead of an int)
Testone = 0d;



Another problem I see is in your constructor where you pass in values, you aren't specifying which Testone you are putting stuff in, and java will put it in the one that is most local. You should either use different names for your input variables or add a this. in front of your first set of values like this:

this.Testone = Testone;

This post has been edited by beef: 20 April 2007 - 03:02 PM

Was This Post Helpful? 0
  • +
  • -

#3 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 03:39 PM

I guess I don't understand. What about the char?

View Postbeef, on 20 Apr, 2007 - 03:01 PM, said:

For one, you are trying to put strings in your double variables. That won't work.

//Bad
Testone = "TESTING";

//Better (the little d tells java this is a double instead of an int)
Testone = 0d;



Another problem I see is in your constructor where you pass in values, you aren't specifying which Testone you are putting stuff in, and java will put it in the one that is most local. You should either use different names for your input variables or add a this. in front of your first set of values like this:

this.Testone = Testone;

Was This Post Helpful? 0
  • +
  • -

#4 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 03:48 PM

Okay, now I need the other two grades to show up and they aren't. I'm supposed to have three grades and then average them with a letter grade.

Revised Student.java


/* The Student class contains four constructors that

are used to initialize variables when Student objects

are created.  It also contains the output method

used by the program StudentStart.java to output information

about the object to the monitor Constructors are used

to initialize variables.  A constructor does not use

a return type in the heading. Also a constructor's name

is identical to the class name.  Constructors cannot be

invoked except when a new object is created. */



public class Student

{



			/* String, double, and char variables declared but not initialized.*/



			private String stName;

			private String stStudentid;

	 		private double Grades;

		 	private char Letter;




			/*

			   This constructor is called the default constructor

			   because it has no parameters and receives no arguments.

			   */



			public Student()



			{



			stName  = "Student Name: ";

			stStudentid = "Student #: ";

			 Grades = 0d;

			  Letter = Letter;









			} /* end of Student default constructor -*/





			/* This constructor is used when new objects are created

			   with one String argument. */
















			/* The first line of the method is called the method

			   heading. The statements between the {  } curly braces

			   are considered the body of the method. Together they

			   are called the method definition. The writeOutput

			   method return type void because it returns no values to

			   the computer.  It is public so any program can access

			   it. This method is used in this program to print the

			   current values of the instance variables in each

			   object when the respective object calls the writeOutput

			   method.*/

public Student(String stName, String stStudentid, double Grades)

{
		   				stName = "Student Name: " + stName + "";

		   				stStudentid = "Student #: " + stStudentid + "";

		   				Grades = "Grades: " + Grades + "";

		   				Letter = "Letter Grade: " + Letter + "";
}




		   public void writeOutput()



			{

			System.out.println(stName);

			System.out.println(stStudentid);

			System.out.println(Grades);

			System.out.println(Letter);


			}	/* end of writeOutput method */









}	 /*end of class Student*/





Revised
StudentStart.java


/* This is a simple program to demonstrate

  how java can create three student objects from a

  class called Student using four constructors

  in the Student class.



  A Student constructor is called for each of the

  objects you create.  However a different

  constructor is called for each object since

  a different number of arguments is sent to

  the constructor each time. The constructor

  is used if the constructors parameters match

  the arguments sent in type and number.

  The three objects we create are named StudentA,

  StudentB and StudentC. We are using two class

  files in this project. They are Student

  in the StudentStart.java file and Student in the

  Student.java file. StudentStart is the program

  file because it contains the method named:

  public static void main(String[] args)

  */



public class StudentStart

{



			public static void main(String[] args)

			{





			/* Each of the following statements creates

			a Student object by making a copy of the class

			named Student.  It then assigns them different

			names. These objects are named StudentA, StudentB and

			StudentC. We refer to this as instantiating

			(making an instant copy of the class)

			We initialize variables in these objects using

			constructors. The arguments in the parentheses

			are used by the constructor to initialize the

			instance variables in the object in accordance with

			the method definition for the constructor.

			In this example the new objects are enclosed in

			quotation marks as literal strings because the

			constructors use type String parameters.*/





			Student studentA = new Student("Ugly Betty", "789", "100", "80", "90", "C");



			Student studentB = new Student("Mary Jane", "123", "80", "75", "65", "B");



			Student studentC = new Student("Luke Sky", "456", "70", "65", "86", "A");










	/* The following statements call the output

	method in each of the objects as indicated.

	The name to the left of the period is the

	object name and the name to the right of the

	period is the output method. Remember you

	cannot call any of the constructor methods

	after the object has been created.  The

	output method illustrates displays information

	showing a different constructor was used

	to initialize the variables in each object.*/





			studentA.writeOutput();



			studentB.writeOutput();



			studentC.writeOutput();








			}		/*end of main method*/



}		   /*end of class StudentStart*/



Was This Post Helpful? 0
  • +
  • -

#5 beef   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 141
  • Joined: 02-November 06

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 04:17 PM

For the char it's kind of the same, a char can only hold one letter and it's not exactly the same as a string. If you want to give it a value use single quotes instead of double ex.
char Letter = 'a';


The way you have it now, Student is only accepting name, id and grades(as one value)

If you need to display all three, you'll have to keep track of all three in Student. An easy way to do this would be an array if you've covered that yet. If not, use 3 values like you had before.
Was This Post Helpful? 0
  • +
  • -

#6 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 04:19 PM

Here is a code I worked on previously that compiled with no errors. When I submitted it to my teacher this is what he said:

You will need to use String
and numbers. So, you have:

private String stNumber;

private String stMake;

private String stTestone;

private String stTesttwo;

private String stTestthree;

private String stLetter;


First, of all make doesn't make sense here. That was for a Car, a car
has a make, model. Well, you're dealing with a Student here so these
should be something like: name, studentId
finally, like I said we don't want to use all String types. The Test
scores should be of type int or type double. The stLetter should be of
type char as it is a single character.

So, when you create a student you don't need all those constructors you
copied from the Car example, you really only need 1. That constructor
will take 5 parameters. The first 2 will be String (for name and id)
and the last 3 will be numbers for each of the test scores.
then, inside the body of the constructor you can compute the average
(you still need to create an instance variable for that) After you
compoute the average, you can use an if statment (still inside the
constructor) to determin what letter grad the student will receive.



STUDENT.JAVA :


/* The Student class contains four constructors that

are used to initialize variables when Student objects

are created.  It also contains the output method

used by the program StudentStart.java to output information

about the object to the monitor Constructors are used

to initialize variables.  A constructor does not use

a return type in the heading. Also a constructor's name

is identical to the class name.  Constructors cannot be

invoked except when a new object is created. */



public class Student

{



			/* String variables declared but not initialized.*/



			private String stNumber;

			private String stMake;

			private String stTestone;

			private String stTesttwo;

			private String stTestthree;

			private String stLetter;




			/*

			   This constructor is called the default constructor

			   because it has no parameters and receives no arguments.

			   */



			public Student()



			{



			stNumber  = "Student Name: ";

			stMake = "Student #: ";

			stTestone = "Grade 1: ";

			stTesttwo = "Grade 2: ";

			stTestthree = "Grade 3: \n\n";





			} /* end of Student default constructor -*/





			/* This constructor is used when new objects are created

			   with one String argument. */



			public Student(String objectNum)



			{



			stNumber = "Student Name: " + objectNum + "";

			stMake = "Student #: ";

			stTestone = "Grade 1: ";

			stTesttwo = "Grade 2: ";

			stTestthree = "Grade 3: \n\n";



			}  /* end of Student constructor -- one parameter */





			/*  This constructor is used when new objects are created

						with two String arguments.  */



			public Student(String objectNum, String make)



			{



			stNumber = "Student Name: " + objectNum + "";

			stMake = "Student #: " + make + "";

			stTestone = "Grade 1: ";

			stTesttwo = "Grade 2: ";

			stTestthree = "Grade 3: \n\n";





			}  /* end of Student constructor -- two parameters */



			/* This constructor is used when new objects are created

			   with three String arguments. */



			public Student(String objectNum, String make, String
Testone)



			{



			stNumber = "Student Name: " + objectNum + "";

			stMake = "Student #: " + make + "";

			stTestone = "Grade 1: " + Testone + " \n\n";

			stTesttwo = "Grade 2: ";

			stTestthree = "Grade 3: \n\n";





			}	/* end of Student constructor -- three parameters */

			public Student(String objectNum, String make, String Testone, String
Testtwo)

			{

				stNumber = "Student Name: " + objectNum + "";

				stMake = "Student #: " + make + "";

				stTestone = "Grade 1: " + Testone + "";

				stTesttwo = "Grade 2: " + Testtwo + "";

				stTestthree = "Grade 3: ";

				stLetter = "Letter Grade: \n\n";

		}

			/* The first line of the method is called the method

			   heading. The statements between the {  } curly braces

			   are considered the body of the method. Together they

			   are called the method definition. The writeOutput

			   method return type void because it returns no values to

			   the computer.  It is public so any program can access

			   it. This method is used in this program to print the

			   current values of the instance variables in each

			   object when the respective object calls the writeOutput

			   method.*/

public Student(String objectNum, String make, String Testone, String
Testtwo, String Testthree)

{
		   				stNumber = "Student Name: " + objectNum + "";

		   				stMake = "Student #: " + make + "";

		   				stTestone = "Grade 1: " + Testone + "";

		   				stTesttwo = "Grade 2: " + Testtwo + "";

		   				stTestthree = "Grade 3: " + Testthree + "";

		   				stLetter = "Letter Grade: \n\n";
}


public Student(String objectNum, String make, String Testone, String Testtwo, String Testthree, String letter)

{
							stNumber = "Student Name: " + objectNum + "";

			   				stMake = "Student #: " + make + "";

			   				stTestone = "Grade 1: " + Testone + "";

			   				stTesttwo = "Grade 2: " + Testtwo + "";

			   				stTestthree = "Grade 3: " + Testthree + "";

		   					stLetter = "Letter Grade: " + letter + "\n\n";
						}

		   public void writeOutput()



			{

			System.out.println(stNumber);

			System.out.println(stMake);

			System.out.println(stTestone);

			System.out.println(stTesttwo);

			System.out.println(stTestthree);

			System.out.println(stLetter);


			}	/* end of writeOutput method */









}	 /*end of class Student*/






STUDENTSTART.JAVA :


/* This is a simple program to demonstrate

  how java can create three student objects from a

  class called Student using four constructors

  in the Student class.



  A Student constructor is called for each of the

  objects you create.  However a different

  constructor is called for each object since

  a different number of arguments is sent to

  the constructor each time. The constructor

  is used if the constructors parameters match

  the arguments sent in type and number.

  The three objects we create are named StudentA,

  StudentB and StudentC. We are using two class

  files in this project. They are Student

  in the StudentStart.java file and Student in the

  Student.java file. StudentStart is the program

  file because it contains the method named:

  public static void main(String[] args)

  */



public class StudentStart

{



			public static void main(String[] args)

			{





			/* Each of the following statements creates

			a Student object by making a copy of the class

			named Student.  It then assigns them different

			names. These objects are named StudentA, StudentB and

			StudentC. We refer to this as instantiating

			(making an instant copy of the class)

			We initialize variables in these objects using

			constructors. The arguments in the parentheses

			are used by the constructor to initialize the

			instance variables in the object in accordance with

			the method definition for the constructor.

			In this example the new objects are enclosed in

			quotation marks as literal strings because the

			constructors use type String parameters.*/





			Student studentA = new Student("Ugly Betty", "789", "100", "80", "90", "C");



			Student studentB = new Student("Mary Jane", "123", "80", "75", "65", "B");



			Student studentC = new Student("Luke Sky", "456", "70", "65", "86", "A");










	/* The following statements call the output

	method in each of the objects as indicated.

	The name to the left of the period is the

	object name and the name to the right of the

	period is the output method. Remember you

	cannot call any of the constructor methods

	after the object has been created.  The

	output method illustrates displays information

	showing a different constructor was used

	to initialize the variables in each object.*/





			studentA.writeOutput();



			studentB.writeOutput();



			studentC.writeOutput();








			}		/*end of main method*/



}		   /*end of class StudentStart*/




Was This Post Helpful? 0
  • +
  • -

#7 beef   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 141
  • Joined: 02-November 06

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 04:52 PM

You're right, it would be better to use doubles for the score and a char for letter, but if you're teacher wants you to do it this way, do it so you get the grade and learn the right way on the side if you have to.

This post has been edited by beef: 20 April 2007 - 04:52 PM

Was This Post Helpful? 0
  • +
  • -

#8 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 04:53 PM

Hello, I just have some questions to my project. I have attached a new revised version. A lot of compiler issues. Still haven't gotten to do the averages yet, still stuck on this part. Here is what I have been working on below:
-------------------------------------------------------------->


I have changed Testone, Testtwo, and Testthree to type double.

I have changed letter to type char.

See below:

public Student(String Name, String Id, double Testone, double Testtwo, double Testthree, char letter)
-------------------------------------------------------------------------------------------------------------------
I also changed this as well from String to double and char:


private String stName; <----- Stays a String
private String stId; <----- Stays a String
private double stTestone; <------ changed to double
private double stTesttwo; <----- changed to double
private double stTestthree; <------ changed to double
private char stLetter; <-------- changed to char
----------------------------------------------------------------------------------------------------------------
I think apart of my problem lies in here somewhere, but I changed the last item.

stName = "Student Name: ";
stId = "Student #: ";
stTestone = "Grade 1: ";
stTesttwo = "Grade 2: ";
stTestthree = "Grade 3: \n\n";
char stletter = 'a'; <--------------------changed
---------------------------------------------------------------------------------------------------------------------
I corrected my constructor so it includes five parameters as shown below:


public Student(String Name, String Id, double Testone, double Testtwo, double Testthree)
{
stName = "Student Name: " + Name+ "";
stId= "Student #: " + Id + "";
stTestone = "Grade 1: " + Testone + "";
stTesttwo = "Grade 2: " + Testtwo + "";
stTestthree = "Grade 3: " + Testthree + "";
stLetter = "Letter Grade: " + letter + "\n\n";
}
public void writeOutput()

{
System.out.println(stName);
System.out.println(stId);
System.out.println(stTestone);
System.out.println(stTesttwo);
System.out.println(stTestthree);
System.out.println(stLetter);

}


------------------------------------------------------------------------------------------------------------------------
On the StudentStart.java I get this error message below:

-------------->
C:\cs151\StudentStart.java:16: cannot find symbol
symbol : constructor Student(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class Student
Student studentA = new Student("Ugly Betty", "789", "100", "80", "90", "C");
^
C:\cs151\StudentStart.java:20: cannot find symbol
symbol : constructor Student(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class Student
Student studentB = new Student("Mary Jane", "123", "80", "75", "65", "B");
^
C:\cs151\StudentStart.java:24: cannot find symbol
symbol : constructor Student(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class Student
Student studentC = new Student("Luke Sky", "456", "70", "65", "86", "A");
^
.\Student.java:35: incompatible types
found : java.lang.String
required: double
stTestone = "Grade 1: ";
^
.\Student.java:37: incompatible types
found : java.lang.String
required: double
stTesttwo = "Grade 2: ";
^
.\Student.java:39: incompatible types
found : java.lang.String
required: double
stTestthree = "Grade 3: \n\n";
^
.\Student.java:56: incompatible types
found : java.lang.String
required: double
stTestone = "Grade 1: " + Testone + "";
^
.\Student.java:58: incompatible types
found : java.lang.String
required: double
stTesttwo = "Grade 2: " + Testtwo + "";
^
.\Student.java:60: incompatible types
found : java.lang.String
required: double
stTestthree = "Grade 3: " + Testthree + "";
^
.\Student.java:62: incompatible types
found : java.lang.String
required: char
stLetter = "Letter Grade: " + letter + "\n\n";
^
10 errors
Tool completed with exit code 1
---------------------------------------------------------------------------------------------------------------------------------

On the Student.java, I get this error message:

---------------->
C:\cs151\Student.java:35: incompatible types
found : java.lang.String
required: double
stTestone = "Grade 1: ";
^
C:\cs151\Student.java:37: incompatible types
found : java.lang.String
required: double
stTesttwo = "Grade 2: ";
^
C:\cs151\Student.java:39: incompatible types
found : java.lang.String
required: double
stTestthree = "Grade 3: \n\n";
^
C:\cs151\Student.java:56: incompatible types
found : java.lang.String
required: double
stTestone = "Grade 1: " + Testone + "";
^
C:\cs151\Student.java:58: incompatible types
found : java.lang.String
required: double
stTesttwo = "Grade 2: " + Testtwo + "";
^
C:\cs151\Student.java:60: incompatible types
found : java.lang.String
required: double
stTestthree = "Grade 3: " + Testthree + "";
^
C:\cs151\Student.java:62: incompatible types
found : java.lang.String
required: char
stLetter = "Letter Grade: " + letter + "\n\n";
^
7 errors
Tool completed with exit code 1

--------------------------------------------------
NEW CODE !! NEW CODE !!! BELOW:
STUDENT.JAVA
-------------------------------------------------





public class Student

{

			private String stName;

			private String stId;

			private double stTestone;

			private double stTesttwo;

			private double stTestthree;

			private char stLetter;



		public Student()



			{



			stName  = "Student Name: ";

			stId = "Student #: ";

			stTestone = "Grade 1: ";

			stTesttwo = "Grade 2: ";

			stTestthree = "Grade 3: \n\n";

			char stletter = 'a';



			}



public Student(String Name, String Id, double Testone, double Testtwo, double Testthree, char letter)

{
							stName = "Student Name: " + Name + "";

			   				stId = "Student #: " + Id + "";

			   				stTestone = "Grade 1: " + Testone + "";

			   				stTesttwo = "Grade 2: " + Testtwo + "";

			   				stTestthree = "Grade 3: " + Testthree + "";

		   					stLetter = "Letter Grade: " + letter + "\n\n";
						}

		   public void writeOutput()



			{

			System.out.println(stName);

			System.out.println(stId);

			System.out.println(stTestone);

			System.out.println(stTesttwo);

			System.out.println(stTestthree);

			System.out.println(stLetter);


			}



}




---------------------------------------------
NEW CODE!! NEW CODE!! BELOW:
STUDENTSTART.JAVA
----------------------------




public class StudentStart

{



			public static void main(String[] args)

			{


			Student studentA = new Student("Ugly Betty", "789", "100", "80", "90", "C");



			Student studentB = new Student("Mary Jane", "123", "80", "75", "65", "B");



			Student studentC = new Student("Luke Sky", "456", "70", "65", "86", "A");





			studentA.writeOutput();



			studentB.writeOutput();



			studentC.writeOutput();
		}
	}







Was This Post Helpful? 0
  • +
  • -

#9 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 04:58 PM

The first errors are coming because you are passing all you parameters to the constructor as strings, when in reality only the first two and last should be. Remove the quotes from the numbers in the call to the constructors, and perhaps use single quotes for the final parameter. The other errors occur because the parameters are incorrect.
Was This Post Helpful? 0
  • +
  • -

#10 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 05:17 PM

I don't understand what your saying fully.


View PostAmadeus, on 20 Apr, 2007 - 04:58 PM, said:

The first errors are coming because you are passing all you parameters to the constructor as strings, when in reality only the first two and last should be. Remove the quotes from the numbers in the call to the constructors, and perhaps use single quotes for the final parameter. The other errors occur because the parameters are incorrect.

Was This Post Helpful? 0
  • +
  • -

#11 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 05:24 PM

Student studentA = new Student("Ugly Betty", "789", "100", "80", "90", "C");


needs to be
Student studentA = new Student("Ugly Betty", "789", 100, 80, 90, 'C');


The other calls to the constructor will have to be modified accordingly.

In your code, the first example, everything is encased in double quotes, and will therefore been seen as a string variable. Your constructor does not accept all string variables however - it also expects doubles and char variables.
Was This Post Helpful? 0
  • +
  • -

#12 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 05:50 PM

OKAY WHAT AM I DOING WRONG HERE?


STUDENT.JAVA
REVISED AGAIN...


public class Student

{

			private String Name;

			private String Id;

			private double Testone;

			private double Testtwo;

			private double Testthree;

			private char Letter;


		public Student()



			{



			Name  = "Student Name: ";

			Id = "Student #: ";

			Testone = 0d;

			Testtwo =  0d;

			Testthree = 0d;

			char Letter = 'A';


			}



public Student(String Name, String Id, double Testone, double Testtwo, double Testthree)

{
							Name = "Student Name: " + Name + "";

			   				Id = "Student #: "+ Id + "";

			   				Testone =  0d;

			   				Testtwo =  0d;

			   				Testthree = 0d;


						}

		   public void writeOutput()



			{

			System.out.println(Name);

			System.out.println(Id);

			System.out.println(Testone);

			System.out.println(Testtwo);

			System.out.println(Testthree);

			System.out.println(Letter);


			}



}






STUDENTSTART.JAVA REVISED AGAIN....



public class StudentStart

{



			public static void main(String[] args)

			{


			Student studentA = new Student("Ugly Betty", "789", 100, 80, 90, 'A');



			Student studentB = new Student("Mary Jane", "123", 80, 75, 65, 'A');



			Student studentC = new Student("Luke Sky", "456", 70, 65, 86, 'A');





			studentA.writeOutput();



			studentB.writeOutput();



			studentC.writeOutput();
		}
	}








Was This Post Helpful? 0
  • +
  • -

#13 beef   User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 141
  • Joined: 02-November 06

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 05:58 PM

Try this in student:
public Student(String Name, String Id, double Testone, double Testtwo, double Testthree)
{
	 this.Name = "Student Name: " + Name + "";
	 this.Id = "Student #: "+ Id + "";
	 this.Testone =  Testone;
	 this.Testtwo =  Testtwo;
	 this.Testthree = Testthree;
}


Was This Post Helpful? 0
  • +
  • -

#14 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 06:51 PM

Also, please post and/or describe any errors you receive when posting...a question such as 'what am i doing wrong here?' provides very little information.
Was This Post Helpful? 0
  • +
  • -

#15 xosunkist   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 28-March 07

Re: Constructors, Instance Variables, and Parameters

Posted 20 April 2007 - 07:07 PM

Thanks, that helped me solve my problem for the first part of this project!!!

View Postbeef, on 20 Apr, 2007 - 05:58 PM, said:

Try this in student:
public Student(String Name, String Id, double Testone, double Testtwo, double Testthree)
{
	 this.Name = "Student Name: " + Name + "";
	 this.Id = "Student #: "+ Id + "";
	 this.Testone =  Testone;
	 this.Testtwo =  Testtwo;
	 this.Testthree = Testthree;
}


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2