pls am new to java and i have a problem with this particular question....
Write a program with a Rational class. The purpose of the Rational class is to manipulate rational number operations. A rational number is a number that can be expressed in the form A / B where A and B are both whole numbers (no fractions or decimals) and B must not be equal to 0.
Your Rational class needs to declare two data attributes: num for numerator and den for denominator. Only one constructor is required, which uses two parameters entered at the keyboard. The first parameter is the numerator and the second parameter is the denominator. The Rational class requires three additional methods, which are getDecimal, getNum and getDen. The getDecimal method returns the decimal value of the current rational number that is stored. If the number 3 / 4 is stored, then getDecimal will return 0.75. Method getNum returns the numerator and method getDen returns the denominator.
well here is how far i have gone with it. the coments here are questions of where i do not understand
import java.text.DecimalFormat;
public class Assignment08
{
public static void main(String args[])
{
System.out.println("LAB08A 70 POINT VERSION");
System.out.println();
Rational r = new Rational( Integer.parseInt(args[0]),Integer.parseInt(args[1]) );
System.out.println("Two parameter constructor");
System.out.println(r.getNum() + "/" + r.getDen());
System.out.println(r.getDecimal());
System.out.println();
}
}
class Rational
{
private int Numerator;
private int Denorminator;
private double d;
public Rational(int a, int b)
{
Numerator = a;
Denorminator = b;
//DecimalFormat d = new DecimalFormat(0.00); // where do i paste my constructor.
d = a / b;
}
public int getNum() {return Numerator;}
public int getDen() {return Denorminator;}
public double getDecimal()
{
DecimalFormat e = new DecimalFormat(0.00); // if i put it here it still
return e.format(d); // wouldn't work.
}
}
if i run the program i get a compile error, -- cannot find symbol constructor DecimalFormat(double) in line 48 and also incompatable types in line 49.
pls i really dont just need the correct or right codes pls i do also need some brief explanation on where am wrong.
thanks ....
*admin edit: code tags
This post has been edited by e_okandeji: 04 September 2007 - 04:56 AM

New Topic/Question
Reply




MultiQuote




|