newb 2 java, need some help

Joined
Nov 10, 2008
Messages
1
Reaction score
0
this is one of the first assignments we have gotten in java and im having some problems. It is saying i am missing a return statement, and i don't know why. I could be completely messed up lol. I have this program running but im trying to make it easier to maintain. Its just suppose to do simple math equations.


Not working one
public class TwoNumbers
{
private double number1;
private double number2;

public TwoNumbers ( double pNumber1, double pNumber2)
{
number1 = pNumber1;
number2 = pNumber2;
}

public void setNums ( double pNumber1, double pNumber2 )
{
number1 = pNumber1;
number2 = pNumber2;
}

public double getNumber1()
{
return number1;

}
public double getNumber2()
{
return number2;
}

public double getSum()
{
return number1 + number2;
}

public double getDifference()
{
return number1 - number2;
}

public double getProduct()
{
return number1 * number2;
}

public double getQuotient()
{
return number1 / number2;
}

public double getAverage()
{
return (number1 + number2) / 2;
}


public static void main(String argv[])
{
TwoNumbers pNumber1 = new TwoNumbers(10.0,15.0);
TwoNumbers pNumber2 = new TwoNumbers(100.0,200.0);
}



public double displaySum(TwoNumbers pNumber1)
{

System.out.println( pNumber1.getSum() + " = " +
pNumber1.getNumber1() + " + " +
pNumber1.getNumber2() );
}


}


WORKING ONE that i am now trying to make easier to read/maintain.
public class TwoNumbers
{
private double number1;
private double number2;

public TwoNumbers ( double pNumber1, double pNumber2)
{
number1 = pNumber1;
number2 = pNumber2;
}

public void setNums ( double pNumber1, double pNumber2 )
{
number1 = pNumber1;
number2 = pNumber2;
}

public double getNumber1()
{
return number1;

}
public double getNumber2()
{
return number2;
}

public double getSum()
{
return number1 + number2;
}

public double getDifference()
{
return number1 - number2;
}

public double getProduct()
{
return number1 * number2;
}

public double getQuotient()
{
return number1 / number2;
}

public double getAverage()
{
return (number1 + number2) / 2;
}


public static void main(String argv[])
{
TwoNumbers pNumber1 = new TwoNumbers(10.0,15.0);
TwoNumbers pNumber2 = new TwoNumbers(100.0,200.0);


System.out.println("-------------------------------- ");
System.out.println(" Sum ");
System.out.println("-------------------------------- ");
System.out.print("The first set of numbers is: ");
System.out.println(pNumber1.getSum());
System.out.print("The second set of numbers is: ");
System.out.println(pNumber2.getSum());
System.out.println();

System.out.println("-------------------------------- ");
System.out.println(" Difference ");
System.out.println("-------------------------------- ");
System.out.print("The first set of numbers is: ");
System.out.println(pNumber1.getDifference());
System.out.print("The second set of numbers is: ");
System.out.println(pNumber2.getDifference());
System.out.println();

System.out.println("-------------------------------- ");
System.out.println(" Product ");
System.out.println("-------------------------------- ");
System.out.print("The first set of numbers is: ");
System.out.println(pNumber1.getProduct());
System.out.print("The second set of numbers is: ");
System.out.println(pNumber2.getProduct());
System.out.println();

System.out.println("-------------------------------- ");
System.out.println(" Quotient ");
System.out.println("-------------------------------- ");
System.out.print("The first set of numbers is:: ");
System.out.println(pNumber1.getQuotient());
System.out.print("The second set of numbers is: ");
System.out.println(pNumber2.getQuotient());
System.out.println();

System.out.println("-------------------------------- ");
System.out.println(" Average ");
System.out.println("-------------------------------- ");
System.out.print("The first set of numbers is: ");
System.out.println(pNumber1.getAverage());
System.out.print("The second set of numbers is: ");
System.out.println(pNumber2.getAverage());


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top