Lets try this first since it's the easiest.
Just copy/paste this and print it.
Try to make the margins very small.
Thanks a lot for the help.
//David Ahlport, J02, #7, 7.8
import java.text.*;
public class Pr0708
{ public static void main(String[] args)
{ Fraction f1 = new Fraction(2, 3);
Fraction f2 = new Fraction(3, 4);
f1.show();
f2.show();
f1.mult(f2).show();
}
}
class Fraction
{ public int num;
public int den;
public Fraction(int n, int d)
{ num = n;
den = d;
}
public void show()
{ System.out.println(num + "/" + den);
}
public Fraction mult(Fraction f)
{ Fraction f3 = new Fraction(num, den);
f3.den *= f.den;
f3.num *= f.num;
return f3;
}
}
/*
2/3
3/4
6/12
*/
//David Ahlport, J02, #7, 7.6
import java.text.*;
class Prog7_6
{ public static void main(String[] args)
{ double x, y; char op;
Builder Calculator = new Builder();
System.out.println("");
System.out.print("Enter expresssion (0 to quit): ");
x = Input.real();
do
{
op = Input.character();
y = Input.real();
System.out.println("");
switch(op)
{
case '+':
Calculator.add(x, y);
break;
case '-':
Calculator.subtract(x, y);
break;
case '^':
Calculator.exponentiate(x, y);
break;
case '*':
Calculator.multiply(x, y);
break;
case '/':
Calculator.divide(x, y);
break;
default:
System.out.print("Invalid operator");
break;
}
System.out.println("");
System.out.print("Enter expresssion (0 to quit): ");
x = Input.real();
}while(x != 0);
}
}
class Builder
{
public Builder()
{
}
public void subtract(double a, double b)
{
System.out.print((a - b));
}
public void add(double a, double b)
{
System.out.print((a + b));
}
public void multiply(double a, double b)
{
System.out.print ((a * b));
}
public void divide(double a, double b)
{
System.out.print ((double)(a / b));
}
public void exponentiate(double a, double b)
{
System.out.print (Math.pow(a, b));
}
}
/*
Enter expresssion (0 to quit): 1+2
3.0
Enter expresssion (0 to quit): 4+4
8.0
Enter expresssion (0 to quit): 4^2
16.0
Enter expresssion (0 to quit): 0
*/