Question

JAVA Applying the concept of method overloading, create, compile and run a Java program that calculates...

JAVA

Applying the concept of method overloading, create, compile and run a Java program that calculates and displays the result for each overload:

Given int P = 30, double Q = 50.00, float R = 70.5 • First overload: return P + 1/3P

• Second overload: return Q + 1/2Q

• Third overload: return R + 1/4R

Take screen captures of code and output. Program should illustrate method overloading (same method name), and appropriate use of classes, variable, and return value for each overload version.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

public class Main {

public static double func1(int P) {

return P + (1.0/3.0) * P;

}

public static double func1(double Q) {

return Q + (1.0/2.0) * Q;

}

public static double func1(float R) {

return R + (1.0/4.0) * R;

}

public static void main(String[] args) {

System.out.println(func1(30));

System.out.println(func1(50.00));

System.out.println(func1((float)70.5));

}

}

Add a comment
Know the answer?
Add Answer to:
JAVA Applying the concept of method overloading, create, compile and run a Java program that calculates...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java please answer A to I please dont type the answer on paper please use the...

    Java please answer A to I please dont type the answer on paper please use the computer A.   Explain why alpha cannot be accessed by other members of its class. B.   In the program, how can you determine the type of access modifier? C.   Describe the differences and similarities of beta and gamma in program, within the context of access specifiers and class member accessibility. D.   Explain how objects, a and b, are passed to the method. E.    Why...

  • Spell it out! Use the following Java concepts to compile the program below:   String myName =...

    Spell it out! Use the following Java concepts to compile the program below:   String myName = "Chuck";     int length = myName.length();     char firstChar = myName.charAt(0);     char secondChar = myName.charAt(1);     if (myName.equals("Tom")) {       System.out.println ("Sorry, Tom!");   } Write a program that uses a METHOD to translate these individual characters:   input output input output input output input output input output a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • Pleass write Java Program with comments. For this peoblem it supposed to create ur own list of po...

    Pleass write Java Program with comments. For this peoblem it supposed to create ur own list of points, then use that list to find the closest point. A list of points and the points have x and y values such as [(1,2),(3,5),(6,7),....] that’s just example. Implement the algorithm to meet the following requirements Define a class named Pair with data fields pl and p2 to represent two points and a method named getDistance) that returns the distance between the two...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT