Jump to content

I need a big favor with project for college

unfortunetly it must do real modifications on disk such as creating a new folder that user wished for  than. ofc make some files make the function that allows user to move around folders

and so on. I try to google by myself most of functions and how to use them or implement but information i found and used so far didint work out.

For this issue i currently found that case maybe my varriable called filename (later i propably will change it to foldername for more clearance) that does not take any input from user because its inside another varriable that takes input too but i am not sure for 100 %.

 

Tbh i didint even get a clue from your method and i dont like C (we used it on our previous year it was a disaster for me after i was learning javascript alone back than ).

 

And ofc i appreciate the fact you want to throw rescue circle in critical time lol (although i made progress atleast got some basic code for now) :P

 

Well, my method assumed you were just simulating it so it's not relevant in this case. Unfortunately I don't have a lot of experience with java, so I can't really help you there. Try stackoverflow.com, there are professional programmers there that will most likely be able to answer all your questions way better than a software engineering student like me. I must warn you though, they're alergic to requests of doing the work for you, so try to avoid asking them directly to do your assignment.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

bumping additional help cuz the Nulu has hands full propably (jugdin by breaks of his answer) and i hope it wont make any problems  :P

 

Indeed. I am currently suffering from skull splitting toothache courtesy of the NHS.

 

-code snip-

 

now i get a problem with my method, so first it does not create folder no matter what i type, second when i dug in the net i found getDataFolder() that is used for some codes from ppl and when i try to implement it it screams with error that he cant find symbol any idea how to make it work :S? because than i will create if statement that simple in metod and make move on to another classes :P

 

You can instantiate a File class by passing in the path you want as a String. You haven't declared a method 'getDataFolder()' anywhere so that's why that won't work. I haven't run your code because I don't have time right now but what were you trying to accomplish with that method?

 

Furthermore your switch logic is outside of your main control loop therefore anything you want evaluated won't be, apart from 'exit' of course.

 

Regarding more general architecture, it's good that you already have the idea of a class for your commands at this stage. Indeed the way I would start this is to contain my commands in one class to begin with; I would make them quite dumb as well, by that I mean everything that's needed to perform the command is passed in rather than setup/acquired as a responsibility of the command class and/or particular method itself. Any exceptions that are thrown should be allowed to propagate back to the main control loop and be handled there appropriately. You want to aim for separation of concerns and encapsulation of implementation detail. In other words the command class shouldn't be acquiring user input, it should consume that instead as a parameter - keep your concepts cleanly separated.

 

While we are talking about architecture, once you have a little more implementation built up you may like to consider the Command design pattern. It should be a relatively straightforward refactor once you arrive near to end and will give you the ability to support an undo/redo stack for bonus points! For now though certainly keep going in the most simple and concrete way that you can.

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

Indeed. I am currently suffering from skull splitting toothache courtesy of the NHS.

 

 

You can instantiate a File class by passing in the path you want as a String. You haven't declared a method 'getDataFolder()' anywhere so that's why that won't work. I haven't run your code because I don't have time right now but what were you trying to accomplish with that method?

 

Furthermore your switch logic is outside of your main control loop therefore anything you want evaluated won't be, apart from 'exit' of course.

 

Regarding more general architecture, it's good that you already have the idea of a class for your commands at this stage. Indeed the way I would start this is to contain my commands in one class to begin with; I would make them quite dumb as well, by that I mean everything that's needed to perform the command is passed in rather than setup/acquired as a responsibility of the command class and/or particular method itself. Any exceptions that are thrown should be allowed to propagate back to the main control loop and be handled there appropriately. You want to aim for separation of concerns and encapsulation of implementation detail. In other words the command class shouldn't be acquiring user input, it should consume that instead as a parameter - keep your concepts cleanly separated.

 

While we are talking about architecture, once you have a little more implementation built up you may like to consider the Command design pattern. It should be a relatively straightforward refactor once you arrive near to end and will give you the ability to support an undo/redo stack for bonus points! For now though certainly keep going in the most simple and concrete way that you can.

