QuestionQuestion

Part A: String Manipulation methods
NOTE: I WANT ALL OF YOUR INPUT AND OUTPUT STATEMENTS TO BE IN YOUR MAIN METHOD
As you know Strings in java are just arrays of chars, and those chars can be manipulated just like numbers in array cells. As such, you can write methods that manipulate the string array just like you can for the numeric array. For this program first create a menu that asks the user which action to perform.

What do you want to do?
1) Reverse a string
2) Replace all instances of a letter in a string
3) Count the number of instances of a letter in a string
4) Count the number of instances of a word in a string

If the user chooses 1 you should ask them to enter a string. Once you have the string stored you should call a method that returns a string and gets passed a string as a parameter . This method should loop through the array and reverse the location of each char. For example, if the user enters “Anthony” they will get “ynohtnA” returned and printed to the screen.

If the user chooses 2 you will ask the user for a string as well as a char that they want to replace and another char to replace it with. You will then call a method that returns a string that has a string and 2 char’s as its parameters. It will look for all of the instances of the first char in the string and replace them with the second char.
Example:
Enter a string: Hello World
Enter a char to replace: o
Enter a the char to replace it with: p
Output: Hellp Wprld
If the user chooses 3 the user will accept a string and a char from the user. You will then create a method that returns an int and accepts a string and a char. You will loop through the string looking for the char and return the number of instances of the char it found.

Example:
Enter a string: Hello World
Enter a char to count: o
Output: There were 2 occurrence(s) of the char o
If the user chooses 4 the user will accept two strings from the user. You will then create a method that returns an int and accepts two strings. You will loop through the first string looking for the second string and return the number of instances of it found.

Example:
Enter a string: Hello World
Enter a char to count: World
Output: There were 1 occurrence(s) of the string World

Part B: What Do I Need to get on the Final Exam
One typical question that students ask professors right before the final exam in a course is what score they need on the final exam in order to get a grade that they want. Your task is to write a program that automates the answer to this question.
For input you will ask the user for the number of quizzes, tests, assignments, and labs are in the class.
You will then need to know the weight of each of these inputs, for example, for our class:
Homework Assignments 15%
Lab Assignments 15%
In-class Quizzes 15%
Tests 25%
Final Exam 30%

Once you have the numbers and the weights, you can calculate what you have so far in the class if you didn't do the exam by getting the marks for each lab, assignment, quiz and test (and storing them in an array for each type of mark) You will then write a method for each mark type that will pass the array of marks and the weight and return its weighted value.
By adding up the weighted values without the exam mark you will get the mark of the user in the class without the exam included. (note: at this time since you haven't completed all of your assignments and tests you can’t exactly use this just yet for your own purposes :( )
Calculate this value and print it on the screen.
You will then ask the user to input what they want to get in the course. You will write a method that will accept what the want to get in the class and what they have so far and return a double value of what they need to get in the exam to get that mark (the formula for this is: “what they want”-”what they have” /.3 ) since the exam is out of 30.
You should then print this value out to them.
You should note that there is a chance that this value is over 100%, meaning that the person would need to get higher than 100% on the exam to get the mark they asked for. Since this case is not possible you should print out a warning to the user to let them know they cannot get that grade.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class assignment4a {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
       int selection;
       Scanner keyboard = new Scanner(System.in);
      
       System.out.print("What do you want to do?\n" +
            "1) Reverse a string\n" +
            "2) Replace all instances of a letter in a string\n" +
            "3) Count the number of instances of a letter in a string\n" +
            "4) Count the number of instances of a word in a string\n"
                + "--> ");
      
       selection = keyboard.nextInt();
       keyboard.nextLine();
       System.out.print("Enter a string: ");
       String input = keyboard.nextLine();
      
       switch(selection){...
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats