Project #1696 - java programming

 

THERE ARE 3 PROBLEMS TOTAL. THANK YOU. 

PROBLEM 1 (3.109)

One day soon, the US government will finally decide to do away with pennies, as they currently cost more than a penny to produce. Complete the program below so that it prompts the user for a price in dollars and cents, determines the cents portion of the price to the nearest dime, and prints the revised price.

For example, if a price was $32.56, the revised price would be $32.60. However, if a price was $23.34, the revised price would be $23.30.

Complete the following code:

 

import java.util.Scanner;

 

/**

   This program reads a price in dollars and cents,

   rounds the price to the nearest dime,

   and prints out the revised price.

*/

public class NearestDime

{

   public static void main(String[] args)

   {

      System.out.print("Please enter the price: ");

      Scanner in = new Scanner(System.in);

      double price = in.nextDouble();

      int pennies = (int) Math.round(price * 100);

 

      // Determine dollar and cents worth of pennies

      int cents;

      int dollars;

      // Your work here    

      // Round cents to nearest dime

      int dimes;

      // Your work here    

      // Print revised price

      double revised = dollars + dimes * 0.1;

      System.out.printf("%.2f\n", revised);     

   }

}

 

PROBLEM 2 (4.101)

Complete the program named GetVowels below so that it reads in a string, finds all the vowels in that string, and prints out the vowels. For example, given the input string of "Hello, World!", the program should print the string "eoo".

import java.util.Scanner;
/**
   Reads a string and prints out all vowels contained in that string.
   Vowels are A E I O U a e i o u. 
   Input: the value of s, a string
   Output: a string containing all the vowels in s,
      in the order in which they appear in s
*/
public class GetVowels
{
   public static void main(String[] args)
   {
      String r = "";
 
      Scanner in = new Scanner(System.in);
      String s = in.nextLine();
 
      // your work here
 
      System.out.println(r);
   }
}

PROBLEM 3 (4.16)

Rewrite the following do loop into a while loop.

int n = in.nextInt();
double x = 0;
double s;
do
{
   s = 1.0 / (1 + n * n);
   n++;
   x = x + s;
}
while (s > 0.01);

 

Subject Computer
Due By (Pacific Time) 12/16/2012
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy