Question

In: Computer Science

PART A Write a program that converts a total number of seconds to hours, minutes, and...

PART A

Write a program that converts a total number of seconds to hours, minutes, and seconds.
It should do the following:

  1. Prompt the user for input
  2. Read an integer from the keyboard
  3. Calculate the result
  4. Use printf to display the output

Your output must be of the format:
totalSeconds seconds = numHours hours, numMinutes minutes, and numSeconds seconds

For example:
If the user entered: 5000
Your program would output:
5000 seconds = 1 hours, 23 minutes, and 20 seconds
5000 seconds = 01h:23m:20s

Sample run would look like:
Enter the number of seconds: 5000
5000 seconds = 1 hours, 23 minutes, and 20 seconds
5000 seconds = 01h:23m:20s

Sample run would look like:
Enter the number of seconds: 3754
3754 seconds = 1 hours, 2 minutes, and 34 seconds
3754 seconds = 01h:02m:34s

Hint1:Use integer division

Hint2: Use the modulus operator

Please make sure to end each line of output with a newline.
Please note that your class should be named SecondsConverter.

PART B

Write a program that converts change into formatted dollars and cents It should do the following:

  1. Prompt the user for their change in Quarters, Dimes, Nickels, Pennies
  2. Read the integers from the keyboard
  3. Calculate the result
  4. Use printf to display the output as $d.cc

Your output must be of the format: (plural is ok even when grammatically incorrect)

You entered:
   6 quarters 
   5 dimes 
   4 nickels 
   3 pennies
The total in dollars is $2.23

Sample run would look like:

Enter the number of quarters:  6
Enter the number of dimes:     5
Enter the number of nickels:   4
Enter the number of pennies:   3
You entered:
   6 quarters 
   5 dimes 
   4 nickels 
   3 pennies
The total in dollars is $2.23

Sample run would look like:

Enter the number of quarters:  1
Enter the number of dimes:     2
Enter the number of nickels:   3
Enter the number of pennies:   2
You entered:
   1 quarters 
   2 dimes 
   3 nickels 
   2 pennies
The total in dollars is $0.62

Hint1: Use printf and be sure to have at least 1 digit to the left of the decimal, and a max of 2 floating on the right.

Please make sure to end each line of output with a newline.
Please note that your class should be named ChangeConverter.

PART C

Write a program that converts a temperature from Celsius to Fahrenheit.
It should do the following:

  1. Prompt the user for input
  2. Read a double value from the keyboard
  3. Calculate the result. Here is the formula.  F = ( C * 9 / 5 ) + 32
  4. Format the output to one decimal place.

Your prompt to the user to enter the temperature in Celsius must be: Enter the Celsius Temperature as a decimal:

Your output must be of the format: celsiusTemperature C =  fahrenheitTemperature F

For example: If the user entered: 24.0
Your program would output: 24.0 C = 75.2 F

Sample run would look like:
Enter the temperature in degrees celsius:  24
24.0 C = 75.2 F

Sample run would look like:
Enter the temperature in degrees celsius:  7.5
7.5 C = 45.5 F

Hint1: Be careful not to use integer division!
Here is the formula  F = ( C * 9 / 5 ) + 32

Hint2: Remember to use printf to format the output.
Please make sure to end each line of output with a newline.
Please note that your class should be named CelsiusToFahrenheit.

Solutions

Expert Solution

//Java programs

import java.util.Scanner;

public class SecondsConverter {
   public static void main(String args[]) {
       int seconds,temp;
       int h,m,s;
       Scanner input = new Scanner (System.in);
      
       System.out.print("Enter the number of seconds: ");
       seconds = input.nextInt();
       temp = seconds;
      
       s = seconds%60;
       seconds/=60;
      
       m = seconds%60;
       h = seconds/60;
      
       System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds",temp,h,m,s);
       System.out.printf("\n%d seconds = %02dh:%02dm:%02ds\n",temp,h,m,s);
      
       input.close();
   }
}
//sample output

(2)

import java.util.Scanner;

public class ChangeConverter {
   public static void main(String args[]) {
       Scanner input = new Scanner(System.in);
       int quarters,dimes,nickels,pennies;
      
       System.out.print("Enter the number of quarters: ");
       quarters = input.nextInt();
      
       System.out.print("Enter the number of dimes: ");
       dimes = input.nextInt();
      
       System.out.print("Enter the number of nickels: ");
       nickels = input.nextInt();
      
       System.out.print("Enter the number of pennies: ");
       pennies = input.nextInt();
      
       System.out.printf("You entered:\r\n" +
               " %d quarters \r\n" +
               " %d dimes \r\n" +
               " %d nickels \r\n" +
               " %d pennies\n", quarters,dimes,nickels,pennies);
      
       float total = 25*quarters + 10*dimes + nickels*5 + pennies;
      
       System.out.printf("The total in dollars is $%.2f\n", total/100);
       input.close();
   }
}
//sample output

(3)

import java.util.Scanner;

public class CelsiusToFahrenheit {
   public static void main(String args[]) {
       Scanner input = new Scanner(System.in);
       float celcius;
      
       System.out.print("Enter the temperature in degrees celsius: ");
       celcius = input.nextFloat();
      
       float F = ( celcius * 9 / 5 ) + 32 ;
      
       System.out.printf("%.1f C = %.1f F\n", celcius,F);
      
       input.close();
  
   }
}
//sample output


Related Solutions

Write a program that accepts a number of minutes and converts it both to hours and...
Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. (I currently have what is below) import java.util.Scanner; public class MinutesConversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numOfMinutes = sc.nextInt(); double hour = numOfMinutes/60.00; double days = (hour/24); System.out.println(numOfMinutes + " minutes is " + hour + " hours or " + days + " days.");...
Write a program that accepts a number of minutes and converts it to days and hours....
Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values. Save the file as  MinuteConversionWithExceptionHandling.java
Write a program that request a time interval in seconds and display it in hours, minutes,...
Write a program that request a time interval in seconds and display it in hours, minutes, second format. (java)
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds),...
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds), (minutes, seconds), (hours, minutes, seconds) The input can be written in main It should produce the following output: (67.4, 14, 5) is 67 Hours, 38 Minutes, 5 Seconds (127.86) is 0 Hours, 2 Minutes, 8 Seconds (-3, 73, 2) is -1 Hours, -46 Minutes, -58 Seconds
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
Write a program that converts the user's number into the desired unit of measurement. The user...
Write a program that converts the user's number into the desired unit of measurement. The user will pick the desired unit from a menu shown below. Ask the follow-up question (the number to convert) and do the math ONLY if the user picks a valid choice from the menu. You can see the conversions / multipliers needed for this program in the output section below. Menu/Prompt: Enter the number that corresponds to your desired unit conversion from the choices below:...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
Write a python program that will take in the number of call minutes used. Your program...
Write a python program that will take in the number of call minutes used. Your program will calculate the amount of charge for the first 200 minutes with a rate of $0.25; the remaining minutes with a rate of $0.35. The tax amount is calculated as 13% on top of the total. The customer could have a credit that also has to be considered in the calculation process. Finally, the program displays all this information. Below is a sample run:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT