105k views
4 votes
In the main function, define five variables of type int, named: first, second, third, fourth, and total. Also in the main function, define three variables of type double named: decimalOne, decimalTwo and decimalTotal Write one function named getData which asks the user for the data and puts it in first, second, third, fourth, decimalOne, and decimalTwo. (You may copy your getData from problem H1 and make additions to manage fourth, decimalOne, and decimalTwo.) Write a function named computeTotal which can take two, or three int arguments and returns an int. Write another function, also named computeTotal which takes four int arguments and returns an int. Write another function, also named computeTotal which takes two double arguments and returns a double. Write a function named printAll which takes three arguments of type int. Write a function named printAll which takes four arguments of type int. Write a function named printAll which takes five arguments of type int. Write a function named printAll which takes three arguments of type double.

User Busetekin
by
3.2k points

1 Answer

2 votes

Answer:

  1. import java.util.Scanner;
  2. public class num8 {
  3. public static void main(String[] args) {
  4. int first, second, third, fourth,total;
  5. double decimalOne, decimalTwo, decimalTotal;
  6. }
  7. public static void getData(int first, int second, int third, int fourth, double decimalOne, double decimalTwo){
  8. System.out.println("Enter the Values");
  9. Scanner in = new Scanner(System.in);
  10. first=in.nextInt();
  11. second=in.nextInt();
  12. third=in.nextInt();
  13. fourth=in.nextInt();
  14. decimalOne = in.nextDouble();
  15. decimalTwo = in.nextDouble();
  16. }
  17. public static int computeTotal(int first, int second, int third){
  18. return first+second+third;
  19. }
  20. public static int computeTotal(int first, int second, int third, int fourth){
  21. return first+second+third+fourth;
  22. }
  23. public static double computeTotal(double decimalOne, double decimalTwo){
  24. return decimalOne+decimalTwo;
  25. }
  26. public static void printAll( int first, int second, int third){
  27. System.out.println("Number one, two and three are: "+first+" "+second+" "+third);
  28. }
  29. public static void printAll( int first, int second, int third, int fourth){
  30. System.out.println("Number one, two and three and four are: "+first+" "+second+
  31. " "+third+" "+fourth);
  32. }
  33. public static void printAll( int first, int second, int third, int fourth, int fifth){
  34. System.out.println("Number one, two and three and four are: "+first+" "+second+
  35. " "+third+" "+fourth+" "+fifth);
  36. }
  37. public static void printAll( double first, double second, double third){
  38. System.out.println("Number one, two and three and four are: "+first+" "+second+
  39. " "+third);
  40. }
  41. }

Step-by-step explanation:

This solution is provided in Java:

All the variable declarations are done in the main method (lines 3-6)

Eight methods as specified in the question are created (Lines 7, 17, 20, 23, 26, 29, 33 and 37).

Observe the concept of Method Overloading (i.e. methods with same name and return types but different parameter list)

User George Godik
by
4.0k points