This keeps popping up
Here's the code for the things that need javadocs
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ufe-c122-pc05
*/
public class Lab2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print ("enter first numerator ");
int num1 = input.nextInt();//take in next input
int denom1=0;//initilize denominator to zero
while (denom1 == 0) //set a determined condition for so long as there is no input
{
System.out.print ("enter first denominator "); //prompt for input of a denominator
denom1 = input.nextInt();//input for next denominator
}
System.out.print ("enter second numerator " );//prompt for another numerator
int num2 = input.nextInt();//for accepting the next numerical input
int denom2=0;//denominator condition set to zero
while (denom2 == 0) //set a determined condition for so long as there is no input for the second denominator
{
System.out.print ("enter second denominator " );//display the prompt message
denom2 = input.nextInt();//
}
Fraction firstfrac = new Fraction(num1,denom1); //this creates an object using the first fraction class
Fraction secndfrac = new Fraction (num2,denom2);//this creates an object using the second fraction class
firstfrac.display();//display first fraction
secndfrac.display();//display second fraction
int denomsum=firstfrac.getDenominator()*secndfrac.getDenominator() ;
int numersum=(firstfrac.getNumerator()*secndfrac.getDenominator())
+(secndfrac.getNumerator()*firstfrac.getDenominator());
Fraction sumfrac=new Fraction(numersum,denomsum);
System.out.print("The sum of both fractions is ");
sumfrac.display();
}
}
and
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ufe-c122-pc05
*/
public class Fraction {
private int numerator;
private int denominator;
// constructor
public Fraction (int num,int denom)//set the fraction to have the numerator and denominator variables
{
numerator=num; //numerator variable declared
denominator=denom; //denominator variable declared
reduce();
}
public void display()//a public variable that can be accesed by Lab2
{
System.out.printf("%d / %d\n",numerator, denominator); //print out message stating input fraction parts
}
// public void add()
// {
//
// }
public int getNumerator()
{
return numerator; //display input numerator
}
public int getDenominator()
{
return denominator;//display input denominator
}
private void reduce()
{
//integer variable to be the gcd
int cd=findGCD();
//find the greatest common divider
// numerator/=cd; short form
numerator=numerator/cd;
denominator=denominator/cd;
}
private int findGCD()//to find the greatest multiple for the inputs
{
//declare private numerator and denominator
int num=numerator;
int denom=denominator;
if(denom==0)//in case the fraction is undefined
{
return num;
}
while (denom>0){
int tmp=num;
num=denom;
denom=tmp%num;
}
return num;//for displaying the divider
}
}
What's wrong in these?.Sorry for sounding so frank -_- it's late now.Thanks everyone.