Question

Lab 2​​ ​CISC 1115 Start a new Java program. It should begin by printing, as part...

Lab 2​​ ​CISC 1115
Start a new Java program. It should begin by printing, as part of the output (in addition to the comment at the beginning of your code, a header for the lab (or homework) that looks like the following:
--------------------------------------------------------------------------
Your name​ Due Date
CISC 1115 MY11 ​ Lab2
--------------------------------------------------------------------------
Write a program that will read a double from the keyboard, which represents a dollar and cents amount, such as 7325.67, and prints out:
7325.67 is 7 thousand 3 hundred 2 tens 5 dollars and 67 cents
Input of 123 54 would print
123.54 is 0 thousand 1 hundred 2 tens 3 dollars and 54 cents
Or, for input of 100.00 the program will print
100.0 is 0 thousand 1 hundred 0 tens 0 dollars and 0 cents
Input of 12.54 would print
12.54 is 0 thousand 0 hundred 1 tens 2 dollars and 54 cents
Another example,
0.54 is 0 thousand 0 hundred 0 tens 0 dollars and 54 cents
One way to do this is to use casting, integer division and the mod operator (%) as we will discuss in the lecture but feel free to go your own way.
One set of code should work for any amount read in as a double. Assume the input amount is never greater than 99999.99
Print the code and run a number of examples like those above.

Having trouble understanding this, please help. Thank you!!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ConvertDollar.java

import java.util.Scanner;


public class ConvertDollar {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter a dollar and cents amount:");
       double n = scan.nextDouble();
       int amount = (int)(n * 100);
       int thousand = amount/100000;
       amount = amount % 100000;
       int hundred = amount/10000;
       amount = amount % 10000;
       int tens = amount/1000;
       amount = amount % 1000;
       int dollars = amount/100;
       amount = amount % 100;
       int cents = amount;
       System.out.println(n+" is "+thousand+" thousand "+hundred+" hundred "+tens+" tens "+dollars+" dollars and "+cents+" cents");
   }

}

Output:

Enter a dollar and cents amount:
7325.67
7325.67 is 7 thousand 3 hundred 2 tens 5 dollars and 67 cents

Add a comment
Know the answer?
Add Answer to:
Lab 2​​ ​CISC 1115 Start a new Java program. It should begin by printing, as part...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input...

    CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input to Program: A file containing lines of data, such that each line has 2 integers on it The first integer represents a zip code (in Brooklyn or the Bronx), and the second represents the number of voters in that zip code. Output: All output may be displayed to the screen. In main: 1. Your program will read in all of the data in the...

  • CSCI 161 - Lab 2: "Give Me a Second!" Overview This lab will have you developing...

    CSCI 161 - Lab 2: "Give Me a Second!" Overview This lab will have you developing a program that asks the user to input a time period as a number of seconds and in turn calculates the whole number of days, hours and minutes that are contained within the entered time period. Refer to the "Output Format" below for an example of what your program must do. The objectives of this lab are to reinforce and help teach: proper Java...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • Java programming Create a simple tip calculator called TipCalcMethod. Your program should read in the bill...

    Java programming Create a simple tip calculator called TipCalcMethod. Your program should read in the bill amount from the command-line, then show 3 tip amounts: 15%, 20% and 25% of the bill. Don't worry about rounding the result to two decimal places, but make sure that the result includes cents (not just dollars). This program will be different than your first Tipcalc program because you will writea method to calculate the tip amount. program will have 2 methods: main) and...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT