Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Challenge

Name: Anonymous 2018-04-15 1:54

Write a fizzbuzz program in a language you've never used before.
It's not hard, but I assume that if you come up with difficult challenges, people won't do them.

Name: Anonymous 2018-04-16 18:01

I'm sorry this is my first time writing Java. Can somebody please code review?

interface Quux {
public String getValue();
}


class FizzBuzzException extends Exception {
public FizzBuzzException(String message) {
super(message);
}
}


class Fizz implements Quux {
static boolean isFizzValid;
static String fizz;

// Initialize the class
public Fizz(boolean isValid) {
isFizzValid = isValid;
fizz = "Fizz";
}

// Get the value of fizz
static String getFizz() {
return fizz;
}

static boolean getFizzValid() {
return isFizzValid;
}

// Get the string of Fizz
@Override
public String getValue() {
if (isFizzValid) {
// Is Fizz
return getFizz();
} else {
// Is not Fizz
return null;
}
}
}


class Buzz implements Quux {
public boolean isBuzzValid;
static String buzz;

public Buzz(boolean isValid) {
isBuzzValid = isValid;
buzz = "Buzz";
}

static String getBuzz() {
return buzz;
}

@Override
public String getValue() {
if (isBuzzValid) {
// Is Fizz
return getBuzz();
} else {
// Is not Fizz
return null;
}
}
}


class NoFizzBuzzException extends Exception {
public NoFizzBuzzException(String message) {
super(message);
}
}


class FizzBuzzFactory {
public Fizz fizz;
public Buzz buzz;

public FizzBuzzFactory(Fizz fizzConstructor, Buzz buzzConstructor) {
fizz = fizzConstructor;
buzz = buzzConstructor;
}

public String getValeu() throws NoFizzBuzzException {
String fizzValue = fizz.getValue();
String buzzValue = buzz.getValue();

if (fizzValue == null && buzzValue == null) {
throw new NoFizzBuzzException("No fizzbuzz");
} else {
String value = "";
if (fizzValue != null) {
value = value + fizzValue;
}
if (buzzValue != null) {
value = value + buzzValue;
}

return value;
}
}
}


class FizzBuzzCalculator {
public int fizzDiscriminator;
public int buzzDiscriminator;
public int zero; // Zero
public int numberToCalculate;

public FizzBuzzCalculator(int number) {
fizzDiscriminator = 3;
buzzDiscriminator = 5;
zero = 0;
numberToCalculate = number;
}

public FizzBuzzFactory calculate() {
boolean fizzValid;
boolean buzzValid;

buzzValid = false;

if (numberToCalculate % fizzDiscriminator == zero) {
fizzValid = true;
} else {
fizzValid = false;
}

if (numberToCalculate % buzzDiscriminator == zero) {
buzzValid = true;
} else {
buzzValid = false;
}

// Initialize the Fizz and Buzz
Fizz fizz;
Buzz buzz;

fizz = new Fizz(fizzValid);
buzz = new Buzz(buzzValid);

// Initialize the FizzBuzzFactory
FizzBuzzFactory fizzbuzz;

fizzbuzz = new FizzBuzzFactory(fizz, buzz);

return fizzbuzz;
}
}


class Main {
public static void main(String[] args) {
for (int numberIndex = 0; numberIndex < 101; numberIndex++) {
FizzBuzzCalculator calculator = new FizzBuzzCalculator(numberIndex);
FizzBuzzFactory factory = calculator.calculate();

try {
String fizzBuzzValue = factory.getValeu();
System.out.println(fizzBuzzValue);
} catch (NoFizzBuzzException except) {
System.out.println(Integer.toString(numberIndex));
}
}
}
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List