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

It\'s time for the Java marathon, the biggest java extravaganza in Java Town, wi

ID: 3633343 • Letter: I

Question

It's time for the Java marathon, the biggest java extravaganza in Java Town, with not 1, but 2 Java events!

Event 1: Math Functions

Write a program that simulates the tossing of two dice. Toss the die, display what each dice displays and display the total of the two die. Have this program continue until a 7 or 11 is the total roll.

Event 2: String Functions

Ask the user to input two strings. Display the strings in alphabetical order. Calculate and display the number of characters in the two words. Next convert the first string to all uppercase and the second string to all lowercase. Display the resulting strings.

Finally:

Ask the user to input a sentence. Count the number of spaces in the sentence to determine the number of words entered. Output the number of characters in the sentence, the number of words in the sentence and the average number of characters per word.

 

Thanks to the responders. P.s. I dont use the latest Java. I use java 1.4.2. Therefore I cannot use scanner class and such classes. Therefore, do not use scanner class and please ensure it works on java 1.4.2. good answer will get x2 points via the usage of a second question (obviously, you dont have to answer it).

Explanation / Answer

Answer to Question 1:

import java.util.Random;

public class MathFunctions
{
   public static void main(String[] args)
   {
       Random rand = new Random();
       int dice1 = 0, dice2 = 0, sum = 0;
       int min = 1, max = 6;
       while(true)
       {
           rand = new Random();
           dice1 = min + rand.nextInt(max-min);
           dice2 = min + rand.nextInt(max-min);
           sum = dice1+dice2;
           System.out.println("Dice 1 = "+dice1+", Dice 2 = "+dice2+" , Total(dice1+dice2) = "+sum);
           if(sum !=7 && sum != 11)
           {
               System.out.println("Tossing the dice again.....");
           }
           else
               break;

       }
   }

}

Answer to Question 2:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class StringFunctions
{
   public static void main(String[] args) throws IOException
   {
       InputStreamReader inp=new InputStreamReader(System.in);
       BufferedReader input =new BufferedReader(inp);
       String str1,str2;
      
       System.out.println("Enter string 1 >>");
       str1 = input.readLine();
       System.out.println("Enter string 2 >>");
       str2 = input.readLine();
      
       if(str1.compareTo(str2) > 0)
       {
           System.out.println(str2 +" "+str1);
       }
       else
       {
           System.out.println(str1 +" "+str2);
       }
      
       System.out.println("Number of characters in string 1 : "+str1.length());
       System.out.println("Number of characters in string 2 : "+str2.length());
       System.out.println(str1.toUpperCase());
       System.out.println(str2.toLowerCase());
   }
}

let me know, if it gives any errors

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