Options: 1. Deposit 2. Withdraw 3. Check the balance 4. Quit Enter your choice (1,2,3, or 4):
Heads 1 Heads 2 Tails Tails Tails Heads 1 Heads 2 Heads 3 Heads 4 Tails Heads 1 ...You'll have to work a little on the formatting to get this to come out right (think about where you'll use print and where you'll use println).
public static boolean isLetter(char c)Recall that a static method is called using the class name. Hence, a call would have the form
Character.isLetter(ch)where ch is a variable of type char. Since a boolean is returned the above call should be placed in an appropriate place for a boolean such as an if.
NumberFormat fmt = NumberFormat.getPercentInstance();
System.out.println ("Percentage of vowels: " + fmt.format(whatever));
read in the first phrase while the phrase is neither "Q" nor "q" { initialize the counters etc. to set up the for loop for loop to count letters and vowels in the phrase print the number of vowels & letters and percentage of vowels read in the next phrase or "Q" to quit }Note that all you need to do is add the sentinel controlled while loop around the code you already have. Be sure the code to initialize the counters is inside the while loop (you start the counters over for each phrase).
Be sure to format your code after adding the surrounding loop (SHIFT-CTRL-F) so it is properly indented.
Test your program thoroughly (enter more than one phrase!!!) then print the final version.
Scanner scan = new Scanner (System.in);The parameter for the constructor is System.in - the input stream we want to read from. Similarly we can instantiate a Scanner object to read from a file if given the name of the file (which is either a String literal or a String variable). Examples are:
Scanner fileScan1 = new Scanner (new File ("myFile.txt")); // assume fileName is a String variable that already has a value Scanner fileScan2 = new Scanner (new File (fileName));When running a program in Eclipse, the String for the filename needs to be the relative path to the file from the Project you are in (which is Labs). So, if the files are saved in your lab10 directory, the above would need to be modified as follows:
Scanner fileScan1 = new Scanner (new File ("lab10/myFile.txt")); // assume fileName is a String variable that already has a value Scanner fileScan2 = new Scanner (new File ("lab10/" + fileName));The usual Scanner class methods - next, nextLine, nextInt, etc. - are used to read data from a file. However the Scanner class has another method called hasNext that returns a boolean indicating whether or not there are more items in the file - this method is often used in the loop control for a loop that is reading through a file and processing the data in it. FileExample.java is an example program that reads a file. In this case the file consists of lines of data each containing an integer (a student grade) followed by a String (the student name - no spaces allowed). Some sample input files of data are grades1.txt and grades2.txt. [NOTE: A Scanner object is an example of an iterator which is discussed in Section 5.6 (pages 245 - 249) of the text.]
Do the following:
The file nflStats.txt contains some statistics about how some of the NFL quarterbacks did in a recent week of play. Specifically, the file contains the name of the quarterback, the number of times he tried to pass the football and the outcome (in yards) of each pass attempt (note: an outcome of 0 means that the pass was incomplete). The file is organized as follows:
QUARTERBACK_NAME NUMBER_OF_PASS_ATTEMPTS YARDAGE_1 YARDAGE_2 YARDAGE_3 ... YARDAGE_NHere's a simple example file:
Montana 13 12 0 35 23 0 0 8 57 0 14 27 21 0 Jones 7 0 0 0 13 0 67 8Your job is to write a program, named FootballStats.java, that reads the file and uses the data to compute some aggregate statistics. For each quartback, you should print a nicely formatted message that contains:
Moreover, we are interested in identifying the "Best" Quarterback performance. After all the data has been read and processed, your program should print out a message that contains the name of the quarterback that had a) the largest total yards, b) the highest yards per attempt and c) the highest yards per complete pass.
To accomplish this, you need to do the following for each player:
Clearly you need a nested loop.
Plan your program before starting it! You should not try to do everything at once - devise a strategy to complete and test the program in steps (the last exercise may give you a hint about a good strategy for writing a program with a nested loop).