my god this is still alive?
package cs240project3;
/*
*************************************************************************
*
* @author Erica
* @date 10-28-08
*
* This program offers the user a set of 4 shapes they can draw
* to the screen with asterisks (*). It also prompts whether or
* not they want the shape filled or not. The user has the option of
* chosing the deminsions of the shape, and has 3 tries to get it
* within the limits.
*
* ***********************************************************************
*/
//Imports
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//Variables
int counter = 3; //The "x tries left" counter
String choice_s; //Input string for the shape
char uchoice_s; //First letter of string_s
String choice_f; //Input string for un/filled option
char uchoice_f; //First letter of string_f
//Main program loop
while (counter != 0) {
//Prompts user for their choice of shape or quit (menu)
Scanner input = new Scanner(System.in);
System.out.print("What do you wish to draw? \n" +
"(B for a box, R for a right triangle,\n" +
"I for an isoceles triangle, D for diamond,\n" +
"or Q to quit)");
//Finds the first letter of input to use as the switch case for their option
choice_s = input.nextLine();
uchoice_s = choice_s.charAt(0);
//Switch statement that relates to the input
switch (uchoice_s) {
case (66): //'B'
case (98): //'b'
//Prompts the user if they want their box un/filled and
//draws the appropiate shape
System.out.println("Do you want your box filled (F) " +
"or unfilled (U)?");
Scanner inputfilled = new Scanner(System.in);
choice_f = inputfilled.nextLine();
uchoice_f = choice_f.charAt(0);
switch (uchoice_f) {
case (70): //'F'
case (102): //'f'
int columns;
int rows;
System.out.println("Type the diminsions for the box" +
" by typing the number of colums followed by" +
" the number of rows.\n" +
"(e.g. 10 20)");
Scanner dim = new Scanner(System.in);
columns = dim.nextInt();
rows = dim.nextInt();
testbox(columns, rows);
if (testbox() = true)
box_f(rows, columns);
else {
counter--;
System.out.println("The diminsions are not in range.");
System.out.print("Try again. \nYou have " +
counter + " tries left!");
}
break;
case (85): //'U'
case (117): //'u'
box_u();
break;
}
break;
case (82): //'R'
case (114): //'r'
//Same as box, only for a triangle
System.out.println("Do you want your right triangle filled (F) " +
"or unfilled (U)?");
inputfilled = new Scanner(System.in);
choice_f = inputfilled.nextLine();
uchoice_f = choice_f.charAt(0);
switch (uchoice_f) {
case (70): //'F'
case (102): //'f'
rtriangle_f();
break;
case (85): //'U'
case (117): //'u'
rtriangle_u();
break;
}
break;
case (73): //'I'
case (105): //'i'
//Ditto
System.out.println("Do you want your isoceles triangle filled (F) " +
"or unfilled (U)?");
inputfilled = new Scanner(System.in);
choice_f = inputfilled.nextLine();
uchoice_f = choice_f.charAt(0);
switch (uchoice_f) {
case (70): //'F'
case (102): //'f'
itriangle_f();
break;
case (85): //'U'
case (117): //'u'
itriangle_u();
break;
}
break;
case (68): //'D'
case (100): //'d'
//You know the drill by now (only for a diamond this time)
System.out.println("Do you want your diamond filled (F) " +
"or unfilled (U)?");
inputfilled = new Scanner(System.in);
choice_f = inputfilled.nextLine();
uchoice_f = choice_f.charAt(0);
switch (uchoice_f) {
case (70): //'F'
case (102): //'f'
diamond_f();
break;
case (85): //'U'
case (117): //'u'
diamond_u();
break;
}
break;
case (81): //'Q'
case (113): //'q'
//Quits the program
System.out.println("Quitting...");
counter = 0;
break;
default:
counter--;
System.out.print("Try again. \nYou have " + counter + " tries left!");
break;
}
}
}
public static boolean testbox(int columns, int rows) {
boolean test;
if (rows <= 0 || columns <= 0 || columns >= 80)
test = false;
else
test = true;
return test;
}
public static void box_f(int columns, int rows) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
public static void box_u() {
int columns;
int rows;
System.out.println("Type the diminsions for the box" +
" by typing the number of colums followed by" +
" the number of rows.\n" +
"(e.g. 10 20)");
Scanner dim = new Scanner(System.in);
columns = dim.nextInt();
rows = dim.nextInt();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (i == 0 || i == rows - 1 || j == 0 || j == columns - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.print("\n");
}
}
public static void rtriangle_f() {
System.out.println("How big do you want your base?");
Scanner dim = new Scanner(System.in);
int base = dim.nextInt();
for (int i = 0; i < base; i++){
for (int j = 0; j < i + 1; j++)
System.out.print("*");
System.out.print("\n");
}
}
public static void rtriangle_u() {
System.out.println("How big do you want your base?");
Scanner dim = new Scanner(System.in);
int base = dim.nextInt();
for (int i = 0; i < base; i++){
for (int j = 0; j < i + 1; j++)
if (i == base - 1)
System.out.print("*");
else if (j == 0 || j == i)
System.out.print("*");
else
System.out.print(" ");
System.out.print("\n");
}
}
public static void itriangle_f() {
System.out.println("How big do you want your base?" +
"(Odd number only please)");
Scanner dim = new Scanner(System.in);
int base = dim.nextInt();
int rows = base / 2;
for (int i = 0; i <= rows; i++) {
for (int j = 0; j < rows - i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
public static void itriangle_u() {
System.out.println("How big do you want your base?" +
"(Odd number only please)");
Scanner dim = new Scanner(System.in);
int base = dim.nextInt();
int rows = base / 2;
for (int i = 0; i <= rows; i++) {
for (int j = 0; j < rows - i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; j++) {
if (i == rows)
System.out.print("*");
else if (j == 0 || j == 2 * i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
}
public static void diamond_f() {
System.out.println("Diz are diamond_f!!!");
}
public static void diamond_u() {
System.out.println("Diz are diamond_u!!!");
}
}
//The end ^_^
...o.o oh yea
Oh gods, why? ಥ_ಥ
DESTROY!
oh, i thought he was talking about my codez, cuz thats what im about to do. i just hope i dont get a zero on it lulz, cuz it was due yesterday and im only half done
Oh gods, why? ಥ_ಥ
Marilyn Chambers
"Everything has a purpose. It's your life's mission to find yours."