Concept explainers
Write a method named quartersToDol1ars. The method should accept an int argument that is a number of quarters, and return the equivalent number of dollars as a double. For example, if you pass 4 as an argument, the method should return 1.0; and if you pass 7 as an argument, the method should return 1.75.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
Modern Database Management
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- In this program, create a method with the following signature: public static double getAverage(double d1, double d2, double d3, double d4, double d5) This method will accept five doubles and return the average. Also in program, create a method with the following signature: public static char determineGrade(double avg) This method will take an average, then return the corresponding letter grade. Write in java and use test case# as an example.arrow_forwardThis program will ask a user to enter their favorite color. Your program will tell the user what their “spirit animal” is based on the color entered. (Or you can do something similar but different – like online quizzes that tell you what kind of potato you are.) You will create a static method called getAnimal that takes in a single String and returns a String. In this method, you will write the code that will determine which animal gets returned. You may choose the possible colors and animals (or you may choose something else ridiculous for this program) but you must have at least 4 options for the user. For example, if they enter “red”, you might return “Tiger”. Make sure to include a response for incorrect inputs. In the main method you will give the program explanation, ask for input (favorite color), capture the input, call the getAnimal method (passing in the user’s input), and print the result. No try/catch blocks or loops are necessary. The static method should contain…arrow_forwardCreate a method that takes a value and indicate whether it is positive or negative by a return aBoolean value.Declared as: boolean isPositive (float a)arrow_forward
- Write a program (use value returning method) that prompts you to enter five scores. The program should display the average score and the corresponding letter grade for the average score. Write the following “solider” methods in the program: calc_average: this method accepts five scores as arguments and returns the average determine_grade: this method accepts an average score as an argument and returns a letter based on the following: 90-100: A 80-89: B 70-79: C 60-69: D.using java programmingarrow_forwardGiven the code below, write a method call for the method (assume that each parameter is a String). Then determine that method’s output given the arguments that you pass. METHOD trickOrTreat (parameters: candy) BEGIN CREATE treat ← 26 SWITCH candy CASE “Tootsie Roll”: treat ++ CASE “Candy Corn”: treat += 2 BREAK CASE “Twizzlers”: treat -= 2 CASE “Dots”: treat -- CASE “Kit Kat”: treat *= 2 END SWITCH RETURN treat END METHOD Method Call Exact Outputarrow_forward088..arrow_forward
- The area of a pentagon can be computed usingthe following formula: Write a method that returns the area of a pentagon using the following header:public static double area(double side)Write a main method that prompts the user to enter the side of a pentagon anddisplays its area. Here is a sample run:Enter the side: 5.5 ↵EnterThe area of the pentagon is 52.04444136781625arrow_forwardQuestion 2 Write a method int countMultiplesofFive (int x, int y) that returns the number of multiples of 5 bounded between x and y inclusive. In the main, ask the user to enter two positive numbers (both must be positive, if users enter a negative value, they keep reentering values until both numbers are positive). Use the method countMultiplesofFive to find and print how many multiples of 5 exists between the two entered numbers inclusive. Sample run 1: First random: 11 Second random: 80 There are 14 umber that are multiple of five between 11 and 80 Sample run 2: First random: 75 Second random: 33 There are 9 number that are multiple of five between 33 and 75arrow_forwardWrite an application that prompts for and reads "double" value representing a monetary amount. Then determine the fewest number of each bill and coin needed to represent that amount, starting with the highest (assuming that a ten-dollar bill is the maximum size needed). For example, if the value entered is 47.63, then the program should print the equivalent amount as:4 ten dollar bills1 five dollar bills2 one dollar bills2 quarters1 dimes0 nickels3 pennies Using your Eclipse / Java integrated development environment (IDE), develop and code a solution to Programming Project 2.11 from pages 94-95 of the text book.arrow_forward
- Prime Numbers A prime number is a number that can be evenly divided by only itself and 1. For example, the number 5 is prime because it can be evenly divided by only 1 and 5. The number 6, however, is not prime because it can be evenly divided by 1, 2, 3, and 6. Write a Boolean method named IsPrime that takes an integer as an argument and returns true if the argument is a prime number or false otherwise. Use the method in an application that lets the user enter a number and then displays a message indicating whether the number is prime.arrow_forwarda) Write a boolean method called productDivisibleByThree that returns true if the product of the digits of its integer parameter is divisible by 3 and false otherwise. For example, if the value passed to the method is 23 then the product of its digits is 6 (2*3). The method should retum true since 6 is divisible by 3. b) Write a main method that calls the method productDivisibleByThree for the values between 10 and 50 inclusive 10 per line. This should output the following numbers: 10 13 16 19 20 23 26 29 30 31 Using java 32 33 34 35 36 37 38 39 40 43 46 49 50arrow_forwardJava Program Chapter 5. PC #13. is Prime Method A prime number is a number that is evenly divisible only by itself and 1. For example, the number 5 is prime because it can be evenly divided only by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a method named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Demonstrate the method in a complete program. The program should ask the user to enter a number for primality test or a negative number to exit. Tip: Recall that the % operator divides one number by another, and returns the remainder of the division. In an expression such as num1 % num2, the % operator will return 0 if num1 is evenly divisible by num2. I do not want a goodbye system out in the program and it has to pass all the test cases. Test Case 1 Please enter a number to check for primality or -1 to exit:\n2ENTER2 is a prime…arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT