Java Assignment + easy exercise 2
Content/assignments/assignment1.html
COMP 1020
Material covered: Please ensure that you: Part A: Airline seating Part B: Date book
- Review of COMP 1010 (arrays and simple strings) in Part A
- Creating basic classes and objects in Part B
- Using arrays of objects in Part B
- solve all problems with programs written in the Java programming language;
- follow the programming standards;
- submit a separate complete program for each part that can be saved in a single Java source code file, and compiled and executed without any other Java files; and
- submit your solution to both parts of the assignment by the assignment due date.
If you submit a solution that does not meet these requirements (for example, if the program does not run), you will lose some or all marks.
Part A: Airline seating [10 marks]
Millions of commercial airline flights cross the world's cities every year, and each one of these flights must solve what seems like a simple problem: how do you arrange where each passenger on one of those flights sits? In this assignment, we will solve a variation on that problem, where we will observe one restriction on the seats: people who book a flight together will be — if possible — seated together.
Your program will process data from an array of strings (call this the "bookings" array). The first array element will contain a number indicating how many seats the aircraft has. The remaining elements will contain information about groups of passengers who have booked seats on the flight. The first element of this grouping will be a number that indicates how many people are in the group. The remaining elements identify the individual passengers in that group by their last and first name. For example, the array might contain the following 10 strings:
8 2 Nobbly, Greg Nobbly, Jo-Anne 1 Lee, Sook 3 Lukas, Stephie Lukas, Cambridge Lukas, Ogden
which means there are 8 seats on the flight, the first group of passengers has 2 people (with their names below), the second group has 1 person, and the third group has 3 people.
Normally this data would come from input, such as lines from a text file, not from an array. That's the next assignment.
The seating chart for the flight will be stored in an array of strings (call this the "seats" array), whose size is equal to the number of seats on the flight. Each position in the array corresponds to a seat on the flight; the first element in the array is seat 1, the second element is seat 2, etc. Initially all the seats are empty. Passengers will be seated by placing their name in this array.
Your program will seat passengers as follows:
- It will create a "seats" array of the appropriate size (given in the first position of the "bookings" array).
- It will process the remaining items in the "bookings" array of strings. For each group of passengers it will attempt to seat them as follows:
- First, it will see if there are enough seats remaining on the flight for everyone in the group; if not, it will display an error message and not assign seats to anyone in the group.
- Secondly, it will go through the "seats" array to determine if a block of empty seats large enough to seat the entire group together is available (for example, if the group size is 3, it will see if there are 3 consecutive empty seats).
- If there is at least one such block of seats anywhere in the array, randomly assign the group to one of these blocks by randomly selecting an element in the "seats" array. If that seat is empty, determine if enough successive array elements (seats) are also empty to seat the entire group; if so, seat them there. Otherwise, randomly try another seat, repeating until successful. (Note that this is not the most efficient approach...)
- If there is no such block, randomly assign each passenger in the group individually to a seat (i.e., the group will be split up). For each passenger, pick random seat numbers until you find an empty seat.
When the seats for the flight have been assigned, print the contents of the "seats" array (neatly) to the display. Show both filled and empty seats, describing empty seats as "empty" (do not display the word "null"). Label each line of output with the seat number, where the first seat on the aircraft is seat 1.
Note that using the algorithm above, passengers never move once their seat has been assigned. A group may be split up due to the result of the randomly chosen seat locations. For example, the sample data above may result in the following output:
Seat 1: Lukas, Ogden Seat 2: Lee, Sook Seat 3: -empty- Seat 4: Lukas, Stephie Seat 5: Nobbly, Greg Seat 6: Nobbly, Jo-Anne Seat 7: -empty- Seat 8: Lukas, Cambridge
Because the seat assignments for the first two groups left no block of three seats empty, each person in the third group had to each be assigned a random seat. If the first two groups had been seated differently, the third group may have been able to sit together.
Your main program will seat three flights. Each flight will be described by a "bookings" array that you will pass to a method that processes the array and determines the flight seating. Call the method three times in your main program, once for each "bookings" array. Display the seating plan for each flight under an appropriate title. Note that your main program should include only declarations, assignments, method calls, and output statements (no loops or other control structures); all the processing should be performed within other methods.
This is programming standard number 18, and should be followed in all your assignments, not just this one.
First, seat the flight containing the sample data shown above (eight seats, three groups). Next, create and seat your own booking array: give the flight 12 seats, and exactly five groups containing a total of 12 passengers. Make up the passenger names. Finally, download the class Bookings.class; inside is a method public static String[] getBookings() which will return an bookings array that you should seat.
A classic computer application is the electronic date book: a list of daily events stored in a calendar. Write a Java program that can be used as a simple date book. The date book will use a separate array for each month of the year, with one array entry for each day in the month (0 = first day of the month, 1 = second day of the month, etc.). The date book is "simple" because at most one event will be allowed on each day.
Your program should include an Event class that will be instantiated for each event in the date book. The Event class consists of three instance variables: the starting time of the event (a String), the name of the event (a String), and the priority of the event (an integer value in the range 1-3, with 3 being the highest priority). Make all your instance variables private and write appropriate instance methods for processing them, including a constructor, toString(), and any others needed by your program.
Each month in the date book will be stored as an array of Events. Days with an event will point to the appropriate Event object, and days without will contain null.
Your program will produce three types of output (three views) for each month:
- A calendar view, listing the days of the week (Sunday to Saturday) horizontally across the top, and the days of the month underneath. Next to each day where there is a scheduled event, print an asterisk "*". Like in a real calendar, the first day of the month can be any of the weekdays.
- A list of events, showing the day of the month and the details of the event (using toString). These can be displayed in the order that they occur during the month. Do not display lines of output for days without events.
- A list of the highest-priority events (those with priority 3). List only the names of the events, not the starting time or priority.
For example:
Sun Mon Tue Wed Thu Fri Sat
1 2* 3 4 5 6
7 8 9 10 11* 12* 13
14* 15* 16* 17 18 19* 20
21 22 23 24 25* 26* 27
28* 29 30
Events:
2: 4:00 PM: Event #8 (priority 3)
11: 2:00 PM: Event #10 (priority 1)
12: 5:00 PM: Event #7 (priority 3)
14: 10:00 PM: Event #2 (priority 1)
15: 6:00 PM: Event #6 (priority 3)
16: 7:00 PM: Event #5 (priority 2)
19: 3:00 PM: Event #9 (priority 2)
25: 9:00 PM: Event #3 (priority 1)
26: 11:00 PM: Event #1 (priority 3)
28: 8:00 PM: Event #4 (priority 1)
High-priority events:
2: Event #8
12: Event #7
15: Event #6
26: Event #1
Write a separate static method to generate each view. Test your program as follows:
- Create two arrays of Events, september and october; the first has 30 entries, the second 31.
- Place 10 events at random locations in each array. Write one method to do this, and call it twice (i.e. the two arrays will contain the same ten events on different days). Make up reasonable values for the names and starting times of the events: make them all recognizably different and meaningful (not just "Event 1", "Event 2", etc.). The method should choose a random number between 1-3 for event priority.
- Display the complete output (all three views) for September. Choose the first day of the month randomly (pick a random number 0-6 where 0 is Sunday).
- Display the complete output (all three views) for October. The first day of the month will be (the first day of September + 30) mod 7: that is, it will continue after September's last day.
Make sure to title both parts of your output (September and October) clearly. Remember from COMP 1010 that you can choose a random number between 1 and n using (int)(Math.random() * n) + 1.
Content/css/comp_1020_new.css
@charset "utf-8"; /* CSS Document */ body {height: auto;margin-top: 10px; margin-left: 25px; margin-bottom: 10px;} #container { width: 780px; height:468px; padding-left: 47px; padding-top: 50px; padding-right: 35px; margin: auto; background-image: url(unit1.jpg); left: 38px; } #containersmall { width: 780px; height:468px; padding-left: 47px; padding-top: 0px; padding-right: 35px; margin: auto; background-image: url(unit1.jpg); left: 38px; } #banner { width:800px; height:100px; } .h1 { font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-style:normal; font-weight:bold; color:#7eae37; margin-bottom:-10pt; } .h1b { font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#000000; } .h1w { font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#006699; } .h2 { font-family:Arial, Helvetica, sans-serif; font-size:13pt; font-weight:bold; color:#244062; font-style:normal; position: relative; background-color: #FFFFFF; } .h2b { font-family:Arial, Helvetica, sans-serif; font-size:12pt; font-weight:bold; font-variant:small-caps; color:#999966; font-style:normal; } .h3 { font-family:Arial, Helvetica, sans-serif; font-size:11.5pt; font-style:normal; font-weight:bold; color:#244062; margin-bottom:-7pt; } .h3b { font-family:Arial, Helvetica, sans-serif; font-size:16pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#336699 } #page { width:780px; height:994px; left: 7px; top: 166px; padding-left: 10px; padding-right: 10px; } .body { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; font-style:normal; font-weight:normal; color:#000000; line-height:14pt; } .body_box { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; font-style:normal; font-weight:normal; color:#000000; line-height:14pt; } .body_bold { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; font-style:normal; font-weight:bold; color:#006699 } .body_bold_box { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; font-style:normal; font-weight:bold; color:##006699 } .body_dr_green { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#336600 } .definition { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:italic; font-weight:normal; border-width:.25pt; border-style:solid; border-color: #CCCCCC; border-collapse:separate; empty-cells:hide; } .toc { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#669933 } a:link {color:#0000FF; text-decoration:underline; font-family:Arial, Helvetica, sans-serif;} a:visited {color:#0000FF; text-decoration:underline;font-family:Arial, Helvetica, sans-serif;} .top { font-family:Arial, Helvetica, sans-serif; font-size:8pt; font-style:normal; font-weight:normal; } p.ind { text-indent:-20px; margin-left:20px; font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#000000 } .quote { margin-left:40px; margin-right:40px; font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#000000 } .blackBox { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; background-color:#FFFFFF; border: 1.5px solid #000; padding-top: 10px; padding-left: 15px; padding-right: 5px; padding-bottom: 10px; margin-right: 200px; margin-left: 3px; } .blueBox { background-color: #daeef4; border: 1.5px solid #FFF; padding-top: 10px; padding-left: 15px; padding-right: 5px; padding-bottom: 10px; margin-left: -10px; margin-right: -15px; } .yellowBox { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; background-color: #FFFF99; border: 1.5px solid #FFF; padding-top: 10px; padding-left: 15px; padding-right: 5px; padding-bottom: 10px; margin-left: -10px; margin-right: -15px; } .blackBorder { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; background-color: #FFFFFF; border: 1.5px solid #00000; padding-top: 10px; padding-right: -17px; padding-bottom: 14px; margin-right: 200px; margin-left: 3px; } .blackBorderwy { font-family:Arial, Helvetica, sans-serif; font-size:10.5pt; background-color: #FFFFCC; border: 1.5px solid #00000; padding-top: 10px; padding-right: -17px; padding-bottom: 14px; margin-right: 200px; margin-left: 3px; } .blueBorder { background-color: #FFFFFF; border: 1.5px solid #669966; padding-top: 10px; padding-right: -17px; padding-bottom: 14px; margin-right: 200px; margin-left: 3px; } .biol_head { font-family:Arial, Helvetica, sans-serif; font-size:12pt; font-style:normal; font-weight:bold; color:#FFFFFF; } .body_white { font-family:Arial, Helvetica, sans-serif; font-size:9pt; font-style:normal; font-weight:normal; color:#FFFFFF } .body_white_bold { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:bold; color:#FFFFFF }
Content/css/COMP1020.css
@charset "utf-8"; /* CSS Document */ body {margin-top: 10px; margin-left: 25px; margin-bottom: 10px;} #container { width: 780px; height:591px; padding-left: 47px; padding-top: 50px; padding-right: 35px; margin: auto; } #banner { left:25px; top: 10px; width:800px; height:100px; padding-bottom: 30px; } .heading_banner { margin: 0px 0px 0px 0px; padding: 20px 0px 0px 30px; font-size: 34px; font-weight: 400; font-family: Arial, Helvetica, sans-serif; color: #FFF; height: 100px; width: 90%; line-height: 1.1em; opacity: 0.75; letter-spacing: 0.05em; position:absolute; } .h1 { font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#336600; margin-bottom:-9pt; } .h1b { font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#000000; } .h1w { font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#FFFFFF; } .h2 { font-family:Arial, Helvetica, sans-serif; font-size:12pt; font-weight:bold; font-variant:small-caps; color:#336600; font-style:normal; position: relative; margin-bottom:3pt; } .h2b { font-family:Arial, Helvetica, sans-serif; font-size:12pt; font-weight:bold; font-variant:small-caps; color:#336699; font-style:normal; } .h3 { font-family:Arial, Helvetica, sans-serif; font-size:16pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#336600; margin-bottom:-7pt; } .h3b { font-family:Arial, Helvetica, sans-serif; font-size:16pt; font-style:normal; font-weight:bold; font-variant:small-caps; color:#336699 } .body { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#000000; } .body_bold { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:bold; color:#000000 } .definition { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:italic; font-weight:normal; border-width:.25pt; border-style:solid; border-color: #CCCCCC; border-collapse:separate; empty-cells:hide; } a:link {color:#336699; text-decoration:underline; font-family:Arial, Helvetica, sans-serif;} a:visited {color:#669933; text-decoration:underline;font-family:Arial, Helvetica, sans-serif;} .top { font-family:Arial, Helvetica, sans-serif; font-size:8pt; font-style:normal; font-weight:normal; } p.ind { text-indent:-20px; margin-left:20px; font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#000000 } .quote { margin-left:40px; margin-right:40px; font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:normal; color:#000000 } .blueBox { background-color: #336699; border: 1px solid #336699; padding-top: 10px; padding-right: 5px; padding-bottom: 10px; padding-left: 10px; } .blueBorder { background-color: #FFFFFF; border: 1px solid #336699; padding-top: 10px; padding-right: 5px; padding-bottom: 10px; padding-left: 10px; } .biol_head { font-family:Arial, Helvetica, sans-serif; font-size:12pt; font-style:normal; font-weight:bold; color:#FFFFFF; } .body_white { font-family:Arial, Helvetica, sans-serif; font-size:9pt; font-style:normal; font-weight:normal; color:#FFFFFF } .body_white_bold { font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-style:normal; font-weight:bold; color:#FFFFFF } .Highlight { background-color: #FFFF00; border: solid thin black; margin-top: .5em; margin-bottom: .5em; margin-right: 20px; margin-left: 20px; padding-top: .5em; padding-bottom: .5em; padding-left: 1em; padding-right: 1em; } .Aside { background-color: lightGrey; border: solid thin black; margin-top: .5em; margin-bottom: .5em; margin-right: 20px; margin-left: 20px; padding-top: .5em; padding-bottom: .5em; padding-left: 1em; padding-right: 1em; } .Action { background-color: #FFFFC0; border: solid thin black; margin-top: .5em; margin-bottom: .5em; margin-right: 20px; margin-left: 20px; padding-top: .5em; padding-bottom: .5em; padding-left: 1em; padding-right: 1em; } .key { background-color: #a9a9a9; color: white; border: solid thin black; font-style: italic; } .menu { background-color: #a9a9a9; color: white; border: solid thin black; } .version { color: olive; font-style: italic; } code { font-family: "Lucida Sans Typewriter", Courier, monospace; color: #222200; background-color: #FFFFE0; } .code { font-family: "Lucida Sans Typewriter", Courier, monospace; background-color: #FFFFB0; border-top: dotted thin black; border-bottom: dotted thin black; padding-top: 1em; padding-bottom: 1em; padding-left: .5em; padding-right: .5em; margin-right: 20px; margin-left: 20px; } .Aside .code { margin-right: 10px; margin-left: 10px; } pre.code { white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */ white-space: -pre-wrap; /* Opera 4 - 6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: pre-wrap; /* CSS3 - Text module (Candidate Recommendation) http://www.w3.org/TR/css3-text/#white-space */ word-wrap: break-word; /* IE 5.5+ */ } dfn { font-weight: bold; color: brown; } .Example { background-color: aqua; border: solid thin black; margin-top: .5em; margin-bottom: .5em; margin-right: 20px; margin-left: 20px; padding-left: .5em; padding-right: .5em; } .ref { color: red; font-style: italic; } .filename { font-family: Arial, Helvetica, sans-serif; color: green; text-decoration: underline; } .output { font-family: "Lucida Sans Typewriter", Courier, monospace; color: purple; font-style: italic; } table.bordered { border-width: thin; border-style: solid; border-spacing: 0; } table.bordered td { border-width: thin; border-style: solid; border-spacing: 0; padding-left: 4px; padding-right: 4px; } table.bordered th { border-width: thin; border-style: solid; border-spacing: 0; padding-left: 8px; padding-right: 8px; } th.side { font-weight: bold; color: black; background-color: #ffd0d0; } th.right { font-weight: bold; color: black; background-color: #ffffd0; } th.top { font-weight: bold; color: black; background-color: #ffd0d0; text-alignment: center; } th.side code { background-color: inherit; } th.top code { background-color: inherit; } .InlineTitle { font-weight: bold; } .view { background-color: black; color: white; border: solid thin black; padding: 0.25em 1em; text-decoration: none; } a.view { background-color: black; color: white; border: solid thin black; } a.view:hover { background-color: blue; color: yellow; text-decoration: none; } /*added for IE as above (hover) does not work in IE*/ a.viewOn { background-color: blue; color: yellow; border: solid thin black; padding: 0.25em 1em; text-decoration: none; } ol li { margin-top: 0.3em; margin-bottom: 0.3em; } #footer {margin: 0px 0px 0px 0px; border: thin solid red;}
Content/images/comp1020_banner.jpg
Content/assignments/standards.html
COMP 1020 Programming Standards
This document lists the programming standards that you must follow for the programming questions of your assignments. Failure to follow these standards will result in the loss of marks.
Commenting files and methods
- Each of your program files must begin with a comment block like the following: /** * Name of class or program (matches filename) * * COMP 1020 SECTION Axx * INSTRUCTOR Name of your instructor * ASSIGNMENT Assignment #, question # * @author your name, your student number * @version date of completion * * PURPOSE: what is the purpose of your program? */
- If the purpose of a method is not self-explanatory, write a prologue comment at the beginning of the method, similar to the following:
/**
* PURPOSE: Describe the purpose of the method. Clearly.
* Indicate how the parameters and return values are used.
* For instance methods, describe the effect on the object state.
*/
or:
/** * Describe the purpose of the method. Clearly. * For instance methods, describe the effect on the object state. * * @param firstParameter description of what firstParameter means * indicate if the value is modified, and why * @param secondParameter description of what secondParameter means (as above) * * @return what is the meaning of the return value? */
Writing readable code
- Group the contents of your class consistently. Always place data before behaviours. The following order is recommended: class Something { // Instance variables // Static variables // Class-level constants // Constructors // Other instance methods // Static methods: main comes first, if it exists }
- Each assignment question should be submitted in a separate Java source code file. Place the "main" (public) class first and then add any other classes after the main class, as shown below. public class A2Q1 { public static void main(String[] args) { ... } ... } class Worker { ... }
- Use blank lines to separate blocks of code and declarations to improve readability. In particular, use blank lines between declarations and other code, and between methods.
- Comment blocks of code. Describe why you wrote the code this way, not what each line does. For example: // Summarizes taxes in each category (only federal so far) System.out.println("The taxes payable are:"); System.out.print("Federal tax = "); System.out.println(federalTax);
- Use meaningful but reasonable variable names. Start in lower case and capitalize only the first letter of each new word.
- a — Very bad. Too short, not meaningful.
- average — Good if there is only one possible average
- averageMark — Good
- average_of_all_the_marks_in_the_list — Bad. Too long and wordy.
- Use consistent indentation to clarify control structures (e.g. loops and if constructs). Levels of indentation should clearly indicate the depth of nesting. For example:
class MyClass {
public static void someMethod() {
statement;
while (...) {
statement;
if (...) {
statement;
...
}
statement;
}
statement;
}
public static int anotherMethod() {
...
}
}
Align else with the corresponding if for readability. Common styles include:
if (...) { statement; ... } else { statement; ... }or:
if (...) { statement; ... } else { statement; ... }
Avoid long lines; where needed, continuations of a statement on a new line should be indented too. Any readable and consistent style is acceptable. The essential features are that all statements that are nested within another statement must be indented, and that the braces { } must be in predictable and consistent positions.
Writing maintainable and extendable code
- Avoid the use of literal constants ("magic numbers") in your program. Generally use constant (final) identifiers rather than literal constants in your program. Acceptable exceptions are strings that appear only once, and small fundamental values. For example:
- sum = 0; — Literal constant 0 is OK
- count = count + 1; — Literal constant 1 is OK
- price = total * 1.07; — Magic values are not proper. Create a named constant like PST_RATE = 1.07.
- lastDigit = accountNumber % 10; — Literal constant 10 is OK.
- while (!command.equals("Quit")) { ... if (command.equals("Quit")) ... — Duplication is not proper. Create a named constant like QUIT_COMMAND = "Quit".
- Declare variables with as small a scope as possible. Use instance variables for object properties, local variables for method-specific data, and variables declared in for loops for counters. Use static variables only where absolutely necessary.
- Values of type float or double should not normally be compared with == or !=.
- Do not use break or continue statements (unless you are using a switch control structure) without the explicit permission of your instructor.
- Do not use multiple return statements in the same method without the explicit permission of your instructor.
- Never change the value of a for loop variable inside the loop.
- Use the best possible construct. For loops are only used when the number of iterations is known in advance; use a while or do/while for non-deterministic loops.
- Avoid unnecessary duplication of code. Use methods and inheritance wherever possible to prevent code duplication.
- Use appropriate language-specific naming standards for Java. Class names must start with InitialCapitalLetters, constants are ALL_UPPER_CASE, and all other identifiers use initialLowerCase.
- There should not be any processing performed in the main method; main should only call the methods that perform the actual processing. (This is also true for constructors.) Thus, the main method will normally consist of several calls to the processing methods. Use meaningful method and variable names. For example, printFlights(flights); instead of output(f);
Input and output
- All output produced on the console must have appropriate titles and headings. Output that is sent to a file typically does not require titles or headings.
- Print console output neatly. Use tabular output where appropriate.
- Print a message on the console at the end of the program that indicates whether or not the program completed successfully; e.g. End of processing. This message should be printed by the last statement in your main program.
Classes and objects
- Never perform any printing inside a toString() method. The toString() method always returns a String that contains information that describes an object.
- Perform as much processing as is possible inside objects. For example, if you have to compare the value of an object's instance variable with some other value, do not extract the value of the instance variable from the object and compare it with the other value outside of the object; instead, define a method such as compareValue(double value) inside the object. The method performs the comparison and returns the result.
- Make your access specifiers as restrictive as possible. Private things should be private, including all data members.
Content/assignments/Bookings.class
public synchronized class Bookings { public void Bookings(); public static void main(String[]); public static String[] getBookings(); }