This program is two files!!
I get this error constructor rational in class Rational cannot be applied to given types;
Rational foo = new Rational();
required: int, int
found no arguement
reason actual and formal argument differ in lenght
I get this error constructor rational in class Rational cannot be applied to given types;
Rational foo = new Rational();
required: int, int
found no arguement
reason actual and formal argument differ in lenght
import java.util.Scanner;
public class RationalTest
{
public static void main (String args [])
{
double num1 = 0;
double den1 = 0;
double num2 = 0;
double den2 = 0;
int choice;
int dec;
Rational foo = new Rational();
// ask user to enter the values for the fractions
Scanner input = new Scanner (System.in);
System.out.print(" this program will do basic math with fractions");
do{
System.out.print("please enter the numaortor for the first fraction\n");
num1 = input.nextDouble();
System.out.print("Please enter the denominator for the frist fraction\n");
den1 = input.nextDouble();
Rational rational1 = new Rational(num1, den1);
// takes num1 and num2 to create a rational
System.out.print("Please enter the numeraotor for the second fraction\n");
num2 = input.nextDouble();
System.out.print("Please enter the denominator for the second fraction\n");
den2 = input.nextDouble();
System.out.print ("please enter the precision\n");
dec = input.nextInt();
Rational rational2 = new Rational (num2, den2);
System.out.println("1 add fractions\n");
System.out.println("2 subtract fractions\n");
System.out.println("3 divide fractions\n");
System.out.println("4 muliply fractions\n");
choice = input.nextInt();
Rational result;
switch( choice)
{
case 1:
result = rational1.getaddfract(rational2);
break;
case 2:
result = rationa1.getsubfract(rational2);
break;
case 3:
result = rational1.gettimesfract(rational2);
break;
case 4:
result = rational1.getdividedfract(rational2);
break;
case 0:
System.out.print("Thank you for using this program");
break;
}
}
while (choice !=0);
}
}
*********
public class Rational
{
int numerator; //1
int denominator; //4
public Rational(int n, int d)
{
this. numerator = n;
this.denominator = d;
}
public Rational getaddfract (Rational r)
{
int num = (numerator * r.denominator)+(r.numerator * denominator);
// r. = rational from second rational
int den = (denominator*r.denominator);
Rational result = new Rational(num, den);
return result;
} // end add method
public Rational getsubfract( Rational r)
{
int num = (numerator * r.denominator)+(r.numerator * denominator);
int den = (denominator * r.denominator);
Rational result = new Rational(num,den);
return result;
} // end sutraction method
public Rational gettimesfract (Rational r)
{
int num = ( numerator * r.numerator);
int den = ( denominator * r.denominator);
Rational result = new Rational (num,den);
return result;
} // end times method
public Rational getdividedfract (Rational r)
{
// double total =0;
// total = ((num1 /num2) / (num2/den2));
// return total;
int num = (numerator / r.denominator);
int den = (denominator / r.numerator);
Rational result = new Rational (num,den);
return result;
}// end divide method
public String toString()
{
return numerator+"/"+denominator+"\n";
}
/* public String toString(int dec)
{
return String.format("%."+dec+"f\n",double(numerator)/double(denominator));
}