a.
Explanation of Solution
Program:
File name: “Alphabetize.java”
//Import necessary header files
import java.util.*;
//Define a class named Alphabetize
public class Alphabetize
{
//Define main method
public static void main(String[] args)
{
//Declare the variables
String str1, str2, str3;
//Create an object for the Scanner class
Scanner in = new Scanner(System.in);
//Prompt the user to enter the first string
System.out.print("Enter first string >> ");
str1 = in.nextLine();
//Prompt the user to enter the second string
System.out.print("Enter second string >> ");
str2 = in...
b.
Explanation of Solution
Program:
File name: “Alphabetize2.java”
//Import necessary header files
import java.util.*;
//Define a class named Alphabetize2
public class Alphabetize2
{
//Define main method
public static void main(String[] args)
{
//Declare the variables
String str1, str2, str3;
//Create an object for the Scanner class
Scanner in = new Scanner(System.in);
//Prompt the user to enter the first string
System.out.print("Enter first string >> ");
str1 = in.nextLine();
//Prompt the user to enter the second string
System.out.print("Enter second string >> ");
str2 = in.nextLine();
//Prompt the user to enter the third string
System.out.print("Enter third string >> ");
str3 = in.nextLine();
//Check if the Strings were entered in alphabetical order
if(str1.toLowerCase().compareTo(str2.toLowerCase()) < 0)
if(str2.toLowerCase().compareTo(str3.toLowerCase()) < 0)
//Print the result
System.out.println(str1 + " " + str2 + " " + str3);
else
if(str3...
Want to see the full answer?
Check out a sample textbook solution- Create an input text file that has the name input.txt with the following content. In Java please. 10 45 23 14 76 55 14 34 11 4 12arrow_forwardGiven string userGreeting on one line and string userName on a second line, append a space to userGreeting. Then, append userName to userGreeting. Lastly, append a period to userGreeting. Ex: If the input is: Hey Wilma Lee then the output is: Hey Wilma Lee. #include <iostream>#include <string>using namespace std; int main() { string userGreeting; string userName; getline(cin, userGreeting); getline(cin, userName); /* Your code goes here */ cout << userGreeting << endl; return 0;}arrow_forward● Create a simple calculator application that asks a user to enter twonumbers and the operation (e.g. +, -, x, etc.) that they’d like to perform onthe numbers. Display the answer to the equation. Every equation enteredby the user should be written to a text file. Use defensive programming towrite this program in a manner that is robust and handles unexpectedevents and user inputs. Now extend your program to give the user the option to either enter twonumbers and an operator, like before, or to read all of the equations froma new txt file (the user should add the name of the txt file as an input) andprint out all of the equations together with the results. Use defensiveprogramming to ensure that the program does not crash if the file doesnot exist and that the user is prompted again to enter the name of the file.arrow_forward
- int a = 10, b =7; System.out.println(a>b?a:b); Will always print what?arrow_forwardIn Chapter 4, you created a program that generates a random number, allows a user to guess it, and displays a message indicating whether the guess is too low, too high, or correct. Now, create a modified program called GuessingGame2 in which the user can continue to enter values until the correct guess is made. After the user guesses correctly, display the number of guesses made. Recall that you can generate a random number whose value is at least min and less than max using the following statements: Random ranNumber = new Random(); int randomNumber; randomNumber = ranNumber.Next(min, max);arrow_forwardWhat is the output of the following code segment?inte=5,f=10;if(eff0) Write(Red); else Write(Orange); a. Red b. Orange c. RedOrange d. nothingarrow_forward
- Find the output #include<iostream.h> void main () { int a=3,b32,c%3Da*b; b++; a=b++; b++; cout<<a<<"\t"<<b<<"\t"<<c<<endl;}arrow_forwardI need help with this code. Modify the Alphabetize application from Chatper 7 Exercise 6A so that it accepts three Strings from the user and displays them in alphabetical order without regard to case. import java.util.*;public class Alphabetize2{public static void main(String[] args){String str1, str2, str3;Scanner in = new Scanner(System.in);System.out.print("Enter first string >> ");str1 = in.nextLine();System.out.print("Enter second string >> ");str2 = in.nextLine();System.out.print("Enter third string >> ");str3 = in.nextLine();// display strings in alphabetical orderif(str1.toLowerCase().compareTo(str2.toLowerCase()) < 0 &&str2.toLowerCase().compareTo(str3.toLowerCase()) < 0)System.out.println("You entered the strings in alphabetical order");elseSystem.out.println("You did not enter the words in alphabetical order");}}arrow_forwardWrite a program that allows a player to play Rock, Paper, Scissors. In this version, if there is a tie the computer wins. The user must beat the computer to win a round. #1 - On paper write main such that it will play the game using the functions you described below #2 - Write on paper the prototypes for each of the following functions: GetInput – Accepts the name and how many rounds they want to play as inputGetAndCheckPlay – This function will provide a menu for the user. It allows the user to choose one of the following options and error checks the input.(R) Rock(P) Paper(S) ScissorsEnter your play:GetComputerPlay – Randomly selects a play for the computer and returns a character representing that play.CheckWin – Check if the user has won, returns true if they won false if the computer wonOutputWin – Output the user’s name and if the user won or lost each round.OutputMatchWinner – Output the user’s name and the % of wins if the user won the match and outputs the % of losses if they…arrow_forward
- Suppose x, y, z, and w are int variables. What value is assigned to each of these variables after the last statement executes? x = 7; y = 2 * x - 3;z = x + y - 3; x = z / y;y = z - x;w = x + y + 2 * z;w--;y = 2 * w + z - x;arrow_forwardwrite an application that reads English-Language phrase and encodes it into morse code. also write an application that reads a phrase in morse code and converts it into the English-Language equivalent . Use one blank between each Morse-code letter and three blanks between each Morse-coded word.arrow_forward#include <iostream> using namespace std; class A { private: int x; public: A(int _x) { x = _x; } int get() { return x; } }; class B { static A a; public: static int get() { return a.get(); } }; int main(void) { B b; cout << b.get(); return 0; } Excecute and provide the screenshot.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,