import java.util.Scanner;import java.io.File;class crf { Scanner user_input = new Scanner(System.in); //String filename;   public void createf(String filename, String komenda){   //filename = "crf " + user_input.next();     File createfolder = new File(filename);     if(komenda.equals("crf "+user_input.nextLine())){     createfolder.mkdir();     System.out.println("troololo");     }     } }    public class SystemShell {    public static void main(String[] args) {        final String ExitCondition = "exit";        Scanner user_input = new Scanner(System.in);               String Userpath1 = System.getProperty("user.dir");        String komenda;        do        {     System.out.print(Userpath1 +" ");     komenda = user_input.nextLine(); switch(komenda){     case "crf ":                  crf newFolder = new crf();String filename = user_input.next();           newFolder.createf(user_input.nextLine(),user_input.nextLine());        System.out.print(Userpath1 +" " + "folder zostal utworzony");                          break;          }        }while (!komenda.toLowerCase().equals(ExitCondition));  }}

i done smth like this and it does not work out still and input looks like this :

run:

D:\PP\SystemShell\SystemShell crf nowy

D:\PP\SystemShell\SystemShell crf D:\nowy

D:\PP\SystemShell\SystemShell 

Where crf thingy is my input from keyboard whihc should trigger method but it doesnt not even single time despite fact i made good arguments (atleat i think so ) to trigger method ... i have no ideas left for even such simple command and i dont wanna image what will happen when i will need to make user move around folders on the system or even give some privilages...

[spoiler = 'edits'] 

EDIT:

ITS finally working LOL . Now lets do a move around functions so that user can change his current location to another one any ideas ?

 

EDIT 2:

okay so fati made the code look like this:

import java.util.Scanner;import java.io.File;class crf { Scanner user_input = new Scanner(System.in);   public void createf(String filename){            File createfolder = new File(filename);     if(  !createfolder.exists()){     createfolder.mkdir();     System.out.println("twoj folder zostal utworzony");     }else{          System.out.println("twoj folder juz istnieje");     }     }   public void createfs(String filename1){        File createfolders = new File(filename1);     if(  !createfolders.exists()){     createfolders.mkdirs();     System.out.println("twoj folder zostal utworzony");     }else{          System.out.println("twoj folder juz istnieje");     }   } }    public class SystemShell {    public static void main(String[] args) {        final String ExitCondition = "exit";        Scanner user_input = new Scanner(System.in);        String Userpath1 = System.getProperty("user.dir");        String komenda;        do        {     System.out.print(Userpath1 +" ");     komenda = user_input.next(); switch(komenda){     case "crf":                  crf newFolder = new crf();String filename = user_input.next();           newFolder.createf(filename);                      break;      case "crf\tree" :           crf newFolders = new crf();String filename1 = user_input.next();         newFolders.createfs(filename1);         break;  }        }while (!komenda.toLowerCase().equals(ExitCondition));  }}             

propably making files will be very similar to folder so i will leave it later but i made a argument to the first command that makes multiple folders.

Now i want to change my location is there any possible way?

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay quick update : so i made the command that changeds current user location but somehow command to exit is not working properly by that i mean the user needs to type it like 4 times (cuz i assume thats because of switch number of cases) untill it will work so any idea how to make it work after 1 try of typing?

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay quick update : so i made the command that changeds current user location but somehow command to exit is not working properly by that i mean the user needs to type it like 4 times (cuz i assume thats because of switch number of cases) untill it will work so any idea how to make it work after 1 try of typing?

 

There's not really anything to go on without your code.

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

There's not really anything to go on without your code.

import java.util.Scanner;import java.io.File;class crf { Scanner user_input = new Scanner(System.in);   public void createf(String filename){            File createfolder = new File(filename);     if(  !createfolder.exists()){     createfolder.mkdir();     System.out.println("twoj folder zostal utworzony");     }else{          System.out.println("twoj folder juz istnieje");     }     }   public void createfs(String filename1){        File createfolders = new File(filename1);     if(  !createfolders.exists()){     createfolders.mkdirs();     System.out.println("twoj folder zostal utworzony");     }else{          System.out.println("twoj folder juz istnieje");     }   } }class chpt {    public void changepath(String newpath){        File newpth = new File(newpath);               newpth.toPath();            }}    public class SystemShell {    public static void main(String[] args) {        final String ExitCondition = "exit";        Scanner user_input = new Scanner(System.in);        String Userpath1 = System.getProperty("user.dir");        String komenda;        do        {     System.out.print(Userpath1 +" ");     komenda = user_input.next(); switch(komenda){     case "crf":                  crf newFolder = new crf();String filename = user_input.next();           newFolder.createf(filename);                      break;      case "crf\tree" :           crf newFolders = new crf();String filename1 = user_input.next();         newFolders.createfs(filename1);         break;     case "chupth":         String newpath = user_input.next();         chpt setpath = new chpt();         setpath.changepath(newpath); Userpath1= newpath; break;              }        }while (!komenda.toLowerCase().equals(ExitCondition));  }}

You ask you have it :P

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

You ask you have it :P

 

Okay quick update : so i made the command that changeds current user location but somehow command to exit is not working properly by that i mean the user needs to type it like 4 times (cuz i assume thats because of switch number of cases) untill it will work so any idea how to make it work after 1 try of typing?

 

I can't reproduce the behaviour you described. I tried 'chupth C:/' and then 'exit' and the program terminated successfully. However if I enter 'chupth' and then 'exit' it won't terminate right way, this is because I am now inside the 'chupth' case block awaiting user input - that we don't ever check for being an exit condition.

 

A fix for this would be to treat each command as a whole, succinct and discrete entity. Have a think about how the Windows terminal commands work; we have to do something like 'mkdir <valid directory>' or 'mkdir /?' for help. If we just entered 'mkdir' then we get an error because it's not valid for that particular command. Now think about 'telnet' - that's a whole application. When you type 'telnet' into the terminal it launches an application and you are then within its specific context. Now think about 'ping' and 'tracert'.

 

Your commands are currently working similar to what happens when you launch up 'telnet'. In other words you completely switch context and the process flow is somewhere else, doing something else. In your case you change what the user input means from being in a context where they select a command to a context where they are within a command.

 

Hopefully this makes sense...

 

In any event the switch statement will evaluate each case in one pass.

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

 

 

 

I can't reproduce the behaviour you described. I tried 'chupth C:/' and then 'exit' and the program terminated successfully. However if I enter 'chupth' and then 'exit' it won't terminate right way, this is because I am now inside the 'chupth' case block awaiting user input - that we don't ever check for being an exit condition.

 

A fix for this would be to treat each command as a whole, succinct and discrete entity. Have a think about how the Windows terminal commands work; we have to do something like 'mkdir <valid directory>' or 'mkdir /?' for help. If we just entered 'mkdir' then we get an error because it's not valid for that particular command. Now think about 'telnet' - that's a whole application. When you type 'telnet' into the terminal it launches an application and you are then within its specific context. Now think about 'ping' and 'tracert'.

 

Your commands are currently working similar to what happens when you launch up 'telnet'. In other words you completely switch context and the process flow is somewhere else, doing something else. In your case you change what the user input means from being in a context where they select a command to a context where they are within a command.

 

Hopefully this makes sense...

 

In any event the switch statement will evaluate each case in one pass.

 

now i gonna do plot twist, after finding out that actually if i type my command as in cmd it will work out unless its command with argument becasue the case with crf -tree take -tree as argument to case crf which makes folder (which is strange in my opinion ) but if i do like you said on telnet method it works fine but crf and chupth  can be done like in windows cmd and chupth change user location but after that the exit is not working and did you try typing exit after just run program ? because than i got that 4 typing bug.

 

And how can i make each command lets say a separate instance? Because i think case here is most suited one or it should be but dunno why it does not work like this as i described earlier . I can try to make them as thread but dunno if that wont make things worse and more complicated than they should be :S.

Oh and i kinda dont know try and catch instruction too :P

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

...did you try typing exit after just run program ?

 

Yes and it works correctly.

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

Yes and it works correctly.

okay atleast we know this one ... how about rest of my question xD?

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

okay atleast we know this one ... how about rest of my question xD?

 

Sorry I think you edited after I had posted and moved away.

 

I can try to make them as thread but dunno if that wont make things worse and more complicated than they should be :S.

 

I think for now involving more threads is not necessary and will just overcomplicate things.

 

And how can i make each command lets say a separate instance? Because i think case here is most suited one or it should be but dunno why it does not work like this as i described earlier .

 

In the most simplest case close the context of execution. In other words make the command act in the same way as I described for 'mkdir <argument>'; it will throw if you simply enter 'mkdir' or provide an invalid argument or do something if you specify a valid one. This way you won't be changing context/paradigm on your user. The command will execute or fail in one operation, you won't have two steps to get the command to execute.

 

You can still do this in a switch for now but later you may want to move each command out into a class/static method. Later still you may want to start thinking about the Command design pattern that I mentioned earlier. For now though I would recommend that you go with the Agile doctrine of getting the simplest and most concrete thing working first then refactoring later.

 

Oh and i kinda dont know try and catch instruction too  :P

 

That's why we have this excellent resource here.

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

Sorry I think you edited after I had posted and moved away.

 
 

 

I think for now involving more threads is not necessary and will just overcomplicate things.

 

 

 

In the most simplest case close the context of execution. In other words make the command act in the same way as I described for 'mkdir <argument>'; it will throw if you simply enter 'mkdir' or provide an invalid argument or do something if you specify a valid one. This way you won't be changing context/paradigm on your user. The command will execute or fail in one operation, you won't have two steps to get the command to execute.

 

You can still do this in a switch for now but later you may want to move each command out into a class/static method. Later still you may want to start thinking about the Command design pattern that I mentioned earlier. For now though I would recommend that you go with the Agile doctrine of getting the simplest and most concrete thing working first then refactoring later.

 
 

 

That's why we have this excellent resource here.

about the commands part if i undestand you correctly you want me to do smth like nameoffileclassvarriable.mkdir(argument)? If yes than sadly i cant do that because mkdir function cant take argument inside itself. Other than that i cant think of anything despite brief reading of your command pattern (more like i was searching most important parts there :S). and btw try to type for example cfr D:\smth in one line you will see it will work (i got suprised) ;p

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

about the commands part if i undestand you correctly you want me to do smth like nameoffileclassvarriable.mkdir(argument)? If yes than sadly i cant do that because mkdir function cant take argument inside itself.

No your not understanding me. I'm meaning that you should try to match the behaviour of the Windows terminal command 'mkdir' (just an example nothing special). Specifically the way that it's a single step execution.

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

No your not understanding me. I'm meaning that you should try to match the behaviour of the Windows terminal command 'mkdir' (just an example nothing special). Specifically the way that it's a single step execution.

so i should add something like if(komenda.equals("crf ")){some error} else the real code?

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

so i should add something like if(komenda.equals("crf ")){some error} else the real code?

Perhaps. Or perhaps you could check what the string starts with for your switch analysis or even tokenize it and check it against a dictionary of commands.

The possibilities are numerous.

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

Perhaps. Or perhaps you could check what the string starts with for your switch analysis or even tokenize it and check it against a dictionary of commands.

The possibilities are numerous.

maybe but the form of them which i should create is unknown even for me and fun fact i didint mention earlier is that when i tried to make komenda into user_input.nextLine() the switch was not even workin :P. And i would be greatfull for example of tokenize method or that switch method it is possible ofc because look how i much of your previous example gave me idea how to make exit command which i could do as switch command :P

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

maybe but the form of them which i should create is unknown even for me and fun fact i didint mention earlier is that when i tried to make komenda into user_input.nextLine() the switch was not even workin :P. And i would be greatfull for example of tokenize method or that switch method it is possible ofc because look how i much of your previous example gave me idea how to make exit command which i could do as switch command :P

Ok if I were to approach this I would start by basing my model exactly on the way that the Windows command line works. Specifically the commands that you execute in one line. The user enters a command and either an error occurs or something executes. The simplest implementation first.

I would start by splitting the user input on the space character. The first index will be the command name and all others the parameters. I would have an interface for a command that has at least an execute method that takes a String list - the command parameters. I would make a number of concrete implementations of this to represent things like making a directory or navigating a path and so on. These I would store in a dictionary of type <String, interface> where the String key is the name of the command and the interface value is the command class. The user enters a command and if it exists in the dictionary then it is executed with the parameters else we report an unknown command.

If I felt that commands were fairly small bits of functionality I may be inclined to think about using lambdas to represent them. Although right now it seems less clean.

This way we have begun the journey to separate and encapsulated what a command means from the rest of the code and also to form the basis of a Command pattern implementation.

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

Oh i forgot that when i made smth like crf-tree the case for that worked without executing crf one :P plus i will think about it

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay i did not post of a long time but well kinda was feeling meh but now i got an idea . So i need to make like 2 java projects one that we speak about it here on topic and second that i wanted to make alone but unfortunetly i cant handle my second project well although its more builded and half way completed . So i decided that i gonna change a direction of this topic for the sake of 2 project to make it finish fast and make more time for the SystemShell project.

 

I hope you will help me out like you did with 1 project .

 

My current problem with 2 project is that my arguments to do while loop are not good (the loop does not end like i want to ). the argument for loop is like this :

while(!(LordVader.zyciesith>0) || (newTimelimit.czas_walki>0));

And now i made variable in class called Rycerzsith and varriable is zyciesith that equals to 200 (LordVader is new instance of that class) and i made timer that should end after hmm 5 mins or so . And now i made a pop up when timer ends and it works but when varriable LordVader.zyciesith is at 0 or less than 0 loop should ended but it doesnt the user can still make move (cuz its a game) and the loop does not end what is funny the loop does not end even if time out pop up has prompted . 

Any ideas why ?

Rest of that code in spoiler (SPOILER ALERT ITS LONG!)

do {    System.out.println("Zycie przeciwnika "+LordVader.zyciesith + "           " +" Mana "+ LordVader.manasith +"\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"\n");           System.out.println("twoje zycie "+zycie+"    "+"twoja mana " +mana);    System.out.println("Wybierz swoj ruch");    System.out.println("1. Podstawowy atak");    System.out.println("2. Podwojne ciecie mieczem");    System.out.println("3. uzycie umiejetnosci "+ userJedi.umiejetnosc);    b=user_input.nextInt();    switch (b){        case 1:        LordVader.zyciesith = LordVader.zyciesith -  basic_attack_damage;        break;        case 2:       LordVader.zyciesith = LordVader.zyciesith -  light_saber_double_slash;        break;        case 3:        if (userJedi.umiejetnosc.equals("lighting") && cdr<=0){            System.out.println("Uzyles umiejetnosci lighting!");                       LordVader.zyciesith=LordVader.zyciesith - lighting_spell_dmg;            mana=mana-40;        cdr = 50;             System.out.println("Przez następne 2 tury nie mozesz uzyc umiejetnosci");        cdr--;        if(!(cdr<=0) && b==3){ System.out.println("Ta umiejetnosc jeszcze nie zostala odnowiona"); cdr--;}    }else if(userJedi.umiejetnosc.equals("force push") && cdr<=0){         System.out.println("Uzyles umiejetnosci lighting!");                     LordVader.zyciesith= - force_push_damage;            mana=mana-20;            force_push_stun = damage.nextInt(0)+1;            if ( force_push_stun == 0){                 System.out.println("przeciwnik nie zostal ogluszony");                }else if ( force_push_stun == 1){                    System.out.println("przeciwnik  zostal ogluszony na 2 rundy");                }            cdr = 50;             System.out.println("Przez następne 2 tury nie mozesz uzyc umiejetnosci");                     cdr--;       if(!(cdr<=0) && b==3){ System.out.println("Ta umiejetnosc jeszcze nie zostala odnowiona"); cdr--;}    }    break;}}while(!(LordVader.zyciesith>0) || (newTimelimit.czas_walki>0));

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Ok if I were to approach this I would start by basing my model exactly on the way that the Windows command line works. Specifically the commands that you execute in one line. The user enters a command and either an error occurs or something executes. The simplest implementation first.

I would start by splitting the user input on the space character. The first index will be the command name and all others the parameters. I would have an interface for a command that has at least an execute method that takes a String list - the command parameters. I would make a number of concrete implementations of this to represent things like making a directory or navigating a path and so on. These I would store in a dictionary of type <String, interface> where the String key is the name of the command and the interface value is the command class. The user enters a command and if it exists in the dictionary then it is executed with the parameters else we report an unknown command.

If I felt that commands were fairly small bits of functionality I may be inclined to think about using lambdas to represent them. Although right now it seems less clean.

This way we have begun the journey to separate and encapsulated what a command means from the rest of the code and also to form the basis of a Command pattern implementation.

a little bump cuz i dunno if you get the notification ;P and for some extra explanation about code in spoiler so all variables that are decreasing value of zyciesith have a value (a random one) and some function may not work as intenderd too like my spell system that user uses spell and cant use it for like 50 sec but it does not work :P

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

There's quite a lot of specific context there. I think that you are trying to say that you are having problems with the fundamentals of process flow control and the basics of logical expressions i.e. your loop conditions.

 

Have you tried using the debugger to walk through your code?

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

well i didnt use debugger hmm unless we arent talking about error notifications in the intepreter or smth like that...

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

well i didnt use debugger hmm unless we arent talking about error notifications in the intepreter or smth like that...

 

I'm not sure what you mean by error notifications. Have a look here, it describes how you can use Eclipse to debug a Java application. In any event the concept itself is transient across most IDEs. In a basic sense one sets a breakpoint, runs the program in debug and then the process flow is halted at the breakpoint thus allowing one to step through the code inspecting, watching and modifying variables as they go.

 

Have you been doing this? Because if you have I'd be very surprised if you still need to ask why your loop conditions are not working...

 

As a side note, IntelliJ is far superior to Eclipse for Java development given the context of use i.e. non commercial. It's built around their ReSharper technology and offers far superior capabilities including much better debugging.

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

Can i add to switch variable that is random ? cuz i made a method with such switch and dont know if its working >.>

int d = ruch.nextInt(3)+1; switch(d){

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Can i add to switch variable that is random ? cuz i made a method with such switch and dont know if its working >.>

 

Yes you can but you would have already known this if you had followed any of the information in my previous post now wouldn't you? Do you understand how to debug?

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

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

×