Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a java file for each of the following tasks. Hint: each file will have it

ID: 3539098 • Letter: C

Question

Create a java file for each of the following tasks. Hint: each file will have its own main method

1) 1) Create a program that will ask the user for 3 integers and return the average of those numbers. Use JOptionPane. Name the class AverageOne. You will want to use a variable of type Double for the average. The value should be displayed back to the user using a JOptionPane. (if the average is not computing correctly, don%u2019t worry)

2) 2)Create a program that will ask the user for 3 decimal numbers and return the average of those numbers. Use JOptionPane. Name the class AverageTwo. You will want to use a variable of type Double for each of the 3 values and for the average. The value should be displayed back to the user using a JOptionPane.

3) 3)Create a program that will ask the user for their name and then will output using JOptionPane the String in reverse order. (for example, if the name is John Smith, the output will be %u201ChtimS nhoJ%u201D). Call this class Reverse.

4) 4)Create a program that will ask the user for an input and then count the number of whitespace characters in that input. (hint: use method isWhiteSpace from class Character)

Explanation / Answer

AverageOne.java

import javax.swing.JOptionPane;


public class AverageOne{
public static void main(String[] a) {
    JOptionPane.showMessageDialog(null, "Enter Three Integers");
    int num1 = Integer.parseInt(JOptionPane.showInputDialog("Enter number1"));
    int num2 = Integer.parseInt(JOptionPane.showInputDialog("Enter number2"));
    int num3 = Integer.parseInt(JOptionPane.showInputDialog("Enter number3"));
    System.out.println("The average is :" + (num1+num2+num3)/3.0);
}
}

AverageTwo.java

import javax.swing.JOptionPane;


public class AverageTwo {
    public static void main(String[] a) {
        JOptionPane.showMessageDialog(null, "Enter Three Decimal numbers");
        double num1 = Double.parseDouble(JOptionPane.showInputDialog("Enter number1"));
        double num2 = Double.parseDouble(JOptionPane.showInputDialog("Enter number2"));
        double num3 = Double.parseDouble(JOptionPane.showInputDialog("Enter number3"));
        System.out.println("The average is :" + (num1+num2+num3)/3.0);
    }
}

Reverse.java

import javax.swing.JOptionPane;

public class Reverse {

    /**
    * @param args
    */
    public static void main(String[] args) {

        String name = JOptionPane.showInputDialog("Enter a name");
        String reverse = "";
        int length = name.length();

        for (int i = length - 1; i >= 0; i--)
            reverse = reverse + name.charAt(i);
        JOptionPane.showMessageDialog(null, "The reverse: " + reverse);

    }

}

SpaceCount.java

import javax.swing.JOptionPane;


public class SpaceCount {
    public static void main(String[] args) {

        int count =0;
        String str = JOptionPane.showInputDialog("Enter a string");
        for (int i=0; i< str.length(); i++){
            if(Character.isWhitespace(str.charAt(i)))
                count++;
        }
        JOptionPane.showMessageDialog(null, "The space count: " + count);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote