Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doggie.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 54 additions & 3 deletions doggie.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
// Create a doggie
import java.awt.FlowLayout;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class doggie {

/**
* Creates a doggie. The doggie can waggle its tail, talk, or even jump
*/
public class Doggie {

private static final String DOGGIE_GIF = "./doggie.gif";
private static final String DOGGIE_JFRAME_NAME = "Jumping Doggies";

/**
* Waggles doggie's tail
*
* @param happy happiness of doggie as an integer
* @return doggie's final happiness as an integer
*/
public static int waggle(int happy) {
if (happy <= 10) {
System.out.println("waggle");
Expand All @@ -11,6 +31,37 @@ public static int waggle(int happy) {
}
}

/**
* Displays a line of jumping doggiess
*
* @param numOfDogs the number of jumping doggies to display
*
*/
public static void lineOfJumpingDoggies(int numOfDogs) {

URL url = Doggie.class.getResource(DOGGIE_GIF);
Icon doggie = new ImageIcon(url);
JFrame frame = new JFrame(DOGGIE_JFRAME_NAME);
JPanel container = new JPanel();
container.setLayout(new FlowLayout(FlowLayout.CENTER));

for (int i = 0; i < numOfDogs; i++) {
container.add(new JLabel(doggie));
}

frame.add(container);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

/**
* Makes doggie talk
*
* @param amount doggie's current loquaciousness as an integer
* @return doggie's final loquaciousness as an integer
*/
public static int talk(int amount) {
if (amount == 0) {
System.out.println("quiet");
Expand All @@ -23,4 +74,4 @@ public static int talk(int amount) {
}
}

}
}
14 changes: 8 additions & 6 deletions doggieTester.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Tester of doggie

public class doggieTester {
/**
* Tests the Doggie class.
*/
public class DoggieTester {
public static void main(String[] args) {
doggie.waggle(2); //must add class name (doggie) for static methods
doggie.talk(13);
Doggie.waggle(2); // must add class name (doggie) for static methods
Doggie.talk(13);
Doggie.lineOfJumpingDoggies(10);
}
}
}
Binary file added penguin.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 54 additions & 3 deletions penguin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
// Create a penguin
import java.awt.FlowLayout;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class penguin {

/**
* Creates a penguin. Penguin can waddle, talk or dance
*/
public class Penguin {

private static final String PENGUIN_GIF = "./penguin.gif";
private static final String PENGUIN_JFRAME_NAME = "Dancing Penguins";

/**
* Makes penguin waddle
*
* @param happy penguin's current happiness as an integer
* @return penguin's final happiness as an integer
*/
public static int waddle(int happy) {
if (happy <= 10) {
System.out.println("waddle");
Expand All @@ -11,6 +31,37 @@ public static int waddle(int happy) {
}
}

/**
* Displays a line of dancing penguins
*
* @param numOfPenguins the number of dancing penguins to display
*
*/
public static void lineOfDancingPenguins(int numOfPenguins) {

URL url = Doggie.class.getResource(PENGUIN_GIF);
Icon penguin = new ImageIcon(url);
JFrame frame = new JFrame(PENGUIN_JFRAME_NAME);
JPanel container = new JPanel();
container.setLayout(new FlowLayout(FlowLayout.CENTER));

for (int i = 0; i < numOfPenguins; i++) {
container.add(new JLabel(penguin));
}

frame.add(container);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

/**
* Makes penguin talk
*
* @param amount penguin's current loquaciousness as an integer
* @return penguin's final loquaciousness as an integer
*/
public static int talk(int amount) {
if (amount == 0) {
System.out.println("quiet");
Expand All @@ -22,4 +73,4 @@ public static int talk(int amount) {
return talk(amount / 5) + talk(amount - 1);
}
}
}
}
14 changes: 8 additions & 6 deletions penguinTester.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Tester of penguin

public class penguinTester {
/**
* Tests the Penguin class
*/
public class PenguinTester {
public static void main(String[] args) {
penguin.waddle(2); //must add class name (penguin) for static methods
penguin.talk(7);
Penguin.waddle(2); // must add class name (penguin) for static methods
Penguin.talk(7);
Penguin.lineOfDancingPenguins(10);
}
}
}