Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 11-15-2004, 12:01 PM   #1 (permalink)
Buffering.........
 
merkerguitars's Avatar
 
Location: Wisconsin...
[java] problem with return statement and placement of {}'s

Ok here is what I have in my Test class
Code:
package a4; 

/** 
* <p>Title: Assignment 4</p> 
* <p>Description: CS 161 Assignment 4 </p> 
* <p>Copyright: Copyright (c) 2004</p> 
* <p>Company: UW-River Falls</p> 
* @author Eric Merker 
* @email ericmerker@centurytel.net 
* @date started: Novemeber 9th 2004 finished: ???? 
* @team prometheusfree.org crew visit us at irc.shadowfire.org at #prometheus 
* @version 1.0 
 */ 


import javax.swing.*; 

public class Test { 
  public Test() { 
  } 

      public static void main(String[] args) { 
      Test test1 = new Test(); 

      int x = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter a number")); 

      } 
  }
And this is what I have in my convert class
Code:
/** 
* <p>Title: Assignment 4</p> 
* <p>Description: CS 161 Assignment 4 </p> 
* <p>Copyright: Copyright (c) 2004</p> 
* <p>Company: UW-River Falls</p> 
* @author Eric Merker 
* @email ericmerker@centurytel.net 
* @date started: Novemeber 9th 2004 finished: ???? 
* @team prometheusfree.org crew visit us at irc.shadowfire.org at #prometheus 
* @version 1.0 
*/ 

import javax.swing.*; 

public class Convert { 
public void print(int x); 
int printPower = x; {{
//missing an open {, and a return type on this line 
if (paraMeter > 12) System.out.println("Does not compute");
 switch (x) { 

case 1: System.out.println("Ten"); 
break; 

case 2: System.out.println("Hundred"); 
break; 

case 3: System.out.println("Thousand"); 
break; 

case 4: System.out.println("Ten Thousand"); 
break; 

case 5: System.out.println("Hundred Thousand"); 
break; 

case 6: System.out.println("Million"); 
break; 

case 7: System.out.println("Ten Million"); 
break; 

case 8: System.out.println("Hundred Million"); 
break; 

case 9: System.out.println("Billion"); 
break; 

case 10: System.out.println("Ten Billion"); 
break; 

case 11: System.out.println("Hundred Billion"); 
break; 

case 12: System.out.println("Trillion"); 
break; }}}
the convert class is the one i'm having problems with, basically I just can't get the return statement correct and the placement of the {}s what the problem does is it takes an input x adn then puts that input into the convert class which matches it up with the proper case statemnet.
__________________
Donate now! Ask me How!

Please use the search function it is your friend.

Look at my mustang please feel free to comment!

http://www.tfproject.org/tfp/showthread.php?t=26985
merkerguitars is offline  
Old 11-15-2004, 03:52 PM   #2 (permalink)
Insane
 
Location: Wales, UK, Europe, Earth, Milky Way, Universe
I dont usually do people's homework for them, especially when the attempt looks pretty appauling like this. But, i'm a softy and i need the practice so... does this help:

Code:
import javax.swing.*; 

public class Convert {
	private int x;

	public Convert(int x) {
		this.x = x;
	}

	public void print {
		if (x > 12) {
			System.out.println("Does not compute");
		} else {
			switch (x) {
				case 1: System.out.println("Ten");
					break;
				case 2: System.out.println("Hundred");
					break;
				case 3: System.out.println("Thousand");
					break;
				case 4: System.out.println("Ten Thousand");
					break;
				case 5: System.out.println("Hundred Thousand");
					break;
				case 6: System.out.println("Million");
					break;
				case 7: System.out.println("Ten Million");
					break;
				case 8: System.out.println("Hundred Million");
					break;
				case 9: System.out.println("Billion");
					break;
				case 10: System.out.println("Ten Billion");
					break;
				case 11: System.out.println("Hundred Billion");
					break;
				case 12: System.out.println("Trillion");
					break;
			}
		}
	}
}
BTW, please note i havent bothered testing it.
__________________
There are only two industries that refer to their customers as "users". - Edward Tufte
welshbyte is offline  
Old 11-15-2004, 08:37 PM   #3 (permalink)
Über-Rookie
 
Location: No longer, D.C
Get in the habit of indenting properly ;p Proper indention makes it so easy to spot missing brackets or too many brackets.

pretty much, if you ever have more than one { or } on a line you should work on your formatting. Otherwise you will hit a snag and it will be harder to spot. This comment is mainly for you at the beginning, until you get used to matching up your { } without thinking
oblar is offline  
 

Tags
java, placement, problem, return, statement


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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 12:19 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73