Computer Science 210
Data Structures
Fall 2019, Siena College
BaaBaa2Methods BlueJ Project
Click here to download a BlueJ project for BaaBaa2Methods.
BaaBaa2Methods Source Code
The Java source code for BaaBaa2Methods is below. Click on a file name to download it.
/** * Example BaaBaa2Methods: move all of the work into 2 methods, * including that which is only called once. * * @author Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012 * @version Fall 2019 */ public class BaaBaa2Methods { /** a method to perform the 4 println statements that were being repeated in the BaaBaaBad version */ public static void refrain() { System.out.println("Baa, baa, black sheep,"); System.out.println("Have you any wool?"); System.out.println("Yes sir, yes sir,"); System.out.println("Three bags full."); } /** A method to perform the 4 println statements that form the verse. This method is just for readability -- we call it just once, but it simplifies our main method. */ public static void verse() { System.out.println("One for the master,"); System.out.println("One for the dame,"); System.out.println("And one for the little boy"); System.out.println("Who lives down the lane."); } /** Print the lyrics to "Baa Baa Black Sheep" The main method is still where our program will begin executing, even though there are now two additional methods defined within our class. @param args not used */ public static void main(String[] args) { // we replace the println statements here // calls that each print a refrain or the verse refrain(); verse(); refrain(); } }