Gaga Rigs

Loops – fixed, user specified, infinite

TASK
a program with a BIG crush on Ralph

Same as before but this time say:
You’re so CUTE CUTE CUTE CUTE CUTE

CUTE should be written some fixed number of times.

After that modify your code (or better, write a different program) that asks Ralph what his favorite number is and write CUTE that many times.

After getting that version, consider a version showing you have gone way beyond the crush phase (what was that movie?) where CUTE keeps being written – forever..

FIXED – meaning you have a final double indicating the number of times you want the loops to run


import javax.swing.JOptionPane;

public class bigCrushFixed {

public static void main(String[] args) {

		final double TIMES_OF_CUTE = 15;
		final String RALPH = "ralph";
		final String RALPH_C = "Ralph"; //cap

		String userName;

		userName = JOptionPane.showInputDialog("Hello there, whats your name?");

		System.out.println("Hello, " + userName + "!");

		if (userName.equals(RALPH) || userName.equals(RALPH_C) ){

		     System.out.println("My name is winnie the pooh, you are wandering in my land");
		     System.out.println("and ones who wonder in my land get a dose of bad flirting");
		     System.out.println("here it goes...");

		     for(int i = 0; i < TIMES_OF_CUTE; i++){
			     System.out.print("*CUTE*");

		     }
		}

		System.exit(0);

	}

}

USER DECIDED – meaning you have a double like userNum and you ask the user for a number, this number is the the times the loop will run


import javax.swing.JOptionPane;

public class bigCrushAsk {

public static void main(String[] args) {

		final String RALPH = "ralph";
		final String RALPH_C = "Ralph"; //cap

		double timesOfCute;

		String userNum;
		String userName;

		userName = JOptionPane.showInputDialog("Hello there, whats your name?");

		System.out.println("Hello, " + userName + "!");

		if (userName.equals(RALPH) || userName.equals(RALPH_C) ){

			userNum = JOptionPane.showInputDialog("Give me a number, please "+ userName + " :)");
			timesOfCute = Integer.parseInt(userNum);

		     System.out.println("My name is winnie the pooh, you are wandering in my land");
		     System.out.println("and ones who wonder in my land get a dose of bad flirting");
		     System.out.println("here it goes...");

		     for(int i = 0; i < timesOfCute; i++){
			     System.out.print("*CUTE*");

		     }
		}

		System.exit(0);

	}

}

INFINITE – meaning the loops will run forever

import javax.swing.JOptionPane;

import javax.swing.JOptionPane;

public class bigRalphCrushInfinant {

	public static void main(String[] args) {

		final double TIMES_OF_CUTE = 15;
		final String RALPH = "ralph";
		final String RALPH_C = "Ralph"; //cap

		boolean ralphTrue = false;

		String userName;

		userName = JOptionPane.showInputDialog("Hello there, whats your name?");

		System.out.println("Hello, " + userName + "!");

		if (userName.equals(RALPH) || userName.equals(RALPH_C) ){

		     System.out.println("My name is winnie the pooh, you are wandering in my land");
		     System.out.println("and ones who wonder in my land get a dose of bad flirting");
		     System.out.println("here it goes...");

		     ralphTrue = true;

		     while(ralphTrue = true){

			     System.out.print("*CUTE*");

		     }
		}

		System.exit(0);

	}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>