Jump to content

Java program!

Go to solution Solved by EG!,
Random random = new Random();
int  randomNumber = random.nextInt(9) + 1;

Would be a random number from 1 to 10 feed that to the switch or your if's or some if elses.

package meetöihi;

/**
 *
 */
import java.util.Scanner;

public class Meetöihi {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        int x;
        Scanner input = new Scanner(System.in);
        System.out.println("Osrs Skilling machine !");

        System.out.println("Choose number 1-9");
         Scanner op = new Scanner(System.in);
        String operation = op.next();
       
        if (operation.equals("1")) {
            System.out.println("Runecrafting");
        }
        if (operation.equals("3")) {
            System.out.println("Woodcutting");
        }
         if (operation.equals("4")) {
            System.out.println("Mining");
        }
          if (operation.equals("5")) {
            System.out.println("Agility");
        }
           if (operation.equals("6")) {
            System.out.println("Smithing");
        }
            if (operation.equals("7")) {
            System.out.println("Fletching");
        }
           
    
}
}

So im doing thing called skilling machine, is it possible to get if(operation.equals("number)) to be random number so this machine would be better

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, Dat Guy said:

Yes.

well do you know how i have tried couple methods but they didnt work

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, bomberblyat said:

well do you know how i have tried couple methods but they didnt work

Could you specify further what you want?

First of all you'd better use a switch instead of just if's

switch (number){
	case 1:
		system.out.println("Thieving");
		break;
	case 2:
		system.out.println("Thieving");
		break;
	default:
		system.out.println("AFK");
		break;
}

and if you want to stack if's use if else statements.

 

As for a random number do you mean that the a 'skil' has a random number or what do you mean?

Desktop

CPUi5-6600K MotherboardGigabyte GA-Z170-HD3P CPU Cooler: Thermalright True Spirit 120M Black/white RAM: Corsair Vengeance LPX 16 GB DDR4 2400Mhz GPU: Gigabyte 1070 HDDs: 2 x Seagate Barracuda 2TB 7200 RPM  SSDSamsung EVO 850 500GB PSU: Coolermaster 550W 80+ Gold Case: NZXT S340 (White) with a white led strip ;)

Laptops

Dell 7577

CPUi7 7700HQ RAM: 16 GB DDR4 2400Mhz GPU: GTX1060 Max-q HDD: 1TB 5400 RPM  SSDNVMe 512GB SCREEN: 4k IPS 15.6"

Macbook pro 2018

CPUi7 RAM: 16 GB DDR4 2400Mhz GPU: Radeon Pro 555X 4GB Storage256GB SCREEN: 15"

Link to comment
Share on other sites

Link to post
Share on other sites

Random random = new Random();
int  randomNumber = random.nextInt(9) + 1;

Would be a random number from 1 to 10 feed that to the switch or your if's or some if elses.

Desktop

CPUi5-6600K MotherboardGigabyte GA-Z170-HD3P CPU Cooler: Thermalright True Spirit 120M Black/white RAM: Corsair Vengeance LPX 16 GB DDR4 2400Mhz GPU: Gigabyte 1070 HDDs: 2 x Seagate Barracuda 2TB 7200 RPM  SSDSamsung EVO 850 500GB PSU: Coolermaster 550W 80+ Gold Case: NZXT S340 (White) with a white led strip ;)

Laptops

Dell 7577

CPUi7 7700HQ RAM: 16 GB DDR4 2400Mhz GPU: GTX1060 Max-q HDD: 1TB 5400 RPM  SSDNVMe 512GB SCREEN: 4k IPS 15.6"

Macbook pro 2018

CPUi7 RAM: 16 GB DDR4 2400Mhz GPU: Radeon Pro 555X 4GB Storage256GB SCREEN: 15"

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, EG! said:

First of all you'd better use a switch instead of just if's

1 hour ago, EG! said:

and if you want to stack if's use if else statements.

That's highly questionable advice... Anytime when there's enough if elses clustered in one place to give off such a 'bad smell' then it's time to address the root of the problem i.e. the design. Specifically in the case employing something like the Command Pattern would be a better alternative by far.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, EG! said:

Could you specify further what you want?

First of all you'd better use a switch instead of just if's


switch (number){
	case 1:
		system.out.println("Thieving");
		break;
	case 2:
		system.out.println("Thieving");
		break;
	default:
		system.out.println("AFK");
		break;
}

