Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Constructors in calculation

  Asked By: Hisham    Date: Feb 22    Category: Java    Views: 1011
  

Now, that I know that there can be more multiple constructors in a
class, try to solve this problem. One class is student and the other
class is showstudent. One constuctor is receiving three vars and the
other is an overload referencing two variables in the showstudent
class.

public class student{
public static void main(String[] args){

int id_no=3835;
double hrs=16;
double pts=64;

meth1(id_no,hrs,pts);
showstudent mav=new showstudent(id_no,hrs,pts);
mav.send();
showstudent frisky=new showstudent(9999,3.5);
frisky.send();}

public static void meth1(int id_no,double hrs,double pts){
avg=pts/hrs;
meth2(id_no,avg);
}

public static void meth2(int id_no, double avg){
System.out.println("ID number "+id_no+" has received an average grade
of "+avg);


}}

public class showstudent{
int id_no;
double avg;

showstudent(int idnum,double average){
id_no=idnum;
avg=average;}

public void send(){
System.out.println("ID number "+id_no+" has received an average grade
of "+avg);}
}

public void send(int id_no,double hrs,double pts){
avg=pts/hrs;
System.out.println("ID number "+id_no+" has received an average grade
of "+avg);}}


Can anyone show me where the errors are and how to correct it with
the right code?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Mamie Wallace     Answered On: Feb 22

In student.main(), you try to use sendstudent(int, double, double) but
have not defined a c'tor that can accept these parameters.

In student.meth1(), you reference local variable avg, but provide no
declaration for it.

That's all Eclipse shows wrong. The javac compiler catches them as well.

Upon fixing these simple errors, I get the output

ID number  3835 has received an average  gradeof 4.0
ID number 3835 has received an average grade of 4.0
ID number 9999 has received an average grade of 3.5

On another note, I do not mean to talk down to you or anything, but
these are simple errors  to fix. Are you trying to debug at all, or
simply using us as your QA team?

 
Didn't find what you were looking for? Find more on Constructors in calculation Or get search suggestion and latest updates.