Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   [java] problem with return statement and placement of {}'s (https://thetfp.com/tfp/tilted-technology/76128-java-problem-return-statement-placement-s.html)

merkerguitars 11-15-2004 12:01 PM

[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.

welshbyte 11-15-2004 03:52 PM

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.

oblar 11-15-2004 08:37 PM

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


All times are GMT -8. The time now is 08:18 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2026, 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