and if you want to stack if's use if else statements.

 

As for a random number do you mean that the a 'skil' has a random number or what do you mean?

iIl explain basicly i want to make program which generates random numbers for all skills, like user puts 2 and it generates like dice roll 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, Nuluvius said:

That's highly questionable advice... Anytime when there's enough if elses clustered in one place to give off such a 'bad smell' then it's time to address the root of the problem i.e. the design. Specifically in the case employing something like the Command Pattern would be a better alternative by far.

I'm not trying to teach him how to use some design pattern or write clean code I just gave a better yet simple option for what he wrote.

3 hours ago, bomberblyat said:

iIl explain basicly i want to make program which generates random numbers for all skills, like user puts 2 and it generates like dice roll 

But why does the user have to put a number in then? Isn't it more logical for the user to give up a name and all your skills to be randomly generated with the random I stated above?

Desktop

CPUi5-6600K MotherboardGigabyte GA-Z170-HD3P CPU Cooler: Thermalright True Spirit 120M Black/white RAM: Corsair Vengeance LPX 16 GB DDR4 2400Mhz GPU: Gigabyte 1070 HDDs: 2 x Seagate Barracuda 2TB 7200 RPM  SSDSamsung EVO 850 500GB PSU: Coolermaster 550W 80+ Gold Case: NZXT S340 (White) with a white led strip ;)

Laptops

Dell 7577

CPUi7 7700HQ RAM: 16 GB DDR4 2400Mhz GPU: GTX1060 Max-q HDD: 1TB 5400 RPM  SSDNVMe 512GB SCREEN: 4k IPS 15.6"

Macbook pro 2018

CPUi7 RAM: 16 GB DDR4 2400Mhz GPU: Radeon Pro 555X 4GB Storage256GB SCREEN: 15"

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, EG! said:

I'm not trying to teach him how to use some design pattern or write clean code I just gave a better yet simple option for what he wrote.

But why does the user have to put a number in then? Isn't it more logical for the user to give up a name and all your skills to be randomly generated with the random I stated above?

you're right its more logical 

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, EG! said:

Random random = new Random();
int  randomNumber = random.nextInt(9) + 1;

Would be a random number from 1 to 10 feed that to the switch or your if's or some if elses.

Thanks a lot ! now it works perfectly ! now i just need to learn how to make GUI for it (im using netbeans)

Link to comment
Share on other sites

Link to post
Share on other sites

14 hours ago, EG! said:

I'm not trying to teach him how to use some design pattern or write clean code I just gave a better yet simple option for what he wrote.

That's no excuse for being lazy. Moreover there's nothing 'simple' about a rats nest of if else statements. The pattern that I linked can be employed as simply as a dictionary of lambdas for example, which would be far more readable and easier to extend.

1 hour ago, bomberblyat said:

im using netbeans

You may want to have a look at IntelliJ as it is the current industry standard.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

31 minutes ago, Nuluvius said:

That's no excuse for being lazy. Moreover there's nothing 'simple' about a rats nest of if else statements. The pattern that I linked can be employed as simply as a dictionary of lambdas for example, which would be far more readable and easier to extend.

You may want to have a look at IntelliJ as it is the current industry standard.

 

ill just stick with the netbeans since im student and my school is using it, do you have any tips/hints how do i create GUI for this program i iknow how to make GUI but dont know about the coding thing on that 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, bomberblyat said:

 

ill just stick with the netbeans since im student and my school is using it, do you have any tips/hints how do i create GUI for this program i iknow how to make GUI but dont know about the coding thing on that 

Please just try IntelliJ, most decent IDEs will be similar enough in their interfaces that it won't cause you many issues.

If you don't know how to make an integral part of your project, in this case a GUI, then either you have some textbook reading and instructor meetings ahead of you (for an academic program), or you are biting off more than you can handle. I recommend rethinking the implementation and features of this program, to hopefully bring it down to a more manageable size.

Too often people learn half a semester's worth of coding and then think they can be the next Notch. Start with smaller projects, work your way up.

Join the Appleitionist cause! See spoiler below for answers to common questions that shouldn't be common!

Spoiler

Q: Do I have a virus?!
A: If you didn't click a sketchy email, haven't left your computer physically open to attack, haven't downloaded anything sketchy/free, know that your software hasn't been exploited in a new hack, then the answer is: probably not.

 

