Go Back   Flash Flash Revolution > General Discussion > Chit Chat
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 02-5-2007, 02:39 PM   #1
inevitabledarkness
Banned
 
Join Date: Dec 2006
Posts: 82
Default Need some help with java

Alright, I'm doing the program that asks for the length and height of a box. That part I got. What I can't seem to get is the part where it asks for an input by the user of which character to use when creating the box. Here's the code. Please help.
EDIT: Cleaner code.
Code:
import java.util.Scanner;
import java.lang.*;

/**
 * Michael Cuiffi
 * Period 8
 * 2/1/07
 **/
 
 public class DrawBox {
 	
 	public static void drawBox(int length, int height, String mark) {
 	
 		for (int i = 1; i <= height; i++){
 			drawBar(length, mark);
 		}
 		System.out.println();
 	}	
 	public static void drawBar(int length, String mark) {
 		
 		for (int i = 1; i <= length; i++) {
 			System.out.print(mark);
 		}
 		System.out.println();
 	}	
 		public static void main(String[] args) {
 			
 			int length, height;
 			String mark;
 			String choice;
 			Scanner s = new Scanner(System.in);
 			
 			System.out.print("Please enter the box's length: ");
 			length = s.nextInt();
 			System.out.print("Please enter the box's height: ");
 			height = s.nextInt();
 			System.out.print("Do you want to enter a character to use to display the box?\n(enter y for yes): ");
 			choice = s.nextLine();
 			System.out.println();
 			
 			if (choice != "Y") {
 				drawBox(length, height, "*");
 			} else if (choice == "Y") {
 				System.out.print("Please enter the character: ");
 				mark = s.nextLine();
 				drawBox(length, height, mark);
 			}
 			
 			
 		
 	}
 	
 	}

Last edited by inevitabledarkness; 02-5-2007 at 03:03 PM..
inevitabledarkness is offline   Reply With Quote
Old 03-10-2007, 05:30 PM   #2
AirForceBlue
FFR Player
 
AirForceBlue's Avatar
 
Join Date: Mar 2007
Location: New Orleans, Louisiana
Age: 32
Posts: 64
Send a message via AIM to AirForceBlue
Default Re: Need some help with java

Hrm, what you want to use is an InputBox, most probably. I'm not really familiar with Java, but I'll do some research and edit this post when I find something out.
AirForceBlue is offline   Reply With Quote
Old 03-11-2007, 03:45 PM   #3
RandomPscho
FFR Player
 
Join Date: Jun 2006
Location: New York
Age: 32
Posts: 504
Default Re: Need some help with java

InputBox NO WAY!!! -- I hate that book AirForce CSLib UGH!
EDIT: Woops, misread.
EDIT:

Ok, the problem:
Code:
System.out.print("Do you want to enter a character to use to display the box?\n(enter y for yes): ");
 			choice = s.nextLine();
Should be
Quote:
choice = s.next();
I am not sure what nextLine() actually does, but next() reads the user's string.

Also: you might want to add if (choice != "Y" || choice !="y") to account for lowercase y's

Last edited by RandomPscho; 03-11-2007 at 04:23 PM..
RandomPscho is offline   Reply With Quote
Old 03-11-2007, 05:50 PM   #4
MRTL_mrclean17
FFR Player
 
MRTL_mrclean17's Avatar
 
Join Date: Nov 2006
Location: sky temple
Age: 35
Posts: 156
Send a message via MSN to MRTL_mrclean17
Default Re: Need some help with java

I was testing this script and was wondering why nothing was showing up, then it dawned on me, this is Java, not JavaScript, which the former happens to be my specialty. Sorry I'm of no help.
__________________
MRTL_mrclean17 is offline   Reply With Quote
Old 04-15-2007, 06:41 PM   #5
Zovistograt
FFR Player
 
Zovistograt's Avatar
 
Join Date: Apr 2007
Location: New York
Posts: 27
Default Re: Need some help with java

ARGH, no, please, never use boolean with Strings. Use

Code:
choice.equalsIgnoreCase(String)
instead. Also, use an else if thing like this...

Code:
if (choice.equalsIgnoreCase("Y")) System.out.println("some code...");
else if (choice.equalsIgnoreCase("N")) System.out.println("other code...");
else System.out.println("enter Y or N only!");
and 'course you should put that in a little while loop so that if they don't enter Y or N it just says it again.
__________________
http://spzc.net/

Last edited by Zovistograt; 04-15-2007 at 06:42 PM.. Reason: forgot some end parentheses D:
Zovistograt is offline   Reply With Quote
Old 04-15-2007, 06:43 PM   #6
Zovistograt
FFR Player
 
Zovistograt's Avatar
 
Join Date: Apr 2007
Location: New York
Posts: 27
Default Re: Need some help with java

Quote:
Originally Posted by RandomPscho View Post
InputBox NO WAY!!! -- I hate that book AirForce CSLib UGH!
EDIT: Woops, misread.
EDIT:

Ok, the problem:
Code:
System.out.print("Do you want to enter a character to use to display the box?\n(enter y for yes): ");
 			choice = s.nextLine();
Should be

I am not sure what nextLine() actually does, but next() reads the user's string.

Also: you might want to add if (choice != "Y" || choice !="y") to account for lowercase y's
nextLine() does the same thing...I thought you only use next() for Scanner stuffs with delimeters and all that semi-confusing annoyance.
__________________
http://spzc.net/
Zovistograt is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 09:39 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution