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

Problem 1. Determine the output of the following code: a= ([10.11],[12.13.14], {

ID: 3592403 • Letter: P

Question

Problem 1. Determine the output of the following code: a= ([10.11],[12.13.14], {15,16}) [100] z.extend (x) x [2].add Hello) x = a[0] x. append (100) x10:2]-[200.300] a 1. append (a [2]) a [1][3]. add (50) print (a) print (x) print(z) Explain this result (draw pictures) Problem 2. Write a function that takes as input strings of the form '32F" or 100C, which represent temperatures in the Fahrenheit (F) or Celsius (C) scale. The return vale of the function should be a string where the input has been converted to the other temperature scale. Include the trailing F or C to indicate the scale of the output Problem 3. Write a function char.table(s), where s is a string. The function should produce a table that shows the characters in the string and the number of occurrences of each character. Make the table nicely format- ted, using right justification for the numbers (check out the format command.) List the characters in order (the order in the character encoding). Give some examples of the output.

Explanation / Answer

2)

import java.util.Scanner;
public class TemperatureConversion {
public static void main (String [] args) {
float valueTemperature=0;
String typeTemperature = "", fullInput = "";
String fullOutput = "";
int counter = 0;

/* Ask for input */
enterInfo();
Scanner keyboard = new Scanner (System.in);

while ((!fullInput.equals("quit")) && (!fullInput.equals("stop"))) {
counter++;
if (counter > 5) {
/* Every 5 occurences, remind the user of the introduction */
enterInfo();
counter = 0;
}
  
System.out.println("");
System.out.println("To quit, enter 'quit' or 'stop'.");
System.out.print("Temperature to convert: ");
fullInput = keyboard.nextLine();

fullInput.trim();
fullInput = fullInput.toLowerCase();

//verify the string is not empty:
if (fullInput.length() <=0)
continue;

typeTemperature = fullInput.substring(fullInput.length()-1);
try {
valueTemperature = Float.parseFloat(fullInput.substring(0,fullInput.length()-1));
} catch(NumberFormatException nfe) {
if ((!fullInput.equals("quit")) && (!fullInput.equals("stop")))
System.out.println("Please specify a numerical temperature.");
continue;
}
  
/* Calculate Output */
fullOutput = calculateOutput(typeTemperature, valueTemperature);
}
  
System.out.println("FULL OUTPUT : "+fullOutput);
System.out.println("");
System.out.println("Thank you!");

}

public static void enterInfo () {
System.out.println("");
System.out.println("Please enter a temperature to convert.");
System.out.println("Enter C/c for celsius or F/f for Fahrenheit");
System.out.println("(Examples: 100C, 32f) ");
return;
}

public static String calculateOutput (String typeOfTemperature, float valueOfTemperature) {
String resultConvert = "", resultType = "";
float convertedResult = 0;
String finalConversionResult = "";

if (typeOfTemperature.equals("c")) {
/* convert to fahrenheit */
convertedResult = 9 * valueOfTemperature /5 +32;
resultConvert = " C ";
resultType = " F ";
} else if (typeOfTemperature.equals("f")) {
/* convert to celsius */
convertedResult = 5*(valueOfTemperature - 32)/9;
resultConvert = " F ";
resultType = " C ";
} else {
System.out.println("Please specify C(celsius) or F(fahrenheit). Example: 32F or 100C");
return finalConversionResult;
}
  
finalConversionResult = valueOfTemperature + resultConvert + "is " + convertedResult + resultType;
System.out.println("Final Result-> "+finalConversionResult);
  
/* Display Output */
System.out.println("");
System.out.println(valueOfTemperature + resultConvert + "is " + convertedResult + resultType);
return finalConversionResult;
}

}

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