Q: What email/VPN should I use?
A: Proton mail and VPN are the best for email and VPNs respectively. (They're free in a good way)

 

Q: How can I stay anonymous on the (deep/dark) webzz???....

A: By learning how to de-anonymize everyone else; if you can do that, then you know what to do for yourself.

 

Q: What Linux distro is best for x y z?

A: Lubuntu for things with little processing power, Ubuntu for normal PCs, and if you need to do anything else then it's best if you do the research yourself.

 

Q: Why is my Linux giving me x y z error?

A: Have you not googled it? Are you sure StackOverflow doesn't have an answer? Does the error tell you what's wrong? If the answer is no to all of those, message me.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, LtStaffel said:

Please just try IntelliJ, most decent IDEs will be similar enough in their interfaces that it won't cause you many issues.

If you don't know how to make an integral part of your project, in this case a GUI, then either you have some textbook reading and instructor meetings ahead of you (for an academic program), or you are biting off more than you can handle. I recommend rethinking the implementation and features of this program, to hopefully bring it down to a more manageable size.

Too often people learn half a semester's worth of coding and then think they can be the next Notch. Start with smaller projects, work your way up.

Alright thanks for advice's much appreciated !

Link to comment
Share on other sites

Link to post
Share on other sites

On 25-11-2017 at 7:56 PM, bomberblyat said:

Alright thanks for advice's much appreciated !

You can use JavaFX for your GUI, there is tool called scene builder in Netbeans which let's you drag and drop to build a simple GUI. On the other hand other IDE's like the good old eclipse will also have such tools and Intellij might have those too. If you know some javascript you could also build a GUI that way.

On 25-11-2017 at 10:53 AM, Nuluvius said:

That's no excuse for being lazy. Moreover there's nothing 'simple' about a rats nest of if else statements. The pattern that I linked can be employed as simply as a dictionary of lambdas for example, which would be far more readable and easier to extend.

You may want to have a look at IntelliJ as it is the current industry standard.

No offence to bomberblyat but have you seen the question he asked, if you haven't got the Java basics under control you want to teach him a design pattern which sole use is to be easier on the eye of an experienced programmer. I myself totally love design patterns such as builder for this reason but I don't see the use of someone who asks a basic question to give him an answer he couldn't come up with himself, Or is that a faulty logic of me? I think that maybe he's trying something to hard for a start.

Desktop

CPUi5-6600K MotherboardGigabyte GA-Z170-HD3P CPU Cooler: Thermalright True Spirit 120M Black/white RAM: Corsair Vengeance LPX 16 GB DDR4 2400Mhz GPU: Gigabyte 1070 HDDs: 2 x Seagate Barracuda 2TB 7200 RPM  SSDSamsung EVO 850 500GB PSU: Coolermaster 550W 80+ Gold Case: NZXT S340 (White) with a white led strip ;)

Laptops

Dell 7577

CPUi7 7700HQ RAM: 16 GB DDR4 2400Mhz GPU: GTX1060 Max-q HDD: 1TB 5400 RPM  SSDNVMe 512GB SCREEN: 4k IPS 15.6"

Macbook pro 2018

CPUi7 RAM: 16 GB DDR4 2400Mhz GPU: Radeon Pro 555X 4GB Storage256GB SCREEN: 15"

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, EG! said:

I think that maybe he's trying something to hard for a start.

I agree with you there.

1 hour ago, EG! said:

if you haven't got the Java basics under control you want to teach him a design pattern which sole use is to be easier on the eye of an experienced programmer.

However I don't agree here. Design patterns do not just make things easier on the eye... They improve readability, extensibility, encapsulation and facilitate good practices and principles; all of which are a part of Software Engineering theory and therefore should be learned as early as possible - along with the basics of the syntax. There's nothing daunting or scary about them, especially in this case since the pattern in question is applied in a very simple way using nothing more than a beginner should have already encountered at this point.

 

To summarize; yes exactly, I would teach a design pattern over offering up a rats nest mess of code. Better to do a job properly and completely than to do it half assed (assuming that one actually possesses the knowledge to do so of course ^_^).

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

58 minutes ago, Nuluvius said:

I agree with you there.

However I don't agree here. Design patterns do not just make things easier on the eye... They improve readability, extensibility, encapsulation and facilitate good practices and principles; all of which are a part of Software Engineering theory and therefore should be learned as early as possible - along with the basics of the syntax. There's nothing daunting or scary about them, especially in this case since the pattern in question is applied in a very simple way using nothing more than a beginner should have already encountered at this point.

