In: Computer Science
Can someone write very similar code to this but have it read the Absolute value, Cos, Sin, and Tan. Also, have it pass from the main method.
import java.util.Scanner;
public class Manymethods{
public void Max ()
{
Scanner scan = new Scanner( System.in);
int [] arr = new int [4];
arr = new int [4];
int i = 0, s = 0;
for (i = 0; i < 4; i++)
{
arr[i] = scan.nextInt ();
if(arr[i] > s)
s=arr[i];
System.out.println(arr[i] + " " + s);
}
}
public void Min ()
{
Scanner scan = new Scanner( System.in);
int [] arr = new int [4];
arr = new int [4];
int i = 0, s = 0;
for (i = 0; i < 4; i++)
{
arr[i] = scan.nextInt ();
if(arr[i] < s)
s=arr[i];
System.out.println(arr[i] + " " + s);
}
}
public void Add ()
{
Scanner scan = new Scanner( System.in);
int [] arr = new int [4];
arr = new int [4];
int i = 0, s = 0;
for (i = 0; i < 4; i++)
{
arr[i] = scan.nextInt ();
if(arr[i] > s)
s=arr[i] +s;
System.out.println(arr[i] + " " + s);
}
}
public void Multi ()
{
Scanner scan = new Scanner( System.in);
int [] arr = new int [4];
arr = new int [4];
int i = 0, s = 1;
for (i = 0; i < 4; i++)
{
arr[i] = scan.nextInt ();
s = arr[i] * s;
System.out.println(arr[i] + " " + s);
}
}
public static void main(String[] args) {
Manymethods m = new Manymethods();
System.out.println("We will call Maxmethod now");
m.Max();
System.out.println("We will call Minmethod now");
m.Min();
System.out.println("We will call Additionmethod now");
m.Add();
System.out.println("We will call Multimethod now");
m.Multi();
}
}
import java.util.*;
class Manymethods
{
public void sin(double degrees)
{
double radians =
Math.toRadians(degrees);
double sinValue =
Math.sin(radians);
System.out.println("sin(" + degrees
+ ") = " + sinValue);
}
public void cos(double degrees)
{
double radians =
Math.toRadians(degrees);
double cosValue =
Math.cos(radians);
System.out.println("cos(" + degrees
+ ") = " + cosValue);
}
public void tan(double degrees)
{
double radians =
Math.toRadians(degrees);
double tanValue =
Math.tan(radians);
System.out.println("tan(" + degrees
+ ") = " + tanValue);
}
public void abs(int a)
{
System.out.println("Absolute value
of "+ a +" = "+Math.abs(a));
}
public static void main(String[] args)
{
Scanner sc=new
Scanner(System.in);
Manymethods m = new
Manymethods();
System.out.println("enter degress
to find value");
double
degree=sc.nextDouble();
System.out.println("We will call
sin method now");
m.sin(degree);
System.out.println("We will call
cos method now");
m.cos(degree);
System.out.println("We will call
tan method now");
m.tan(degree);
System.out.println("enter value
to find Absolute value");
int a=sc.nextInt();
System.out.println("We will call
Absolute now");
m.abs(a);
}
}