Question
Question 1: -- Write a Java application that prompts a user to input a word and output the word to the screen the word in
Question 1: --
Write a Java application that prompts a user to input a word and output the word to the screen the word in alternating lowercase and uppercase letters printing all characters in a single line. Note that the first character is in lowercase. For example, if the input is
florida
the output should be
fLoRiDa
Question 2: --
Provide a GUI for problem 1. Modify the Java program from problem 1 so that the input is entered using a GUI window like JOptionPane and the output is displayed in a JOptionPane message dialog window.
Question 3: --
Write a program that asks the user for the first name of type string, the last name of type string and the age of type integer. Then it outputs this data to the text file test.txt, that is, it outputs the first name, the last name, and the age.
Question 4: --
Review the provided classes prob4.java, CelsiusThread.java, and FarenheitThread.java. In these programs, the user is prompted to enter a temperature. Then, in one thread the temperature is converted to Celsius and printed, and in the other thread the temperature is converted to Fahrenheit and printed. See the sample output below: --
Enter the temperature (Fahrenheit or Celsius):
32
Starting Executor
32.00 Degrees Fahrenheit = 0.00 degrees Celsius
32.00 Degrees Celsius = 89.60 degrees Fahrenheit
These codes have errors which do not allow them to run using the two threads. For instance, the threads are not properly configured, and there are problems with the input data and objects specifications. Review and fix these errors.
File prob4.java
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.Scanner;
public class prob4
{
@SuppressWarnings("resource")
public static void main(String[] args)
{
double T;
scanner = new Scanner(System.in);
// Enter the temperature
System.out.println(" Enter the temperature (Farenheit or Celsis):");
T = scanner.nextDouble();
// create and name each runnable
addMT = new CelsiusThread(T);
subtractMT = new FarenheitThread(T);
System.out.println("Starting Executor");
// create ExecutorService to manage threads
ExecutorService executorService = Executors.newCachedThreadPool();
// start the two threads
executorService.execute(addMT);
executorService.execute(subtractMT);
// shut down ExecutorService--it decides when to shut down threads
// System.out.printf("Tasks started, main ends.%n%n");
} // end main
File CelsiusThread.java
/*
* Calculate the temperature in degrees Celsius, assuming that the input temperature
* is in degrees Fahrenheit
*/
public class CelsiusThread {
double T, TC;
public CelsiusThread(double Tinput)
{
// Store variables
T=Tinput;
}
// Calculate temperature in degrees Celsius
public void calculateCelsius()
{
// System.out.printf("%n Starts Celsius thread ... %n ");
TC=(T-32.0)*5.0/9.0;
System.out.printf("%n %.2f %s %.2f %s", T,"Degrees Farenheit = ",TC," degrees Celsius");
}
}
File FarenheitThread.java
/*
* Calculate the temperature in degrees Farenheit, assuming that the input temperature
* is in degrees Celsius
*/
public class FarenheitThread {
double T, TF;
public FarenheitThread(double Tinput)
{
// Store variables
T=Tinput;
}
// Subtract the numbers
public void calculateFarenheit()
{
// System.out.printf("%n Starts the Farenheit thread ... %n ");
TF=T*9.0/5.0+32.0;
System.out.printf("%n %.2f %s %.2f %s", T,"Degrees Celsius = ",TF," degrees Farenheit");
}
}
NOTE: -- Kindly give solutions in step by step manner and provide screenshots of outputs. [Programming Language: -- JAVA]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started