Question

In: Computer Science

Can someone write very similar code to this but have it read the Absolute value, Cos,...

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();
}
  
}

Solutions

Expert Solution

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);
   }
}


Related Solutions

Bonds X and Y are very similar: they have the same face value, the same coupon...
Bonds X and Y are very similar: they have the same face value, the same coupon rate, the same maturity, and both make semi-annual payments.  Bond X has a credit-rating of AA.  Bond Y has a credit rating of BB.  Which bond will have the higher yield to maturity?  Why?
This code is to be written in Matlab. Write a function that will plot cos(x) for...
This code is to be written in Matlab. Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values....
write the MATLAB code for: Let ? = sin2 (?) and ? = sin(?) cos(?). Let...
write the MATLAB code for: Let ? = sin2 (?) and ? = sin(?) cos(?). Let x vary from 0 to 10? in increments of 0.1?. Plot two figures part a & b. This panel has rows, one figure per row. a. Plot x versus y. This plot is on the top of panel and the next figure (part b) is at bottom of panel. i. Give a meaningful title to this figure. ii. x-axis is time with unit of...
Polymers that have very different applications often have properties that are very similar. The polymers for...
Polymers that have very different applications often have properties that are very similar. The polymers for soda bottles (polyethylene), plastic pipes (PVC) and Saran® wrap are all very different in strength and flexibility. Research the polymer structure of each of these products and explain how they are similar on a molecular level. Please no hand written answers and at least 150 words
Python 3 can someone explain in very simple terms what EVERY line of code does, including...
Python 3 can someone explain in very simple terms what EVERY line of code does, including what j and i do def longest(string): start=0;end=1;i=0; while i<len(string): j=i+1 while j<len(string) and string[j]>string[j-1]: j+=1 if end-start<j-i: end=j start=i i=j; avg=0 for i in string[start:end]: avg+=int(i) print('The longest string in ascending order is',string[start:end]) print('The average is',avg/(end-start)) s=input('Enter a string ') longest(s)
Use Newton's method to find the absolute maximum value of the function f(x) = 3x cos(x),...
Use Newton's method to find the absolute maximum value of the function f(x) = 3x cos(x), 0 ≤ x ≤ π; correct to six decimal places.
I have a problem with my code. It does not run. Please can someone check the...
I have a problem with my code. It does not run. Please can someone check the code and tell me where I went wrong? This is the question: Program Specification: Write a C program that takes the length and width of a rectangular yard, and the length and width of a rectangular house (that must be completely contained in the yard specified) as input values. Assuming that the yard has grass growing every where that the house is not covering,...
Write an assembly code in MIPS program that can read 3 numbers from the user and...
Write an assembly code in MIPS program that can read 3 numbers from the user and print the following: a. The summation b. The average c. The minimum d. The maximum e. Print the values between the minimum and maximum f. Write comments to explain each line in your code -look at Fibonacci code- (no comments mean zero for the assignment ) use MARS MIPS .
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
can someone translate this pseudo code to actual c++ code while (not the end of the...
can someone translate this pseudo code to actual c++ code while (not the end of the input) If the next input is a number read it and push it on the stack else If the next input is an operator, read it pop 2 operands off of the stack apply the operator push the result onto the stack When you reach the end of the input: if there is one number on the stack, print it else error
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT