Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Week 04: Lab 3 - Introductory Programming in Java Skip navigation Introductory Programming in Java ANU College of Engineering & Computer Science Search query Search ANU web, staff & maps Search COMP6700 Lectures Labs Assignments menu Search query Search ANU web, staff & maps Search Search COMP6700 labs Week 01: Welcome Week 02: Lab 1 Week 03: Lab 2 and HW 1 Week 04: Lab 3 and HW 2 Week 05: Drop-in Lab, HW 3 Week 06: Lab 4 and HW 4 Week 07: Mid-sem Exam Week 08: Free (Anzac Day) Week 09: Lab 5 and HW 5 Week 10: Lab 6 and HW 6 Week 11: Lab 7 and HW 7 Week 12: Lab 8 and HW 8 related sites Wattle Piazza Week 04: Lab 3 Objectives We will define and use methods to program execution of relatively complex tasks in a simple and elegant way. Exercise One (warm up) Write a program which will print out the integers from 1 to 20 along with their halves. Calculate their halves in a separate method. (Remember that your method will have to be declared as being static if it gets called from the main method and it is in the same class as the main method.) Exercise Two Our modern system of determining dates is known as the Gregorian Calendar. Since 1582, this calendar has had leap years. You can determine if a year is a leap year according to the following rules: There were no leap years before 1582. The year is not a leap year unless: It is divisible by 4, then it is a leap year unless: It is divisible by 100 in which case it is not, unless: It is divisible by 400. Write a method: static boolean isLeapYear(int year) which returns true if the year is a leap year, and false otherwise. Pack your solution as a single class program, which apart from the main-method contains the isLeapYear(int). The main must collect a command line argument, convert it to int and then pass it to isLeapYear. Try using two versions of isLeapYear: when it is defined as static (as suggested originally) when the static modifier is removed (how the main body should be changed?) Consider the options of declaring a method static or not: When one is preferable to another? Find someone else who has completed this exercise and test your method against theirs! This exercise has an extension for those who is interested, check the bottom of the page (Warning: it is elementary, but somewhat involved, and it is optional!) Further programming ideas: Doomsday Algorithm Conway’s trick to quickly calculate a day-of-the-week John Conway is a famous mathematician who invented the Game of Life (and many other games and also numbers which are games.) Once Conway was asked how he would calculate what the week day was on a particular date – a well known problem with many answers each too complex to works out in one’s head, without pen and paper. After some pondering, Conway came up with characteristically original solution which was simple enough to be performed mentally. The algorithm is called “Doomsday” because it relies on calculating a particular day of the week (the doomsday) on which certain memorable dates fall, and also because Conway was born on one of these dates (December 26, 1937). The algorithm has since been modified and simplified several times (for details, see the Wikipedia’s Doomsday Rule and elsewhere). The key step is finding the year doomsday (YDD) — the weekdays are counted modulo 7, Sunday = 0, Monday = 1, etc. The flow chart below gives the YDD in a century (so, the last two digits are used): Once the YDD is computed, one should use the doomsday for the date century (CDD: 1800-1899 is Friday, 1900-1999 is Wednesday, 2000-2099 is Tuesday, 2100-2199 is Sunday, others are periodic with 400 year period). The full year doomsday (FYDD) is the sum of CDD + YDD. The dates 4.04 (April 4th), 6.06, 8.08, 10.10 and 12.12 are all doomsdays (their value is given by FYDD). For the given day and month, one can compute the (modulo 7) difference between this day and the closest DD of that year, thus arriving at the answer – the day of week. Try to formalise these rules (research more if necessary), and program the full day-of-week calculator for an arbitrary day (in chosen Gregorian calendar; other calendars are just variation). What day of the week: did the deadliest earthquake ever hit Shaanxi? was Martin Luther born? did women vote for the first time in an election in New Zealand? did Gustav Mahler die? did Neil Armstrong walk on the moon? Check the correctness of your solution by using services of one of the following sites: Day of the Week Calculator CalendarHome.com Updated:  15 Mar 2017/ Responsible Officer:  Head of School/ Page Contact:  Alexei Khorev Contact ANU Copyright Disclaimer Privacy Freedom of Information +61 2 6125 5111 The Australian National University, Canberra CRICOS Provider : 00120C ABN : 52 234 063 906 You appear to be using Internet Explorer 7, or have compatibility view turned on. Your browser is not supported by ANU web styles. » Learn how to fix this » Ignore this warning in future