import java.awt.Container;

import javax.swing.*;
import java.util.*;
import java.text.DecimalFormat;

public class MaximumTest extends JApplet
{
	//initialize applet by obtaining user input and creating GUI
	public void init()
	{
		//obtain user input
		String s1 = JOptionPane.showInputDialog("Enter first floating-point num");
		String s2 = JOptionPane.showInputDialog("Enter second floating-point num");
		String s3 = JOptionPane.showInputDialog("Enter third floating-point num");
		int[] reverseSort = {1,2,3,4,5};

		//convert user input to double values
		double number1 = Double.parseDouble(s1);
		double number2 = Double.parseDouble(s2);
		double number3 = Double.parseDouble(s3);

		double max = maximum(number1, number2, number3);
		double min = minimum(number1, number2, number3);
		boolean pos = isPositive (number1);
		String num = myRound (number1);
		double mult = mult((int)number1, (int)number2);
		double gcd = gcd((int)number1, (int)number2);

		JTextArea outputArea = new JTextArea();

		outputArea.setText("number1: " +number1+ "\nnumber2: " +number2+
		"\nnumber3: " +number3+ "\nmaximum is: " +max+
		"\nminimum is: " +min+ "\nis positive: " +pos+ "\n" +getDate()+
		"\nRounded to 4 decimal places: " +num+
		"\nThe mult of " +number1+ " and " +number2+ " is: " +mult+
		"\nThe gcd of " +number1+ " and " +number2+ " is: " +gcd+
		reverseSort(x, y-1));

		//get applets GUI component display area
		Container container = getContentPane();

		//attach outputArea to container
		container.add(outputArea);
	}

	public static void reverseSort(int[]x, int y)
	{
		if (y==1)
			System.out.print (x[0]);
		else
		{
			System.out.print (x[y-1]);
			reverseSort(x,y-1);
		}
	}


	//---------maximum method uses Math class, method max
	public double maximum(double x, double y, double z)
	{
		return Math.max (x, Math.max(y, z));
	}

	public double minimum(double x, double y, double z)  	//--do not use Math.min()
	{
		if (x < y && x < z)
			return x;
		else if (y < x && y < z)
			return y;
		else
			return z;
	}

	public boolean isPositive(double x)
	{
		if (x >= 0) {return true;}
		return false;
	}

	public char grade(double x)
	{
		if (x < 100) {return 'A';}
		else if (x <=1000) {return 'B';}
		return 'C';
	}

	public String getDate()
	{
		Date d = new Date();
		return d.toString();
		//System.out.println("The date is " + d);
	}

	public String myRound(double num)							//*************
	{
		DecimalFormat fred = new DecimalFormat("0.0000");
		return fred.format(num);
	}

	public int mult(int x, int y)		//multiply two numbers recursively
	{
		if (y <= 1)
			return x;
		else
			return x + mult(x, y-1);
	}

	public int gcd(int x, int y)
	{
		if (y == 0)
			return x;
		else
			return gcd(y, x%y);
	}
}//end class MaximumTest


