当前位置:文档之家› JAVA实验指导书-实验一

JAVA实验指导书-实验一

《Java SE程序设计》实验指导手册授课教师:崔毅东实验指导教师:崔毅东教学对象:二年级本科生开课时间:秋季学期北京邮电大学软件学院《Java语言与编程》实验指导书程保中孙艺一、实验一:Java程序编制(基础练习)1、实验目的学生通过使用Java语言进行基本程序的开发,掌握Java通用IDE,练习类的封装使用、Java基本类库的使用、利用UML进行简单建模。

2、实验内容(详细内容见附件一)3、实验环境a)Windowsb)Eclipse 或者 NetBean4、实验要求1) 独立完成实验内容要求2) 熟练使用Java常用 IDE 进行编程3)需要上交源程序文件4) 需要打印实验报告上交(标准格式见附件二)5、实验步骤1) 启动Java常用 IDE。

2)建立project。

3)编辑源程序。

4)编译、链接并执行源程序,看结果是否正确。

5)如果报错或告警,做必要修改,重复3)--5)步骤直到没有错误和告警。

附件一:Project #1 A Math Learning Tool (covers Chapter 2)CSCI 1301 Introduction to ProgrammingArmstrong Atlantic State UniversityDevelop a program that lets a first grader practice additions. The programrandomly generates two single-digit integers and displays a question such as “What is 7 + 9?” to the student, as shown in Figure a. After the student types the answer in the input dialog box, the program displays a message dialog box to indicate whether the answer is true or false, as shown in Figure b.(a) (b) (c) (d)NOTE: Write the program without using conditional statements. Use only thematerials you learned in Chapter 2.(注:写程序,无需使用条件语句。

只使用你在第2章所学的材料。

)Hint: Generate the random number using the System.currentTimeMillis()introduced in Chapter 2.提示:使用系统生成的随机数。

currenttimemillis()介绍2章。

Submit the following items:1.Analysis: Restate the problem in your own words (e.g., what is input, output ifany, what needs to be computed, what data needs to be stored and their type).1.分析:用自己的话重述问题(例如,什么是输入,输出,如果有,需要计算,哪些数据需要存储和类型)。

2.Design: Clearly describe the steps to solve this problem using English or pseudocode.2.设计:清晰地描述用英语或伪代码来解决这个问题的步骤。

3.Coding: Implement the solution in Java.4.Testing: Make sure that the numbers appear random. Submit the screen shots oftwo sample runs.4.测试:确保数字显示随机。

提交两个示例运行的屏幕截图。

Project #2 Tax Table (covers Chapter 3)CSCI 1301 Introduction to ProgrammingArmstrong Atlantic State UniversityThe United States federal personal income tax is calculated based on filing status and taxable income. There are four filing statuses: single filers, married filing jointly, married filing separately, and head of household. The tax rates for 2005 are shown in Table (a)-(d). If you are, say, single with a taxable income of $10,000, the first $7,300 is taxed at 10% and the other $2,700 is taxed at 15%. So your tax is 730 + 2700 * 0.15. Schedule X — Single15%的金额超过7300Schedule Y-1 — Married Filing Jointly or Qualifying Widow(er)Schedule Y-2 — Married Filing SeparatelySchedule Z — Head of HouseholdDevelop a program that prints a tax table for taxable income from $50,000 to$60,000 with intervals of $50 for all four statuses, as follows:写一个计程序,打印应纳税所得税表从50000美元到60000美元的所有四个状态的50个区间taxable Single Married Married Head ofIncome Joint Separate a House50000 9846 7296 10398 850650050 9859 7309 10411 8519...59950 12532 9982 13190 1119260000 12546 9996 13205 11206NOTE: the numbers in the preceding tax table are incorrect intentionally. Youshould print the correct values in the table.Submit the following items:1.Analysis: Restate the problem in your own words (e.g., what is input, output ifany, what needs to be computed, what data needs to be stored and their type).2.Design: Clearly describe the steps to solve this problem using English or pseudocode.3.Coding: Implement the solution in Java.4.Testing: Submit the screen shots for first 20 lines in the tax table.4.测试:在税收表中提交前20行的屏幕截图。

Project #3 Least Common Multiple (covers Chapter 5)CSCI 1301 Introduction to Programming Armstrong Atlantic State UniversityDefinition: The least common multiple (LCM) of two numbers is the smallest number that is a multiple of both. For example, the LCM for 8 and 12 is 24, for 15 and 25 is 75, and for 120 and 150 is 600.Develop a program that prompts the user to enter two integers and finds their least common multiple.开发一个程序,提示用户输入两个整数,并找到它们的最小公倍数。

To find the LCM of two numbers, first create a prime factor table for each number. The first column of the table consists of all the prime factors and the second column tracks the occurrence of the corresponding prime factor in the number. For example, the prime factors for 120 are 2, 2, 2, 3, 5, so the prime factor table for number 120 is shown as follows:2 3 3 1 5 1table[0][0] = 2 table[0][1] = 3 table[1][0] = 3 table[1][1] = 1 table[2][0] = 5 table[2][1] = 1The prime factors for 150 are 2, 3, 5, 5, so the prime factor table for number 150 is shown as follows:2 13 1 5 2table[0][0] = 2 table[0][1] = 1 table[1][0] = 3 table[1][1] = 1 table[2][0] = 5 table[2][1] = 2The LCM of the two numbers consists of the factors with the largest occurrence in the two numbers. So the LCM for 120 and 150 is 553222⨯⨯⨯⨯⨯, where 2 appears three times in 120, 3 one time in 120, and 5 two times in 150.Submit the following items:1. Analysis: Restate the problem in your own words (e.g., what is input, output ifany, what needs to be computed, what data needs to be stored and their type). 2. Design: Clearly describe the steps to solve this problem using English or pseudocode. (Hint: The prime factor table can be represented using a two-dimensional array. Write a method named getPrimeFactors(int number) that returns a two-dimensional array for the prime factor table.)(提示:可以使用一个二维数组表示素因子表。

相关主题