Show Bid Request
modify Fraction program
Bid Request Id: 9170
|
|
|
Description:
modify the FractionalMath programe so it performes a partial input valdiation . If either fraction does not contian exactly one slash , have the program prompt the user to re-enter the fraction . The program will repeat the prompt as often as necessary until the user enters a string containing one slash.
Deliverables: enter first fraction: 3/5 enter second fraction: 1/6
sum: 23/30 Difference :13/30 Product:3/30 Quotient 18/15
ALL OPERATIONS ARE THE CALLING OBJECT op F *****/
import java.io.*;
public class Fraction {
private int num, den;
//Two constructor public Fraction(int n, int d) { num = n; //Numerator den = d; //Denominator
if(den < 0) { num *= -1; den *= -1; }
} //another constructor //pass the fraction in the string like "1/2" public Fraction(String f) { int i = 0; boolean done = false;
while(!done) { if(f.charAt(i) == '/') done = true; else i++; }
String n = f.substring(0, i); String d = f.substring(i+1, f.length());
Integer i1 = new Integer(n); num = i1.intValue();
Integer i2 = new Integer(d); den = i2.intValue();
if(den == 0) { den *= -1; num *= -1; } }
//default constructor public Fraction() { num = 0; den = 1; }
//////////////////// //ALL OPERATIONS ARE THE CALLING OBJECT op F // Fraction f; // f.sub(f2); is f - f2 ///////////////////
public Fraction add(Fraction f) //Add method { Fraction sum = new Fraction(); sum.den = den * f.den; sum.num = num * f.den + f.num * den;
return sum; }
public Fraction sub(Fraction f) //Subtract method { Fraction dif = new Fraction(); dif.den = den * f.den; dif.num = num * f.den - f.num * den;
return dif; }
public Fraction mul(Fraction f) //Multiply Method { Fraction prod = new Fraction();
prod.den = den * f.den; prod.num = num * f.num;
return prod; }
public Fraction div(Fraction f) //Divide method { Fraction quot = new Fraction(); quot.den = den * f.num; quot.num = num * f.den; return quot; }
public void display() { System.out.print(num); System.out.print('/'); System.out.print(den); System.out.print(" "); }
public static void main(String[] args) { Fraction f1, f2;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
Fraction f3 = new Fraction();
System.out.print("Enter first fraction: "); //First Prompts for the Input X/Y String tmpstr_f1 = in.readLine(); f1 = new Fraction(tmpstr_f1);
System.out.print("Enter second fraction: "); //Second Prompt X/Y String tmpstr_f2 = in.readLine(); f2 = new Fraction(tmpstr_f2); f3 = f1.add(f2); System.out.print("Sum :"); //Output of Sum f3.display();
f3 = f1.sub(f2); System.out.print("\nDifference :"); //Output of Difference f3.display();
f3 = f1.mul(f2); System.out.print("\nProduct :"); //Output of Products f3.display();
f3 = f1.div(f2); System.out.print("\nQuotent :"); //Output of Quotient f3.display();
} catch(IOException e) { System.out.println("error"); }
}
}
Platform:
window melenium
Additional Files:
This bid request includes IMPORTANT additional attached files. Please download and read fully before bidding.
Remember that contacting the other party outside of the site (by email, phone, etc.) on all business projects < $500 (before the buyer's money is escrowed) is a violation of both the software buyer and seller agreements.
We monitor all site activity for such violations and can instantly expel transgressers on the spot, so we thank you in advance for your cooperation.
If you notice a violation please help out the site and report it. Thanks for your help.
|
|
Bidding/Comments:
|
All monetary amounts on the site are in United States dollars.
Rent a Coder is a closed auction, so coders can only see their own bids and comments. Buyers can view every posting made on their bid requests. |
See all rejected bids (and all comments)
Name |
Bid Amount |
Date |
Coder Rating |
|
|
|
This bid was accepted by the buyer!
|
$8 (USD)
|
Feb 20, 2002 2:48:23 PM EDT
|
10
(Excellent)
|
|
|
I can get this done in 1 hr if the given Java code has no bugs :-)
- Kats |
|
|
|
|
|