Hows my java code?

Discussion in 'OT Technology' started by Spur, Oct 4, 2004.

  1. Spur

    Spur Boomer

    Joined:
    Nov 14, 2001
    Messages:
    3,685
    Likes Received:
    5
    Location:
    AZ
    So this is my first assignment i've ever done for java.

    I had to recreate the the lyrics to the childrens song of "The Old woman who ate a fly"


    Heres the code


    Code:
    public class Song1 {
    	public static void main(String[] args)  {
    		fly();
    		spider();
    		bird();
    		cat();
    		dog();
    		horse();
    	}
    
    	public static void fly() {
    		System.out.println("There was an old woman who swallowed a fly.");
    		iDontKnowWhy();
    	}
    
    	public static void iDontKnowWhy() {
    		System.out.println("I don't know why she swallowed that fly,");
    		System.out.println("Perhaps she'll die.");
    		System.out.println();
    	}
    
    	public static void spider() {
    		System.out.println("There was an old woman who swallowed a spider,");
    		System.out.println("That wriggled and iggled and jiggled inside her.");
    		SwallowedSpider();
    	}
    
    	public static void SwallowedSpider() {
    		System.out.println("She swallowed the spider to catch the fly,");
    		iDontKnowWhy();
    	}
    
    	public static void bird() {
    		System.out.println("There was an old woman who swallowed a bird,");
    		System.out.println("How absurd to swallow a bird.");
    		SwallowedBird();
    	}
    
    	public static void SwallowedBird() {
    		System.out.println("She swallowed the bird to catch the spider,");
    		SwallowedSpider();
    	}
    
    	public static void cat() {
    		System.out.println("There was an old woman who swallowed a cat,");
    		System.out.println("Imagine that to swallow a cat.");
    		SwallowedCat();
    	}
    
    	public static void SwallowedCat() {
    		System.out.println("She swallowed the cat to catch the bird,");
    		SwallowedBird();
    	}
    
    	public static void dog() {
    		System.out.println("There was an old woman who swallowed a dog,");
    		System.out.println("What a hog to swallow a dog.");
    		SwallowedDog();
    	}
    
    	public static void SwallowedDog() {
    		System.out.println("She swallowed the dog to catch the cat,");
    		SwallowedCat();
    	}
    
    //Old woman ate the horse...AND DIED!
    	public static void horse() {
    		System.out.println("There was an old woman who swallowed a horse,");
    		System.out.println("She died of course.");
    	}
    }
    

    How does it look?
     
  2. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    looks good, although I have a few suggestions. I don't know if this is beyond what you've learned but here's what I've got.
    The lines:
    "There was an old woman who swallowed a ...," and
    "She swallowed the ... to catch the ...,"

    What I might do is make a function that prints those lines out, but takes one or two paramaters (the animals in question). Could end up looking like less work to your teacher even though you've already done it the long way.
     
  3. Spur

    Spur Boomer

    Joined:
    Nov 14, 2001
    Messages:
    3,685
    Likes Received:
    5
    Location:
    AZ
    Thanks for the comments and info.

    We havn't learned that yet. I've only had one full lecture so this is pretty much all i know
     
  4. kosstamogen

    kosstamogen New Member

    Joined:
    Aug 26, 2004
    Messages:
    386
    Likes Received:
    0
    Location:
    SoCal
    that's good work man. I can't believe thay are making people do this type of homework. That is just so far beyond the realm of reality. What ever happened to good old fashioned "hello world."
     
  5. beez

    beez New Member

    Joined:
    Jun 3, 2004
    Messages:
    19,143
    Likes Received:
    0
    Location:
    Queens
    Looks alright. I guess this was an exercise to get you all comfortable with writing/calling internal methods, eh?
     
  6. Spur

    Spur Boomer

    Joined:
    Nov 14, 2001
    Messages:
    3,685
    Likes Received:
    5
    Location:
    AZ
    haha. That was part of our lecture.
     
  7. Spur

    Spur Boomer

    Joined:
    Nov 14, 2001
    Messages:
    3,685
    Likes Received:
    5
    Location:
    AZ

    basically. The class is CSE 142. and they assume that we have no background what so ever to java code.

    and well... i don't
     
  8. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    We still have Hello World as our first lab :dunno:
     
  9. Euclid

    Euclid New Member

    Joined:
    Apr 19, 2004
    Messages:
    8,139
    Likes Received:
    0
    Location:
    Nashville, TN
    Lucky you. Lots of CS majors became ITM majors (information tech management aka "I Tried, Mom") because of our "introductory" java course. :hs:
     
  10. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    :rofl: Our introductory CS courses are easy as fuck (for most people anyway). It's the first-year math courses that CS students have to take that weeds out the Christmas graduates.
     

Share This Page