A lab for java using API

Today’s lab will test your knowledge of classes, methods, using the API, and solving problems.

You will create two classes. One class will be the driver that has your main method. My main method took the user input of a sentence and called each method in the second class to solve the problems presented. In the main I used a do/while loop to take user input, call and output the results of each step and then ask the user if they want to continue. Look at the sample output below.

Don't use plagiarized sources. Get Your Custom Essay on
A lab for java using API
Get a plagiarism free paper Just from $13/Page
Order Essay

Your second method will have several methods using condition statements (if and switch) , and loops (for, while and do/while) to solve the problems.

The problem:

You are to write a program that will complete the following tasks:

  • Start: Prompt the user to give you a sentence (String) of any kind. Send the String to the constructor of the second class.
    • You will need an instance of the Scanner class to take the String from the user. Use the nextLine() method.
  • After the input is set, you have the String from the user, you will give the user a menu of choices that will manipulate the String, 5 menu items needed:
    1. Count the number of occurrences of a single character in the String. You will take user input for the character you will search for.
      • So if the String is “fellow fall” and the user chooses l to search the method will return 4.
      • “why the white whale wallows” and user asks for w the method will return 5.
    2. Count the words in the String, ignore white space “This is a string” and “This is a String” would both count 4 words. The method will return 4.
    3. Return the String as a String without spaces.
      • If the string is “why the white whale wallows” the method returns a String “whythewhitewhalewallows”
      • Extra tricky if you want to try it: return the String in camelback notation like this: “whyTheWhiteWhaleWallows”
        • Camelback notation has every new word after the first with a capital letter.
        • Everything you need to do this is in the Java String API
    4. Change the original input String (just reset the String you took at the startup to a new String given by the user).
    5. and exit.
  • According to whatever choice the user request you will use a switch statement to call the method that handles that chore.
  • The program will continue to run until the user chooses the exit choice. Use a do/while loop.
  • Use the Scanner class to take user input.

Here is a sample output of my program running. Sample Output Here are the steps the user picked to get this output.

  1. Gave the input String
  2. Selected count a letter and chose ‘s’ as the letter
  3. Counted the words.
  4. Changed the input String to one with a bunch of spaces.
  5. Counted the words again (notice it ignored the white space)
  6. Chose exit

Hints:

Other things you will need to use to solve the problem.

  • String API – I used indexOf(String, int), charAt(int)
    • on indexOf make sure you increment the int or you’ll keep finding the same letter or space over and over again.
  • I used a do/while in the counting letters and finding words.
  • After I found the end of a word, I moved the index up one until the spaces ended, then incremented my counter and searched for the end of the next word.

The steps you should take to make it easier:

Go step by step.

  1. First get the user input working.
  2. Then get the menu to print out.
  3. Then get the switch statement set up.
  4. Then get exit to work.
  5. Then get the resetting the String to work.
  6. Then work on counting letters or words.

Compile often. Compile after each step.

Master Homework
Order Now And Get A 20% Discount!
Pages (550 words)
Approximate price: -

Advantages of using our writing services

Custom Writing From Scratch

All our custom papers are written by qualified writers according to your instructions, thus evading any case of plagiarism. Our team consists of native writers from the USA, Canada, and the Uk, making it convenient for us to find the best to handle your order.

Unlimited Free Revisions

If you feel your paper didn't meet all your requirements, we won't stop till it's perfect. You're entitled to request a free revision within 7 days after we submit your paper.

Quality Writing In Any Format

If you have issues with citing sources and referencing, you need not worry. Our writers are highly knowledgeable in referencing, including APA/MLA/Havard/Chicago/Turabian and all other formatting styles.

Fast Delivery And Adherence To The Deadline

All our custom papers are delivered on time, even the most urgent. If we need more time to perfect your paper, we may contact you via email or phone regarding the deadline extension.

Originality & Security

At Master Homework, your security and privacy is our greatest concern. For this reason, we never share your personal information with third parties. We use several writing tools to ensure your paper is original and free from plagiarism.

24/7 Customer Support

Our agents are online 24 hours a day, 7 days a week, and are always ready to serve you. Feel free to contact us through email or talk to our live agents whenever you need assistance with your order.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

We work nonstop to see the best client experience.

Pricing

Flexible Pricing

We offer pocket-friendly prices that coincide with the preferred client's deadline.

Communication

Admission help & Client-Writer Contact

Our support team is always ready to ensure vital interaction between you and the writer whenever you need to elaborate on something.

Deadlines

Paper Submission

We deliver our papers early within the stipulated deadlines. We are glad to help you if there should be an occurrence of any alterations required.

Reviews

Customer Feedback

Your review, positive or negative, is of great concern to us and we take it very seriously. We are, consequently adjusting our policies to ensure the best customer/writer experience.