This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class AnimationSelfAvoidingRandomWalk extends JFrame { | |
private static final int N = 16; | |
private Point[][] lattice = new Point[N + 1][N + 1]; | |
private int i = (N + 1) / 2; | |
private int j = (N + 1) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class HitBalloonGame extends JFrame { | |
private ShootPanel p = new ShootPanel(); | |
HitBalloonGame() { | |
add(p); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rational extends Number implements Comparable<Rational> { | |
// Data fields for numerator and denominator | |
private BigInteger numerator = BigInteger.ZERO; | |
private BigInteger denominator = BigInteger.ONE; | |
/** Construct a rational with default properties */ | |
public Rational() { | |
this(BigInteger.ZERO, BigInteger.ONE); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The {@link Rational} class is used for rational number. | |
* A rational number consists of a numerator and a denominator. | |
* There are many equivalent rational numbers—for example, | |
* 1/3 = 2/6 = 3/9 = 4/12. | |
* The numerator and the denominator of 1/3 have no common divisor except 1 | |
* | |
* @author AhmedNasser | |
*/ | |
public class Rational extends Number implements Comparable<Rational> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.*; | |
import java.util.*; | |
import java.io.*; | |
import javax.swing.*; | |
public class Test { | |
public static void main(String[] args) throws Exception { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
public class Test { | |
public static void main(String[] args) throws Exception { | |
File file = new File("hangman.txt"); | |
Scanner input = new Scanner(file); | |
List<String> words = new ArrayList<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* *13.11 (Plot the square function) Write a program that draws a diagram for the function | |
* f(x) = x2 (see Figure 13.29c). | |
* | |
* Hint: Add points to a polygon p using the following loop: | |
* | |
* double scaleFactor = 0.1; | |
* for (int x = -100; x <= 100; x++) { | |
* p.addPoint(x + 200, 200 - (int)(scaleFactor * x * x)); | |
* } |
NewerOlder