Question

In: Computer Science

Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...

Java Codes:

1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the sentence? Second, ask the user to enter three separate words and display them in alphabetical order.

2. Create a class named Proficiency2Practice In the main method write code that takes two numbers from the Java console representing, respectively, an investment, and an interest rate. Then calculate and output the future value of the investment, in dollars and cents, using the following formula: future value = investment * ( 1 + interest rate )year Assume that the interest rate is an annual rate and is compounded annually, and that year is a whole number greater than or equal to 1. Your program should display the value of the investment in 5, 10 and 20 years. Both of the inputs need to be positive values, so use an if statement to test the user input. If a negative value was entered, display a message to the user, convert the input to a positive value, and continue with your program. (Later in the semester, you’ll learn how to loop and repeat the request for input when there is a problem with an input value.)

Solutions

Expert Solution

Thanks for the question.

Below is the code for both the problems.  Let me know if you have any doubts or if you need anything to change.

Thank You !!



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

import java.util.Scanner;

public class Proficiency1Practice {


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a short sentence: ");
        String sentence = scanner.nextLine();

        System.out.println("Total characters in the sentence: " + sentence.length());
        // splitting the sentence using space delimiter
        String words[] = sentence.split("\\s+");
        System.out.println("First word in the sentence: " + words[0]);
        System.out.println("First word \"" + words[0] + "\" contains " + words[0].length() + " characters.");

        System.out.print("Enter first word: ");
        String firstWord = scanner.nextLine();
        System.out.print("Enter second word: ");
        String secondWord = scanner.nextLine();
        System.out.print("Enter third word: ");
        String thirdWord = scanner.nextLine();

        if (firstWord.compareTo(secondWord) <= 0 && firstWord.compareTo(thirdWord) <= 0) {
            if (secondWord.compareTo(thirdWord) <= 0) {
                System.out.println("Printing in alphabetically order: " + firstWord + ", " + secondWord + ", " + thirdWord);
            }else{
                System.out.println("Printing in alphabetically order: " + firstWord + ", " + thirdWord + ", " + thirdWord);
            }
        }else if (secondWord.compareTo(firstWord) <= 0 && secondWord.compareTo(thirdWord) <= 0) {
            if (firstWord.compareTo(thirdWord) <= 0) {
                System.out.println("Printing in alphabetically order: " + secondWord + ", " + firstWord + ", " + thirdWord);
            }else{
                System.out.println("Printing in alphabetically order: " + secondWord + ", " + thirdWord + ", " + firstWord);
            }
        }else{
            if (firstWord.compareTo(secondWord) <= 0) {
                System.out.println("Printing in alphabetically order: " + thirdWord + ", " + firstWord + ", " + secondWord);
            }else{
                System.out.println("Printing in alphabetically order: " + thirdWord + ", " + secondWord + ", " + firstWord);
            }
        }
    }
}

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

import java.util.Scanner;

public class Proficiency2Practice {


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        double investment = 0, interestRate = 0.0;
        System.out.print("Enter investment amount: $");
        investment = scanner.nextDouble();

        System.out.print("Enter interest rate (%): ");
        interestRate = scanner.nextDouble();

        if (investment < 0) {
            System.out.println("You have entered -ve investment amount. Converting it to positve.");
            investment = -investment;
        }
        if (interestRate < 0) {
            System.out.println("You have entered -ve interest rate. Converting it to positve.");
            interestRate = -interestRate;
        }

        System.out.println("Future Value in 5 years  : $" + investment * Math.pow(1 + interestRate / 100, 5));
        System.out.println("Future Value in 10 years : $" + investment * Math.pow(1 + interestRate / 100, 15));
        System.out.println("Future Value in 20 years : $" + investment * Math.pow(1 + interestRate / 100, 20));


    }
}


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


Related Solutions

Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation.
Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Here is the code that I have so far I can't seem to get it...
Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation. This is the code I have from the...
This class contains the main method. In this class you should: Ask the user for the...
This class contains the main method. In this class you should: Ask the user for the name, job tilte, and salary. Instantiate a Employee object with those parameters. Use the accessor methods to check the value of all three instance variables and print them. Ask the user to enter a percentage to raise the salary by. Use the raise method to increase the salary. Use the salary accessor check the new value of salary and print it.
USING JAVA (netbeans) In your main, ask the user for an int. Do this by first...
USING JAVA (netbeans) In your main, ask the user for an int. Do this by first printing a request for the int, then creating an int x, and using the Scanner to read an int from the user and put it in x, like this: int x = scan.nextInt(); ☑ Next read in two doubles d1 and d2 from the user. This will look a lot like what you did for the int, but the scanner reads doubles using scan.nextDouble();...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Java Class Create a class with a main method. Write code including a loop that will...
Java Class Create a class with a main method. Write code including a loop that will display the first n positive odd integers and compute and display their sum. Read the value for n from the user and display the result to the screen.
In java: -Create a class named Animal
In java: -Create a class named Animal
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of miles, passes the value to a method that converts the value to kilometers, and then returns the value to the Main() method where it is displayed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT