Question

In: Computer Science

10) Write the one line of code to find this |-13.75| = 13.75 11) Write a...

10) Write the one line of code to find this |-13.75| = 13.75

11) Write a function declaration for a function called Diff that takes two agruements of type int returns the difference of the two integers.

12) Write a main function which calls the above function and display the difference returned by the Diff function.

13) We need three functions
One which is taking length, width, and height to calculate volume of Rectangular prism and returns a double value.
One which is taking an int value and returns true it is multiple of 5. (Bool function)
One which is not taking no arguement but ask the user’s response for a rating. (User’s response should be a character)
It should return that character of user’s choice.
(a) Give the function declaration for the above 3 conditions

(b) Make function calls inside main for each of the above 3 functions.


Help is needed, please and thank you!

Solutions

Expert Solution

10.

System.out.println("Value of |-13.75| is " + Math.abs(-13.75));

PROGRAM IMPLEMENTATION

import java.lang.*;
public class demo
{

public static void main(String[] args)
{

System.out.println("Value of |-13.75| is " + Math.abs(-13.75));

}
}

OUTPUT

11)

public static int diff(int a, int b)
{
return a-b;
}

12. program IMPLEMENTATION

import java.lang.*;
import java.util.Scanner;

public class demo
{

public static int diff(int a, int b)
{
return a-b;
}
public static void main(String[] args)
{
int x,y;

Scanner sc = new Scanner(System.in);//declare the scanner object
//input the value of x
System.out.println("Enter X value :");
x = sc.nextInt();
//input the value of y
System.out.println("Enter Y value :");
y = sc.nextInt();
//DISPLAY THE DIFFERENCE
System.out.println("Difference of "+x+" and "+y+ " is "+diff(x,y));

}
}

OUTPUT

13.

//area method takes three parameters and find the area of rectangular prism
public static double area(double len,double wid, double height)
{
double area;
area= 2*(wid*len + height*len + height*wid);
return area;
}

//check method will return true if number is multiple of 5 otherwise returns false.
public static boolean check(int a)
{
if(a%5==0)
return true;
else
return false;
}

//rating method will return a character for rating
public static char rating()
{
Scanner sc = new Scanner(System.in);//declare the scanner object
char c;
System.out.println("Enter the rating(E/O/G/N)");
c = sc.next().charAt(0);
return c;
}

PROGRAM IMPLEMENTATION

import java.lang.*;
import java.util.Scanner;

public class demo
{

//check method will return true if number is multiple of 5 otherwise returns false.
public static boolean check(int a)
{
if(a%5==0)
return true;
else
return false;
}
//rating method will return a character for rating
public static char rating()
{
Scanner sc = new Scanner(System.in);//declare the scanner object
char c;
System.out.println("Enter the rating(E/O/G/N)");
c = sc.next().charAt(0);
return c;
}
//area method takes three parameters and find the area of rectangular prism
public static double area(double len,double wid, double height)
{
double area;
area= 2*(wid*len + height*len + height*wid);
return area;
}

public static void main(String[] args)
{
int x,y;
char c;
double l,w,h;

Scanner sc = new Scanner(System.in);//declare the scanner object

//input the value of x
System.out.println("Enter X value :");
x = sc.nextInt();
//check whether x is multipleof 5 or not
if(check(x))
System.out.println(x+" is multiple of 5");
else
System.out.println(x+" is not multiple of 5");

System.out.println("Your rating is "+ rating());

System.out.println("Enter the length of rectangular prism");
l = sc.nextDouble();

System.out.println("Enter the width of rectangular prism");
w = sc.nextDouble();

System.out.println("Enter the height of rectangular prism");
h = sc.nextDouble();


System.out.println("Area of rectangular prism is : "+ area(l,w,h) + "Sq. Units.");

}
}

OUTPUT


Related Solutions

Write an algorithm in pseudo code to find one element and delete it in a doubly...
Write an algorithm in pseudo code to find one element and delete it in a doubly linked list. Your algorithm will print the original list, request the user to put in an element to be deleted, then print the final list after the deletion is done. If the element doesn’t exist in the list, print "XXX is not in the list" where "XXX" should be the one you received from the user. Use the following as your test cases to...
write a code using c++. Find the first 10 prime numbers and store them in an...
write a code using c++. Find the first 10 prime numbers and store them in an array.
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children...
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657   ...
Find an equation of the tangent line to the curve cos ( x ) + 11...
Find an equation of the tangent line to the curve cos ( x ) + 11 y ^2 = x y ^3 + 34 at the point ( 0 , √ 3 ) . Assume that y is a function of x . Express all numbers in exact form and write the equation of the tangent line in terms of x and y .
write a java program. 10-20 lines of code You are a landscaper, one of your first...
write a java program. 10-20 lines of code You are a landscaper, one of your first tasks is to determine the cost of landscaping a yard. You charge a flat fee of $40 to landscape a yard, and an extra $10 a bag for raking leaves. Not all yards you work on have leaves that need to be raked. Houses without any leaves will be discounted $5. Using your program, use the JOption Pane to ask the homeowner to enter...
Write a line of code that indicates to the compiler that the method being declared overrides...
Write a line of code that indicates to the compiler that the method being declared overrides a superclass method. Write a line of code that specifies that class Fly inherits from class Insect. Call superclass Insect's toString method from subclass Fly's tostring method. Call superclass Insect's constructor from subclass Fly's constructor, assume that the constructor receives an integer for number of legs and a string for the ability it has.
For each of the following write the line(s) of code that: Declares and initializes (creates) an...
For each of the following write the line(s) of code that: Declares and initializes (creates) an ArrayList that holds String objects Adds to your ArrayList the words "Too" and "Fun" Verifies that your ArrayList now contains 2 elements Sets the second String in the ArrayList to "No" Verifies that your ArrayList still contains exactly 2 elements Prints the contents of the ArrayList to the screen in the following format: <element>, <element>, . . . , <element>
Write a code to find the following in a text file (Letter). language: Python (a) Find...
Write a code to find the following in a text file (Letter). language: Python (a) Find the 20 most common words (b) How many unique words are used? (c) How many words are used at least 5 times? (d) Write the 200 most common words, and their counts, to a file. text file: Look in thy glass and tell the face thou viewest, Now is the time that face should form another, Whose fresh repair if now thou not renewest,...
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
Java programming Write the max-heapify code and test it and then write the program to find...
Java programming Write the max-heapify code and test it and then write the program to find the three largest values of the array without sorting the entire array to get values.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT