diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..69ace3f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Java-Lab-003.iml b/Java-Lab-003.iml index b46c0dd..e1006ff 100644 --- a/Java-Lab-003.iml +++ b/Java-Lab-003.iml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/README.md b/README.md index cdcf86f..fbdb418 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ For each of the issues above, screenshot and add the error images to this repo n Your answers to this exercise should be added using Markdown into the project's `README.md` file so that they get committed with the project's code.. --- +# Answers: +1. Argument type 'int' does not match the type of the format specifier '%f' +2. Argument type 'double' does not match the type of the format specifier '%d' +3. Too few arguments for format string (found: 1, expected: 2) ## Part 2: Celsius to Fahrenheit Converter @@ -48,8 +52,7 @@ Enter a temperature in Celsius: 24 ## Part 3: Seconds to Time Converter -**Objective:** -Write a Java program that converts a total number of seconds to hours, minutes, and seconds. +**Objective:**Write a Java program that converts a total number of seconds to hours, minutes, and seconds. **Steps:** 1. Prompt the user for input. diff --git a/src/TempConvert.java b/src/TempConvert.java new file mode 100644 index 0000000..3bbebca --- /dev/null +++ b/src/TempConvert.java @@ -0,0 +1,12 @@ +import java.util.Scanner; + +public class TempConvert { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.print("Enter temperature in Celsius: "); + double celsius = scanner.nextDouble(); + + double fahrenheit = (celsius * 9/5) + 32; + System.out.printf("Temperature in Fahrenheit: %.1f\n", fahrenheit); + } +} diff --git a/src/TimeConvert.java b/src/TimeConvert.java new file mode 100644 index 0000000..3dfb821 --- /dev/null +++ b/src/TimeConvert.java @@ -0,0 +1,15 @@ +import java.util.Scanner; + +public class TimeConvert { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.print("# of seconds: "); + int total = scanner.nextInt(); + + int hours = total / 3600; + int minutes = (total % 3600) / 60; + int seconds = total % 60; + + System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds.\n", total, hours, minutes, seconds); + } +}