首页 技术 正文
技术 2022年11月6日
0 收藏 496 点赞 1,107 浏览 3096 个字

Computer Science, Claremont McKenna College
CS51.2 – Introduction to Computer Science, Fall 2014
Problem Set 2 Due: 11:55 AM, Sept 18, 2014
General Instructions
Please carefully read and follow the directions exactly for each problem. Files and classes should be
named exactly as directed in the problem (including capitalization!) as this will help with grading.
You should create your programs using your preferred text-editor, the Eclipse text editor, or jGrasp. Do
not use a word processor such as Microsoft Word, WordPad, Google Docs, Apple’s Pages, etc…
Your programs should be formatted in a way that’s readable. In other words, indent appropriately, use
informative names for variables, etc… If you are uncertain about what is a readable style, look at the
examples from class as a starting point for a reasonable coding style.
This problem set assumes you have installed Java and an IDE (Eclipse or jGrasp) on your system. Please
see the course web page on Sakai for installation instructions.
Your programs should compile and run without errors. Please do not submit programs that do not
compile! It’s better to submit partial implementation that compiles as oppose to implementations that do
not compile.
At the top of each file you submit, you should put your name and your email as comments.
This homework set should be submitted via Sakai using the Assignment Menu option (on the left pane).
You should only submit the requested “.java” files. Do not submit “.class” files or Eclipse-specific
project files. Finally, please do not submit files using Sakai’s Dropbox Menu.
Turn in the following file(s):
MilesToFeet.java
DollarsToBills.java
DollarFigure.java
FactorialLoop.java
Problem 1
In this warmup problem, write a program in MilesToFeet.java that converts a specified number of
miles into number of feet. Declare a variable named numMiles that’s initialized to 11.3. Declare
another variable named numFeet. Think about what type these variables should be. You should then
perform the conversion from miles to feet and assign the value to numFeet. Print something informative
such as “X miles is Y feet.”
Problem 2
Write a program in DollarsToBills.java that converts a specified number of dollars into the
number of twenty dollar bills, the number of ten dollar bills, the number of five dollar bills, and the
number of one dollar bills. In doing this conversion, you should first maximize the number of twenty
dollar bills, then maximize the number of ten dollar bills, etc… Declare a variable named nDollars
and assign 99 to it. Declare a variable named nTwenty to hold the number of twenty dollar bills,
nTens to hold the number of ten dollar bills, nFives to hold the number of five dollar bills and nOnes
to hold the number of one dollar bills. Think about what type these variables should be. (You may use
other variables as needed.) Print out the conversion with meaningful annotation such “99 dollars is equal
to 4 twenties, 1 tens, …”
Problem 3
In a file named DollarFigure.java , write a program that uses for loops to produce the following:
$$$$$$$**************$$$$$$$
**$$$$$$************$$$$$$**
****$$$$$**********$$$$$****
******$$$$********$$$$******
********$$$******$$$********
**********$$****$$**********
************$**$************
Problem 4
Using nested for loops, write a program in FactorialLoop.java that calculates and then prints out
the factorial of the numbers from 3 to 9 (inclusive). Print out the factorials in the following form:
3 factorial is equal to 6
4 factorial is equal to 24
etc…
Consider using a variable to track the intermediate “running” factorial result as the factorial is being
calculated in a loop.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295