Chapter 5 Flashcards
when you are dealing with upscale and dangerous technology, why is it important that everything that is written in a program is written precisely without errors? give a real historic example.
NASA scientists caught an error that could have trashed the Mercury space flights. (Yup! These were flights with people on board!) The error was a line with a period instead of a comma. (A computer programmer wrote DO 10 I=1.10 instead of DO 10 I=1,10.)
what’s something to keep in mind when it comes to spelling your programs correctly?
In Java, consistent spelling and capitalization are very important — if you’re not consistent within a particular program, the program will probably have some nasty, annoying compile-time errors.
when making a new project why should you mark the box labeled public static void main(String[] args}?
Optionally, you can put a check mark in the box labeled public static void main(String[] args}. If you leave the box unchecked, you’ll have a bit more typing to do when you get to Step 8. Either way (checked or unchecked), it’s no big deal. Click Finish.
why should or shouldn’t you copy and paste code rather than writing it yourself?
This strategy might be okay, as long as all the spelling when transfered and pasted is spelled correctly as sometimes some symbols like quotation marks may be curly but in Java you must avoid curly quotation marks and instead use straight quotation marks. as long as the spelling results are correct, there should be no problem copying and pasting someong else’s code.
what’s something to remember when you want to type inside of the console view after a run?
If you forget to click inside the Console view, Eclipse may not send your keystrokes to the running Java program. Instead, Eclipse may send your keystrokes to the editor or (strangely enough) to the Package Explorer.
what is keyboard.nextLine( ); ?
It is to type a line of text into your code after you run the program.
as you run the code this will stop the code dead in it’s tracks waiting for you to type and input something from your keyboard onto the console view, and then you press enter to gain the results of your code unless you have several keyboard.nextLine( ); in your code will you be prompted again to types something else and then hit enter again. basically it’s to input what you type into the keyboard to affect that part in your code
what is calling keyboard.nextInt() for?
geting numbers (integers) from the keyboard with no decimal in it.
what is calling keyboard.nextLine for?
getting a line of text from the keyboard.
what is calling keyboard.nextDouble for?
getting a number from the keyboard that has a decimal in it.
what is calling keyboard.next() for?
Typing a word into the console
what is calling findWithinHorizon(“.”,0).charAt(0) for?
getting a single character from the keyboard, whether it is a letter a number or a punctuation symbol
what 3 lines of code are needed to read input from the keyboard when using keyboard.next() keyboard.nextLine keyboard.nextInt etc. ?
import java.util.Scanner;
Scanner keyboard = new Scanner(System.in);
keyboard.close();
what is the good news and bad news of the 3 important lines of code that are part of the keyboard.next kinds of code?
the bad news is the reasoning behind it can be easily misunderstood but the good news is you can just copy and paste it , you dont need to know the reasoning behind it.
when using the scanner method, what’s the first line in your code?
Make the import java.util.Scanner line the first line in your program.
where do you put the Scannr keyboard = new Scanner(System.in) line?
Put the Scanner keyboard = new Scanner(System.in) line inside the main method immediately after the public static void main(String args[]) { line.