Reputation: 3
I am relatively new to Java, and I decided to make this program, because it seemed a simple enough task to start learning how to play with methods. anyways this is my program as it stands right now.
import javax.swing.JOptionPane;
public class smallAverage{
public smallAverage getsmall() {
String sd1 = JOptionPane.showInputDialog("What is the first number?");
double sdx = Double.parseDouble (sd1);
String sd2 = JOptionPane.showInputDialog("What is the second number?");
double sdy = Double.parseDouble (sd2);
String sd3 = JOptionPane.showInputDialog("What is the third number?");
double sdz = Double.parseDouble (sd3);
return double sdx;
return double sdy;
return double sdz;
}
public smallAverage getavg() {
String ad1 = JOptionPane.showInputDialog("What is the first number");
double adx = Double.parseDouble (ad1);
String ad2 = JOptionPane.showInputDialog("What is the second number");
double ady = Double.parseDouble (ad2);
String ad3 = JOptionPane.showInputDialog("What is the third number");
double adz = Double.parseDouble (ad3);
return double adx;
return double ady;
return double adz;
}
public smallAverage work() {
double small = Math.min(sdx, sdy, sdz);
double avg = (adx + ady + adz) / 3;
System.out.println("The smallest of "+ sdx+ sdy+ sdz+ " is " + small + ", and the average of"+ adx+ ady+ adz+ " is "+ avg+ ".");
}
}
The actual math going on here really means nothing to me, its the way the code works that I want to learn. I have tried rewriting this code in many different ways but this seems to be the closest to being correct. I just have no idea why it will not work. when I try to compile through the terminal I get this:
smallAverage.java:12: error: '.class' expected
return double sdx;
^
smallAverage.java:13: error: '.class' expected
return double sdy;
^
smallAverage.java:14: error: '.class' expected
return double sdz;
^
smallAverage.java:27: error: '.class' expected
return double adx;
^
smallAverage.java:28: error: '.class' expected
return double ady;
^
smallAverage.java:29: error: '.class' expected
return double adz;
^
6 errors
Any help would be greatly appreciated
Upvotes: 0
Views: 9174
Reputation: 23634
When you return , you don't need to type specifier anymore:
return double adx;
return double ady;
return double adz;
should be
return adx;
return ady;
return adz;
same error the other three.
Meanwhile.
public smallAverage getsmall()
is wrong since you are not returning class objects from that function. You cannot put 3 return statement together in one function close to each other without any different data path. For example:
return adx;
return ady; //two return statements below will never be reached.
return adz;
Those are fundamental errors, you probably need to view some basic Java tutorials: Java Tutorial
Upvotes: 3
Reputation: 34424
you just need to do i.e
return sdx;
because type is not required as you have already defined at the time of declaring sdx.
Would recommend using some IDE like Eclipse as it points the compilation error without even running the programme. Its very helpful for development
Upvotes: 0