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());
}
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());
}