Results 1 to 10 of 10
  1. #1
    jayti is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default Need help with the output statements

    My question id how do we actually get the output without using the System.out.print statements?
    Basically, w need to get the following output:

    A new type of boiler is to be designed that can have its temperature set and its pump turned off and on. However, it must always operate within the following safety constraints:

    * The temperature must never be less than 10 or more than 80 (degrees Celsius).
    * If the pump is turned off the temperature must not be set to more than 50.
    * If the temperature is more than 50, the pump must not be turned off.
    * If the temperature is 70 or more, the automatic safety valve must be open.
    * If the temperature less than 70, the automatic safety valve must be closed.

    We have to make two classes, one of the main public class, where we can use the system.out.print statements..but we cannot use system.out.print in the other class.

    if you want the whole question, then i cn email.

  2. #2
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    It sounds like your second class will need methods that return values to the main class then the main class can use the system.out.print statements.

    An example of a class that has a method that returns an integer could be something like:

    Java Code:
    class MyClass {
       public MyClass() {  //constructor
       }
       public int calculation() {  //method that returns an integer
          int result = 2 * 3;
          return result;
       }
    }
    your main class would call the method in the example:
    Java Code:
    MyClass example = new MyClass();  //instantiates an object of MyClass
    int value = example.calculation();  //calls method
    Hope this Helps!
    Chris
    Last edited by tashimoto; 11-23-2010 at 05:50 PM. Reason: Names of classes should start with a capital letter. Corrected class name from myClass to MyClass.

  3. #3
    jayti is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    thnx a lot for the hel, i tried your way n it almost workd. i have used d switch statements in my main class n if the user entered o of p then the output they should get, is suppose to be in the other class(so here it will be in myclass). bt v cannot use any print statements.
    Boiler Program Started.

    Temperature: 10
    Pump: off
    Safety valve: closed

    Type:
    p - to turn on the pump
    o - to turn off the pump
    t - to set the temperature
    q - to quit

    Enter selection: p

    Temperature: 50
    Pump: on
    Safety valve: closed

    hence when the user selects p, the output that is produced has to be in the other (secondary class) without d use of print statements. i dnt if this makes sense. bt i cn email u d whole question if u want.

  4. #4
    jayti is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    thnx a lot for the help, i tried your way n it almost workd. i have used d switch statements in my main class n if the user entered o of p then the output they should get, is suppose to be in the other class(so here it will be in myclass). bt v cannot use any print statements.

    Boiler Program Started.

    Temperature: 10
    Pump: off
    Safety valve: closed

    Type:
    p - to turn on the pump
    o - to turn off the pump
    t - to set the temperature
    q - to quit

    Enter selection: p

    Temperature: 50
    Pump: on
    Safety valve: closed

    hence when the user selects p, the output that is produced has to be in the other (secondary class) without d use of print statements. i dnt if this makes sense. bt i cn email u d whole question if u want.

  5. #5
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    Quote Originally Posted by jayti View Post
    thnx a lot for the hel, i tried your way n it almost workd. i have used d switch statements in my main class n if the user entered o of p then the output they should get, is suppose to be in the other class(so here it will be in myclass). bt v cannot use any print statements.
    I don't understand your reply. Are you posting from a phone and using short-text? It would help if you could spell out words instead of using acronyms. (I'm guessing cn=can, bt=but, n=and ? It is hard to decipher what is a word and what might be a variable. Just thought I'd mention it for future posts! )

    It sounds as though you probably need a method within your second class that will take a parameter, but I'm just guessing here because I'm not sure what you have done so far.

    Maybe pass the user's input as a parameter and return a variable. An example of passing parameters:

    Java Code:
    class MyClass {
       public MyClass() {  //constructor
       }
       public int calculation() {  //method that returns an integer
          int result = 2 * 3;
          return result;
       }
       public int timesTwo(int number) {  //takes an integer parameter, returns an integer 
          int result = 2 * number;
          return result;
       }
    }
    This is how you would call the new timesTwo method in MyClass:

    Java Code:
    MyClass example = new MyClass();  //instantiates an object of MyClass
    int value = example.timesTwo(6);   //calling method timesTwo and passing an integer
    ~Chris
    Last edited by tashimoto; 11-23-2010 at 05:51 PM. Reason: fixed capitalization in code on MyClass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Wow...txt spk ovrkll.

  7. #7
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    @Tolls
    Which works if text messaging to friends, but does not work when talking about a subject that has its own language and terms, made-up variables, and where other readers use English-to-Another Language translators. :)

    @jayti
    Did you get your program working??
    Last edited by tashimoto; 11-24-2010 at 06:26 PM. Reason: Added question for OP

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by jayti View Post
    i dnt if this makes sense.
    t dsnt.u tnk t shd?

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Quote Originally Posted by tashimoto View Post
    @Tolls
    Which works if text messaging to friends, but does not work when talking about a subject that has its own language and terms, made-up variables, and where other readers use English-to-Another Language translators. :)
    I know. Which is why I said (in translation) "Text speak overkill".
    I think you'll find enough posts on here from me informing people that txt spk is not helpful...:)

  10. #10
    jayti is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 09-30-2010, 08:16 PM
  2. if else if statements
    By Allspark in forum New To Java
    Replies: 9
    Last Post: 09-28-2010, 06:50 PM
  3. Help with if else statements
    By np2392 in forum New To Java
    Replies: 2
    Last Post: 09-24-2010, 01:25 AM
  4. age: using if statements
    By yasmin k in forum New To Java
    Replies: 2
    Last Post: 10-04-2009, 09:50 PM
  5. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •