Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Operating System Expert

CS 1063 Lab 2: Counting Coins and Making Change

The Coins Class

Objectives

Use methods.
Use local variables.
Use arithmetic expressions.
Use Scanner to input values.
Use a class constant.
Hand-in Requirements
All projects and laboratories will be submitted electronically through Blackboard. Zip up your entire lab directory to submit as the source. (Right click on the lab folder and follow Send To > Compressed (zipped) Folder or 7-Zip > Add to "lab2.zip"). The lab folder should include the following:

Coins.java
CoinsOutput.txt
Tasks

prepare a program that prints

Lab 2 written by YOURNAME
and calls two methods:
Input the number of quarters, dimes, nickels, and pennies from the user. Print out the number of coins and total value in dollars.
Input the number of cents from the user. Determine and print out the number of quarters, dimes, nickels, and pennies to add up to that number of cents. No, you can't use all pennies.
Details

Getting Input from the User

You can get input from the user using a Scanner object. Here is an ex program with key lines in bold.

import java.util.*;

public class HalfDollar {
public static final Scanner CONSOLE = new Scanner(System.in);

public static void main(String[] args) {
halfDollarAmount( );
}

public static void halfDollarAmount( ) {
System.out.print("Enter the number of half dollars: ");
int halfDollar = CONSOLE.nextInt( );
double amount = halfDollar * 0.50;
System.out.println(halfDollar + " half dollars is $" + amount);
}
}
The import statement tells Java that we want to use Java's java.util package (Scanner is part of this package).

The statement:

public static final Scanner CONSOLE = new Scanner(System.in);
declares a special kind of variable (a class constant) named CONSOLE of type Scanner and stores an "object" for input from the keyboard in CONSOLE. CONSOLE can be used anywhere in the class.
The first two statements of the halfDollarAmount method:

prompt the user for information, and
input a number from the keyboard and stores the number in a variable named halfDollar.
You only need the declaration/assignment for CONSOLE once in the class. On the other hand, you need prompt and input statements for each value you want the user to enter.

Local Variables

You should have local variables for each value that is entered and each value that you find out. For ex, for the first method there should be a local variable that stores the total dollar amount of the change, as well as a local variable for the total number of coins.

Making Change

For the second method, we can use integer division and the mod operator to make change. Suppose the user enters 99 as the number of cents. The sequence of calculations should be as follows.

The integer division 99 / 25 can be used to determine the number of quarters (3).
Using the mod operator 99 % 25 determines the remaining number of cents to be converted into change (24).
Integer division 24 / 10 can be used again to determine the number of dimes (2).
The mod operator 24 % 10 can be used again to determine the remaining amount (4).
Next, for nickels, integer division 4 / 5 for the number of nickels (0) and a mod operation 4 % 5 for the remaining amount (4).
Whatever is left is the number of pennies (4).
Of course the values that were find outd (3, 24, 2, 4, 0, 4) would be different if the user enters something different from 99. This means we should have variables to store all of these values. For ex, we might have a variable named cents to hold the value that the user entered, a variable named remainingAfterQuarters for the remaining amount after the quarters are determined, which could be assigned by:

int remainingAfterQuarters = cents % 25;
Output File

Include the output of your program in a file named CoinsOutput.txt.

Rubric

Your program should compile without any errors. A program with more than one or two compile errors will likely get a zero for the whole assignment.

The following criteria will also be used to determine the grade for this assignment:

[1 Point] If the main method of your program prints "Lab 2 written by [...]".
[1 Point] If your submission was a Zip file named lab2.zip containing a folder named lab2, which contains the other files.
[1 Point] If your Java program was in a file named Coins.java.
[1 Point] If the output of your Java program was in a file named CoinsOutput.txt.
[1 Point] If your program contains a comment that describes what the program does and contains a comment for each method.
[1 Point] If your program is indented properly.
[7 points] If your main method calls a method that does the following:
[3 Points] If it prompts the user for the number of quarters, dimes, nickels, and pennies.
[4 Points] If it prints out the total number of coins and their value in dollars.
[7 points] If your main method calls another method that does the following:
[3 Points] If it prompts the user for the number of cents.
[4 Points] If it prints out the number of quarters, dimes, nickels, and pennies necessary to add up to that number.
Revision Date Tue Sep 13 2011 16:03:26 GMT-0500 (CDT) 

Operating System, Computer Science

  • Category:- Operating System
  • Reference No.:- M989552

Have any Question?


Related Questions in Operating System

State the required answer precisely and then provide proper

State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. Consider a computer embedded in the control of a manned spacecraft. Would it require an ...

Question 1answer the following questions 10 marks a

Question 1 Answer the following questions: 10 marks a. Consider the following page reference string: 3, 1, 4, 1, 2, 3, 5, 3, 2, 1, 2,5, 4, 3, 5, 2, 4,2, 5,3 Using the above page reference string display the contents of t ...

Discussion question this research assignment will give

Discussion Question : This research assignment will give further information on the nature and workings of multi-tasking and multi-processing operating systems. All information reported in this assignment is to be in the ...

Question state the required answer precisely and then

Question : State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. What is the purpose of the command interpreter? Why is it usually separate fr ...

Question students working at individual pcs in a computer

Question : Students working at individual PC's in a computer laboratory send their files to be printed by a server that spools the files on its hard disk. Under what conditions may a deadlock occur if the disk space for ...

Question research hex editors available for mac os and

Question : Research hex editors available for Mac OS and Linux. Based on the documentation, how easy would validating these tools be? Select at least two hex editors for each OS, and discuss what you would do to validate ...

Question topic computerized operating systems os are almost

Question: Topic: Computerized Operating Systems (OS) are almost everywhere. We encounter them when we use out laptop or desktop computer. We use them when we use our phone or tablet. Find articles that describes the diff ...

Research types of operating systems that are currently

Research types of operating systems that are currently available and provide a scenario in which the operating system you chose would be appropriate to be used in this situation. Explain why you think the choice you made ...

State the required answer precisely and then provide proper

State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. Briefly describe the following concepts and indicate how they are related in the context ...

Question you are a security administrator responsible for

Question: You are a security administrator responsible for providing secure configuration requirements for new laptop deployments. After reading Module 2 of Certified Secure Computer User v2exercises, apply the configura ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As