我在一天前制作了相同的设定代码并且工作正常。 现在它得到了很多我不理解的错误。 有人可以帮忙吗?感谢。
import java.util.Scanner;
import java.io.PrintStream;
import java.lang.Math;
import type.lib.*;
public class Fraction
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
PrintStream print = new PrintStream(System.out);
print.println("For each fraction enter its numerator/denominator,");
print.println("pressing ENTER after each");
print.println("Enter x");
Fraction a = new Fraction(scan.nextLong(),scan.nextLong());
print.println("Enter y");
Fraction b = new Fraction(scan.nextLong(),scan.nextLong());
a.add(b);
Fraction a = x;
print.println("Enter z");
Fraction c = new Fraction(scan.nextLong(),scan.nextLong());
print.println("Enter t");
Fraction d = new Fraction(scan.nextLong(),scan.nextLong());
c.add(d);
Fraction c = y;
x.divide(y);
print.println("A = ");
print.println(x.toString());
}
}
答案 0 :(得分:0)
进行以下更改,并创建使用的方法,例如添加和分割
public class Fraction {
public Fraction(long nextLong, long nextLong2) { // add the constructor
// TODO Auto-generated constructor stub
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
PrintStream print = new PrintStream(System.out);
print.println("For each fraction enter its numerator/denominator,");
print.println("pressing ENTER after each");
print.println("Enter x");
Fraction a = new Fraction(scan.nextLong(),scan.nextLong());
print.println("Enter y");
Fraction b = new Fraction(scan.nextLong(),scan.nextLong());
a.add(b);
Fraction x = a; // change the fraction places
print.println("Enter z");
Fraction c = new Fraction(scan.nextLong(),scan.nextLong());
print.println("Enter t");
Fraction d = new Fraction(scan.nextLong(),scan.nextLong());
c.add(d); //create add method
Fraction y =c; // change the fraction places
x.divide(y); // create divide method
print.println("A = ");
print.println(x.toString());
}
//Create the required methods..
private void divide(Fraction y) {
// TODO Auto-generated method stub
}
private void add() {
// TODO Auto-generated method stub
}
}