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.
- 浏览: 964742 次
文章分类
最新评论
-
18335864773:
很多公司项目 都在使用pageoffice 来操作word,e ...
用java生成word文档 -
Gozs_cs_dn:
请问下博主, 怎样将sitemesh3.xsd绑定 sitem ...
SiteMesh3配置 -
Rose_06:
springside4.0quick-start.bat报错原因 -
ilemma:
我也是刚参见工作啊,经理让自学这个,有些东西不太懂,能不能发个 ...
Apache Shiro在Web中的应用 -
shanbangyou:
你废了
程序员上班打酱油的方法
java循环
- 博客分类:
- java
- ch01.pdf (8 MB)
- 下载次数: 0
发表评论
-
java冒泡排序对布尔类型进行排序
2015-12-11 23:06 602QQ 928900200 程序代写 java不能对 ... -
java星球机器人建模UML
2014-10-06 22:29 360Your task is to design and imp ... -
代写java程序qq:928900200
2014-06-18 12:46 3学校为全面提升学校教学质量,提高管理水平,决定开发一套小型成 ... -
StringTokenizer类的使用
2013-12-13 15:15 360StringTokenizer是一个用来分隔String的应 ... -
销售管理需求分析
2013-07-03 08:18 4561. 概述 目前,销售管理在企业管理中 ... -
基于jsp+servlet+jdbc的销售管理
2013-07-02 16:32 7源码http://apenny.taobao.com 1 ... -
Java获取请求客户端的真实IP地址
2012-05-07 16:40 867通常通过request.getRemoteAd ... -
java读取excel
2012-03-30 16:56 419import org.apache.poi.hssf.user ... -
基于Myeclipse9.1的spring3.1MVC开发搭建
2011-10-01 14:27 1987(1)配置基础装备。每个符合Java EE规范的web应用程 ... -
myeclipse 9.1 破解成功
2011-09-28 18:06 71469.0 的注册机在windows下 ... -
myeclipse9.1下载及破解方法-破解版
2011-09-26 11:17 16660MyEclipse 9.1 下载 注册 破 ... -
JDBC4.1更新了两个新特性
2011-05-20 10:23 9741. Connection,ResultSet 和 State ... -
Java replaceAll的陷阱之括弧
2011-05-09 16:26 4464大家都知道,replaceAll这个东西支持regular e ... -
Archive for 四月, 2011JavaEye被逼改名ItEye
2011-04-02 08:50 580Oracle挥舞法律大棒 JavaEy ... -
test
2011-04-02 08:34 395<script type="text/Java ... -
开源文档学习
2011-03-31 17:29 485http://www.family168.com -
myeclipse 8.6 M1 注册码
2011-03-31 10:13 1000Subscriber:MaYong Subscription ... -
java web 开源框架
2011-03-31 09:49 955WebWork WebWork是由O ... -
js 画线
2010-06-06 12:42 3067本例子用wz_jsgraphics.js进行画矢量图,兼容多浏 ... -
google 谷歌 吃豆人 pacman
2010-05-26 12:12 1243原则上Google的Doodle只有 ...
相关推荐
Java 循环语句练习题.docx
Java循环练习
Map a = new HashMap(); //方法一 Iterator it = a.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); System.out.println(pairs.getValue()); ...//以下方法需要jdk5以上...
JAVA循环 练习题
java循环队列的分析和实例介绍.pdf
典型的JAVA循环语句,包括数组循环,遍历循环等
Java循环解析xml文档,放在hashtable里,方便安装标签名取值
练习Java循环的一些源代码例子 练习Java循环的一些源代码例子
17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java循环语句.zip17.java...
Java循环读取1指定目录下的文件.docJava循环读取1指定目录下的文件.docJava循环读取1指定目录下的文件.docJava循环读取1指定目录下的文件.docJava循环读取1指定目录下的文件.docJava循环读取1指定目录下的文件.doc...
java循环结构学习教案.pptx
Java循环结构习题.pdf
Java循环语句学习例子源码程序,这是一个Visita风格的登录界面,但一位Java高手将它用JAVA技术编写了出来,看上去非常精致,模仿的也很像。
java循环用法java循环用法java循环用法java循环用法
一个简单的会员积分录入循环模式,供初学者借鉴。
JAVA循环结构
Java循环练习题
java循环结构,while、for循环、do-while,及调试解决程序错误
Java 语言练习。让你更透彻的掌握循环的精髓。好好努力吧。
java写的读取图片代码,循环读取可以调节贞数,觉得效果还行,就放上来了!