ITP109_Lab3 - binary number from the keyboard as a string...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
ITP 109 Lab 3 Goal In this lab, you will write a program that contains 2 parts - Vending Machine and Binary to Decimal Conversion . You will practice using variables, constants, the Scanner class to get keyboard input, division and mod operators, the substring method of the String class, the parseInt method of the Integer class, and comments. Assignment The first part of your program is to determine the change to be dispensed from a vending machine . An item in the machine can cost between 25 cents and 1 dollar, and the machine accepts only a single dollar bill to pay for the item. You need to figure out the change that will be dispensed in quarters, dimes, nickels, and pennies. Use the division and mod operators to figure out the change. Use constants for 100 (DOLLAR), 25 (QUARTER), 10 (DIME), and 5 (NICKEL). The second part of your program is to read in a four-bit
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: binary number from the keyboard as a string and then convert it into decimal . For example, if the input is 1100, the output should be 12. – Break the string into substrings (using the String.substring method). – Convert each substring to an int value for a single bit (using the Integer.parseInt method). – If the bits are b , b 1 , b 2 , and b 3 , the decimal equivalent is 8b + 4b 1 + 2b 2 + b 3 . Use constants for 8, 4, and 2. • Create your program using Eclipse. Your project should be named Lab3 , and your Java class should be named Lab3 . • Use the Scanner class to get input from the user, and use System.out to print to the console window. • Make sure to comment your code, especially the two parts. Grading - 15 points total • 5 points: Vending Machine • 5 points: Binary to Decimal Conversion • 5 points: Comments, style, and proper submission...
View Full Document

This note was uploaded on 10/15/2008 for the course ITP 109x taught by Professor Trinagregory during the Spring '08 term at USC.

Ask a homework question - tutors are online