java 初级练习题(英文版).pdf_第1页
java 初级练习题(英文版).pdf_第2页
java 初级练习题(英文版).pdf_第3页
java 初级练习题(英文版).pdf_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

IS200 IS Software Foundations IS200 2010 11 LabX doc Page 1 of 5 LabX The Lab that never happened Objectives 1 Get java fundamentals right 2 Solve problems logically with java 3 Have FUN Create a directory in your working drive say D named is200 In that create a directory named labX D is200 labX Note We will follow this convention throughout this lab Let s start with the simple stuff 1 Write a program that takes in the value of age and heart beat rate from the user and print out the number of heart beats his or her heart has made throughout his life Here is a sample output of the program Age in years is 20 Heart rate beats per minute is 90 The number of heart beats is 946080000 Note You might have to use a long variable to store the result for number of heart beats Note the difference in the result of heart beats by inputting the value of 50 in variable age that is declared as int and in variable age that is declared to be long 2 Write a program that takes in 2 values one min and one max and then print out the values of prime numbers between these 2 values I leave it to you to decide if you want to include the printing of min and max If there are no prime values between the range of numbers it should not print out anything other than maybe your min and max value Min 1 Max 10 Prime nums 2 3 5 7 IS200 IS Software Foundations IS200 2010 11 LabX doc Page 2 of 5 Let s bring it up to the next level 1 Book Loan In this question we would try to emulate automated book borrowing process http blue smu edu sg issf week3 Go to this web link and look at the Book API once again Please code out this API in java to practice your API reading skills In the same web link you would also see a Student API Please code out the Student class but with some changes Add in this constructor The student object can be created by taking in the value of his name age and also the book referring to the book class above which he borrowed Hint This means you need one more parameter in your 4th constructor Add in methods getBook returns the book object which the student borrowed setBook Book book sets the book which the student borrowed Write a program that takes in the title of the book number of pages of the book and the price of the book Thus then create a book object The same program then takes in the name of the student age of the student Created the student object and assign the book to him Hint You can either construct the student with the book as a parameter or use the setBook method What are the pros and cons of using these 2 ways of assigning After this is done create a loan receipt showing the student s name and the book which he borrowed How you want to design the user interface UI is entirely up to you All I want to see is how do your program ask the user for their inputs and how you display the loan receipt Be as creative as you like and impress me Best UI gets a prize from Kelvin Leong 2 Book Loan Part II IS200 IS Software Foundations IS200 2010 11 LabX doc Page 3 of 5 Your library has found out that most of the books get damaged when people who are younger than 10 years old borrow them Thus then you set the age limit to 10 years old In your program check for the age of the student before generating the loan receipt If the person is too young please display a message to tell the user that his or her age is too young to borrow books at your library 3 Book Loan Part III Your library received more troubling news Some of the teenagers tried to mess with your system by keying in the wrong type of data at the wrong fields E g He tried to key in his name at the part where you asked for his age causing the application to throw an error because the program was expecting an int not a String Rewrite your program to display to the user what is the expected type of input from the user This is only displayed after the user tries to be funny with your application E g please key in your age in numerals The program should not end but rather keep prompting the user for the right type of input Some Brain teasers 1 Pascal Triangle Write a program that takes in a number which represents the number of rows of the Pascal triangle Display the Pascal triangle Sample Hint this program does not use any Collection classes nor arrays IS200 IS Software Foundations IS200 2010 11 LabX doc Page 4 of 5 2 To verify the accuracy and validity of credit card numbers most credit card numbers are encoded with a check digit A check digit is a digit added to a number either at the end or the beginning that validates the validity of the number A simple algorithm is applied to the other digits of the number which yields the check digit The steps for validation are as follows i The digits in the even position starting from the right are multiplied by 2 and then reduced to a single digit by subtracting 9 ii Add the individual digits comprising the products obtained in step i to each of the unaffected digits in the original number iii The total obtained in step ii must be divisible by 10 For example given the number 2323 2005 7766 3554 this is how step i is performed In step ii the following numbers are added together 4 3 4 3 4 0 0 5 5 7 3 6 6 5 1 4 which yields the answer 60 Because 60 is divisible by 10 this credit card number is a valid one Multiply by 2 Subtract 9 if value 10 1st digit 2 2 2 4 4 2nd digit 3 3rd digit 2 2 2 4 4 4th digit 3 5th digit 2 2 2 4 4 6th digit 0 7th digit 0 0 2 0 0 8th digit 5 9th digit 7 7 2 14 14 9 5 10th digit 7 11th digit 6 6 2 12 12 9 3 12th digit 6 13th digit 3 3 2 6 6 14th digit 5 15th digit 5 5

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论