Yes, yeah I do agree that it should be taught as early as possible but in this case I'm not so sure about it.:) Yes it was too quick of me to say that it's just about readability  (is there an expression to say I was to quick to say someting? In Dutch there's too quick through a corner but that doesn't sound like proper English)

Desktop

CPUi5-6600K MotherboardGigabyte GA-Z170-HD3P CPU Cooler: Thermalright True Spirit 120M Black/white RAM: Corsair Vengeance LPX 16 GB DDR4 2400Mhz GPU: Gigabyte 1070 HDDs: 2 x Seagate Barracuda 2TB 7200 RPM  SSDSamsung EVO 850 500GB PSU: Coolermaster 550W 80+ Gold Case: NZXT S340 (White) with a white led strip ;)

Laptops

Dell 7577

CPUi7 7700HQ RAM: 16 GB DDR4 2400Mhz GPU: GTX1060 Max-q HDD: 1TB 5400 RPM  SSDNVMe 512GB SCREEN: 4k IPS 15.6"

Macbook pro 2018

CPUi7 RAM: 16 GB DDR4 2400Mhz GPU: Radeon Pro 555X 4GB Storage256GB SCREEN: 15"

Link to comment
Share on other sites

Link to post
Share on other sites

51 minutes ago, EG! said:

Yes, yeah I do agree that it should be taught as early as possible but in this case I'm not so sure about it.:) Yes it was too quick of me to say that it's just about readability  (is there an expression to say I was to quick to say someting? In Dutch there's too quick through a corner but that doesn't sound like proper English)

 

3 hours ago, EG! said:

You can use JavaFX for your GUI, there is tool called scene builder in Netbeans which let's you drag and drop to build a simple GUI. On the other hand other IDE's like the good old eclipse will also have such tools and Intellij might have those too. If you know some javascript you could also build a GUI that way.

No offence to bomberblyat but have you seen the question he asked, if you haven't got the Java basics under control you want to teach him a design pattern which sole use is to be easier on the eye of an experienced programmer. I myself totally love design patterns such as builder for this reason but I don't see the use of someone who asks a basic question to give him an answer he couldn't come up with himself, Or is that a faulty logic of me? I think that maybe he's trying something to hard for a start.

I have looked this FX thingy for while now generate button works but ididnt get text field to work, it prints all to netbeans :/ its supposed to display on program so i just need textfield with my code dont have any clue how to do that, im quite busy now ill try again tomorrow. 

Link to comment
Share on other sites

Link to post
Share on other sites

35 minutes ago, bomberblyat said:

 

I have looked this FX thingy for while now generate button works but ididnt get text field to work, it prints all to netbeans :/ its supposed to display on program so i just need textfield with my code dont have any clue how to do that, im quite busy now ill try again tomorrow. 

Here's another JavaFX guide.

On the oracle download page there are Java 8 sample applications too, (Use ctrl+f "JavaFX 8 Demos" for quick navigation.)

 

BTW: there is a guide for other IDE's too.

Desktop

CPUi5-6600K MotherboardGigabyte GA-Z170-HD3P CPU Cooler: Thermalright True Spirit 120M Black/white RAM: Corsair Vengeance LPX 16 GB DDR4 2400Mhz GPU: Gigabyte 1070 HDDs: 2 x Seagate Barracuda 2TB 7200 RPM  SSDSamsung EVO 850 500GB PSU: Coolermaster 550W 80+ Gold Case: NZXT S340 (White) with a white led strip ;)

Laptops

Dell 7577

CPUi7 7700HQ RAM: 16 GB DDR4 2400Mhz GPU: GTX1060 Max-q HDD: 1TB 5400 RPM  SSDNVMe 512GB SCREEN: 4k IPS 15.6"

Macbook pro 2018

CPUi7 RAM: 16 GB DDR4 2400Mhz GPU: Radeon Pro 555X 4GB Storage256GB SCREEN: 15"

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, EG! said:

Here's another JavaFX guide.

On the oracle download page there are Java 8 sample applications too, (Use ctrl+f "JavaFX 8 Demos" for quick navigation.)

 

BTW: there is a guide for other IDE's too.

Thanks a lot i will definitely check those !

Link to comment
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

×