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.
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...
In java: -Create a class named Animal
In java: -Create a class named Animal
.......Subject Java..... main() main() will ask the user for input and then call functions to do...
.......Subject Java..... main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main(). Second function Create another function named computeBill that receives 2 parameters. It will receive the...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method displays inches in feet and inches. For example, 67 inches is 5 feet 7 inches.
Create a class using C# named InchesToFeet. Its Main()method holds an integer variable named inches to...
Create a class using C# named InchesToFeet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method uses 2 ref parameters: feet, inches left of type int and a parameter that is not ref of type int to which you pass inchesinches. For example, 67 inches is 5 feet 7 inches.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT