Jump to content

please post source code in [ code ] tags. most people (including myself) will be unwilling to download random programs off the internet.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/1116388-i-made-a-program/#findComment-12989554
Share on other sites

Link to post
Share on other sites

1 hour ago, vorticalbox said:

please post source code in [ code ] tags. most people (including myself) will be unwilling to download random programs off the internet.

import java.util.Scanner;
public class GuessingGame
{public static void main(String [ ] args)
    {
      Scanner in;
      in = new Scanner(System.in);
      char gameWon = 'N';
      int randNum = (int)(Math.random()*99) + 1;
      int counter = 0;
      while(gameWon == 'N')
      {  
      System.out.println("A Random Number Between 1-100 Has been selected, Try and guess!");
      int guess1 = in.nextInt();
      if(guess1 == randNum){
      counter ++;
      gameWon = 'Y';}
      if(guess1 > randNum)
      System.out.println("Number of Guesses:" + counter);
      if(guess1 > randNum)
      counter ++;
      if(guess1 > randNum)
      System.out.println("Your Guess was too High");
     if(guess1 < randNum)
      counter ++;
      if(guess1 < randNum)
      System.out.println("Your Guess was too Low");
      if(guess1 < randNum)
      System.out.println("Number of Guesses:" + counter);
    }
      if(counter >= 1 && counter <= 3)
      System.out.println("Excellent Guessing!");
      if(counter >= 4 && counter <= 6)
      System.out.println("Good Guessing, You have Talent!");
      if(counter >= 7 && counter <= 10)
      System.out.println("Your Guessing Skills are good!");
      if(counter >= 10)
      System.out.println("Keep Practicing");
    
      
        
        
        
        
        
        
        
        
        
    }
}
 

Link to comment
https://linustechtips.com/topic/1116388-i-made-a-program/#findComment-12989653
Share on other sites

Link to post
Share on other sites

9 minutes ago, dgsddfgdfhgs said:

I could try out any unknown source, coz this is my office pc lol

i'm at the office too, we create a financial CRM that handles millions per month and 1000s of customer private information so rather not risk me job lol

p.s you missed the code tags

print("ew java")

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/1116388-i-made-a-program/#findComment-12989673
Share on other sites

Link to post
Share on other sites

Okay, a few things for improvement:

  • You should improve your formatting. Code has to be easily readable. You can make out the flow of a program by well intended blocks, it's lacking that now.
  • Why gameWon is not a bool? You use it as a bool, but it's not a bool.
  • Too many if statements. You actually need maybe just three + plus a while loop. Now you've got 11 (and a while loop). Consequently you have 12 control flow cases. For such a simple program that's enormous.

EDIT:

  • You manage to use System.out.println 9 times in this, way too much for this.
  • Code duplication. Some if statements are exactly the same. In the same block. Execute right after each other.
Link to comment
https://linustechtips.com/topic/1116388-i-made-a-program/#findComment-12989694
Share on other sites

Link to post
Share on other sites

8 minutes ago, DevBlox said:

You manage to use System.out.println 9 times in this, way too much for this.
 

Any code that is repeated like this is a good indication that you need to refactor it to a function

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/1116388-i-made-a-program/#findComment-12989701
Share on other sites

Link to post
Share on other sites

3 hours ago, DevBlox said:

Okay, a few things for improvement:

  • You should improve your formatting. Code has to be easily readable. You can make out the flow of a program by well intended blocks, it's lacking that now.
  • Why gameWon is not a bool? You use it as a bool, but it's not a bool.
  • Too many if statements. You actually need maybe just three + plus a while loop. Now you've got 11 (and a while loop). Consequently you have 12 control flow cases. For such a simple program that's enormous.

EDIT:

  • You manage to use System.out.println 9 times in this, way too much for this.
  • Code duplication. Some if statements are exactly the same. In the same block. Execute right after each other.

Ok Thanks for all the feedback

 

 

AND yes Sorry I realize now that was was dumb of me to do. I should have put my source code.

Link to comment
https://linustechtips.com/topic/1116388-i-made-a-program/#findComment-12990058
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×