Question

IN JAVA: Write a function that determines if a user is playing the banjo by passing...

IN JAVA: Write a function that determines if a user is playing the banjo by passing their name as a parameter, if their name starts with A through L they are not playing the banjo. Return a statement indicating if they are playing or not to the main method.

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

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new java program with name "main.java" is created, which contains following code.

main.java :

import java.util.*;//import package
public class Main //Java class
{ //main method
   public static void main(String[] args) {
   //creating object of Scanner class
   Scanner sc=new Scanner(System.in);
   //asking user to enter name
       System.out.print("Enter name : ");
       String name=sc.nextLine();//reading name
       //calling method and passing nmae
       System.out.println(checkName(name));
      
   }
   //method to check user name
   public static String checkName(String name)
   {
   String play="";//variable to store playing state
   //getting first character from name
   char c=name.charAt(0);
   //checking name
   if(c>='A' && c<='L')
   {
   //if first character is from A to l
   play="user is playing the banjo";
   }
   else
   { //if name does not starts with A to L
   play="user is not playing the banjo";
   }
   //retrun
   return play;
   }
}

======================================================

Output : Compile and Run main.java to get the screen as shown below

Screen 1 :main.java, screen when name starts with A to L

Screen 2 :main.java, screen when name starts with other than A to L

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
IN JAVA: Write a function that determines if a user is playing the banjo by passing...
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
  • A Java Problem. E5.19 Write a program that takes user input describing a playing card in...

    A Java Problem. E5.19 Write a program that takes user input describing a playing card in the following shorthand notation: А Ace 2... 10 Card values Jack Queen King Diamonds Hearts Spades Clubs Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades Implement a class Card whose constructor takes the card notation string and whose getDescription method returns a description of the card. If the notation string is not...

  • 1. Write a statement that calls a function named showSquare, passing the value 10 as an...

    1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • For JAVA- Write an application that reads three nonzero values entered by the user and determines...

    For JAVA- Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle.

  • solve it with Java please Write a Java program that prompts the user to input length...

    solve it with Java please Write a Java program that prompts the user to input length and width of a shape. If length is equal to width, call a method to calculate the area of the shape and send only one side as parameter to this method. This meth return the area of the shape. If length is not equal to width, call a method to calculate the area of the shape and send both width and length as parameters...

  • Write a C – program that calls a user-defined function from within main() that determines the...

    Write a C – program that calls a user-defined function from within main() that determines the minimum value from three positive numbers received from the user. Your function should be called minimum.  You must use a loop to receive the numbers. If the user enters a negative number, you must ask the user to re-enter the number. The function should also print out the positive numbers and the smallest number.

  • Write a java program that computes the total surface area of a rectangular prism. There are...

    Write a java program that computes the total surface area of a rectangular prism. There are six sides, so the area of all six sides has to the summed to get the total area. The program should ask the user to enter the length (L), width (W) and the height )H) for the object in inches. Create a separate method from the main to calculate the area (name the method calcArea). The output of calcArea will return a double. Output;...

  • PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning...

    PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...

  • Intro to Java. Can someone please help me answer this question. Create a java program playing...

    Intro to Java. Can someone please help me answer this question. Create a java program playing the game of craps with a random number generator. Write a method craps that plays the game of craps and it should return a 1 representing a win, a 2 representing a loss, and a 0 representing the need to toss the pair of dice again. The main method should ask how many games you wish to play then call the method craps. Main...

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

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