Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

HELP...... with Java Question.

  • 28-07-2013 11:02am
    #1
    Registered Users, Registered Users 2 Posts: 72 ✭✭


    I only started a java programming course and is my first time doing anything like this and I am stuck on the following question and was wondering if anyone who more proficient in java than i am could help..........

    Wrte a program called BooleanMethod.java that contains a method called isValid. This method should return a Boolean Value(decide yourself whether you want true or false). Call the method from the main method and store it in a boolean variable. If the value is true, then output to the screen "Is valid", otherwise output "Is not valid"....

    Can anyone help me with the coding for this please????


Comments

  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    no one will write code for you, attempt it yourself and then people might give you some help on how to finish it.


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Hi Ya,

    I have attempted it and am completely stuck - i have searched through all lecturers notes etc and they do not help in anyway... the following is what i have done so far.....

    class BooleanMethod{
    public static void main(String[] args){
    // call method
    isValid();
    }
    public static void isValid();
    boolean bool = true;
    }
    if(bool = true){
    System.out.println("Is Valid!!");
    else{
    System.out.println("Is not Valid!!");
    }
    }

    where do i go from here.....


  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    shanard wrote: »
    Hi Ya,

    I have attempted it and am completely stuck - i have searched through all lecturers notes etc and they do not help in anyway... the following is what i have done so far.....

    class BooleanMethod{
    public static void main(String[] args){
    // call method
    isValid();
    }
    public static void isValid();
    boolean bool = true;
    }
    if(bool = true){
    System.out.println("Is Valid!!");
    else{
    System.out.println("Is not Valid!!");
    }
    }

    where do i go from here.....

    Your code is quite close to what he is looking for.

    Step 1.
    This method should return a Boolean Value(decide yourself whether you want true or false).

    This method should be return type boolean.
    Declare a boolean.
    Then return that value.
    public static boolean isValid(){
    		boolean bool = true;
    		return bool;
    	}
    

    The next step is calling this from the main method and storing the result in a boolean called bool (this could be named something different).
    	public static void main(String[] args){
    		// call method
    		boolean bool = isValid();
    	}	
    

    Now we want to addon to our main method by printing out its value. This is done like so:
    if(bool [COLOR="Red"]==[/COLOR] true){
    			System.out.println("Is Valid!!");
    		} else{
    			System.out.println("Is not Valid!!");
    		}
    

    Notice the double equals this means compare the value bool and true, a single equals will just assign the value true (and if your on an older version of java this will compile and give you silly results).

    One other problem you made was
    public static void isValid();
    

    When declaring a method (function) it should end in a { bracket not a semi colon!

    SO the finished result looks like this:
    class BooleanMethod{
    	public static void main(String[] args){
    		// call method
    		boolean bool = isValid();
    		
    		if(bool == true){
    			System.out.println("Is Valid!!");
    		} else{
    			System.out.println("Is not Valid!!");
    		}
    	}
    	public static boolean isValid(){
    		boolean bool = true;
    		return bool;
    	}
    	
    	
    }
    

    You've got to work on your brackets using tabs like i've done above will greatly help you keep track of what brackets have been opened and not closed!


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Thanks a mil, mad turnip - makes sense - if i get stuck with anymore - are you available to review the code for me, as on the course i am doing, we only had the lecturer for 3 weeks and he gone since last friday, so being the first time doing java, it was a case of information overload during the 3 weeks.

    Cheers:)


    S.


  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    pm me on here but still post the thread and i'll see what I can do.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    FIT Software Development Assignment 1 (25%)
    Assignment Definition:
    You are required to write a Java program that models an employee management system. The program should have a menu style system that allows the user to choose from the following options:
     Enter an Employees details
     Retrieve an Employees details
     Exit the system
    Each employee will have a 6 digit ID number, a name, an address and a hire date. If the user chooses to enter an employee’s details, an employee object is created and the attributes are set. When the employee’s details are entered, they must be written to a text file called Employees.txt. The employee information must be written to the file in the following way:
    [ID] [Name] [Address] [Hire Date]
    e.g.
    123456 Joe Bloggs 24, High Street, Dublin 2 21/7/2013
    If the user chooses to retrieve an employee’s details, the user must be asked to enter the ID of the employee. The program must then search the Employees.txt file for the employee. If the employee is found, then the details should be printed to the screen.
    You MUST use object-oriented code in this assignment. Therefore, you must have an Employee class containing all of the attributes of an employee. The employee class should contain all the necessary constructors, getter/ setter methods etc. to allow creation of employee objects for storage in the file.
    Grading
    Marks are going for:
     Well written code. In other words, clear elegant Java code, using proper syntax, appropriate data types, variables, control structures, methods, objects etc.
     Well-structured code. Code must be properly indented, with ample spacing to promote clarity in your code.
     Adequate commenting. You must comment your code where appropriate.
    Program Requirements:
     The user should be asked to choose an option (as above).
     If the user chooses to enter in an employee’s details, they must be allowed input the ID, name, address and start date. If they choose to retrieve information about an employee, they must be allowed enter in an ID to use for the search.
     For each employee entered, the program should create an employee object for each person and write the details to the text file.
    Methods:
    Your employee class should contain the following methods:
    Getter and Setter methods for the following:
     ID (int)
     Name (String)
     Address (String)
     Start Date (String)
    Public constructor, i.e.
    Public Employee(int id, String name, String address, String date){
    }
    The constructor will set the values for the employee object.
    Public void display(){
    }
    This method will print out the employee’s details to the screen.
    Deliverables:
    You must save your Java files into a folder (the folder should be named with your full name), zip the folder and upload it to Moodle.


  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    shanard wrote:
    Hi MT.

    I put my assignment up as a reply of thread i set up last week and the code i wrote todate is below..... i not sure if i am even right and to be honest i do not know where to go to from here - it says something about setting up new class - which i assume is setting up different prorgam (yeah??) - and in here to specify all strings, ints etc relating to the question - but surely if we were initially asked to get the user to enter these details, why would we have to put them in here again - do you know what i mean????

    We have a bad teacher - really bad - he knows his stuff, but just cant relate any of it to us, and when we ask him anything, he just does it himself rather than telling us, and when we email him, it takes him a week to get back to us - ridiculous...and to top it off, we are after starting C couple days ago, so me being new to all this programming, i sort of just getting over information overload with Java, and now to be hit with C too - lol..... anyways cheers again MT - heres what i have done so far -

    import java.util.Scanner;
    import java.io.*;
    public class EmployeeManagementSystem{
    public static void main(String[] args){
    String s;
    //use the Scanner
    Scanner scan = new Scanner(System.in);
    try{ // use BufferedWriter to write the users details on file called "Employees.txt"
    BufferedWriter bw = new BufferedWriter(new FileWriter("Employees.txt"));
    System.out.println("Please enter an Employee ID Number");
    int ID = scan.nextInt(); //this line of code reads in the users input
    bw.write(" " + System.getProperty("line.seperator"));
    System.out.println("Please enter an Employee Name");
    String name = scan.next();
    bw.write(" " + System.getProperty("line.seperator"));
    System.out.println("Please enter an Employee Address");
    String address = scan.next();
    bw.write(" " + System.getProperty("line.seperator"));
    System.out.println("Please enter an Employee start date\n");
    String date = scan.next();
    bw.write(" " + System.getProperty("line.seperator"));
    // to close the BufferedWriter
    bw.close();
    //use the BufferedReader now to read the written file called "Employees"
    BufferedReader br = new BufferedReader(new FileReader("Employees.txt"));
    s = br.readLine();
    while(s != null){
    System.out.println(s);
    s = br.readLine();
    }
    br.close(); // this will close the buffered reader
    }catch(IOException e){
    System.out.println(e);
    }
    }
    }


    Question:
    The program should have a menu style system that allows the user to choose from the following options:
     Enter an Employees details
     Retrieve an Employees details
     Exit the system

    You have implemented option 1 and part of option 2. You also need to implement the other two options.

    The simplest way to do this exercise is to split the three functions into three different methods.

    Step 1: print out the option menu:
    System.out.println("What would you like to do?");
    System.out.println("1) Enter a new employees details");
    System.out.println("2) Search for an employee");
    System.out.println("3) Exit");
    

    You should then read in an integer and based on what number is inputed it should execute a different if statement e.g:
    if(action == 1){
    
    } else if(action == 2){
    
    } else if(action == 3){
    
    }
    

    Each of the three actions should be in 3 different methods to keep the code clean!
    If the user chooses to enter an employee’s details, an employee object is created and the attributes are set.

    You also need to create a class called Employee, with all the attributes of an employee for example (this is out of my head).
    public class Employee {
    private String name;
    private int id;
    }
    

    your writing to the file code is also not correct. It can be done in one write statement:
    bw.write(ID+" "+name+" "+address+" "+date+"\n");
    
    the \n indicates a new line you could also do this instead:
    bw.write(ID+" "+name+" "+address+" "+date);
    bw.newLine();
    

    also due to how hard disks work when you call the "write" method it does not write to the disk, instead it goes to a memory buffer and it will write to the disk when this buffer is either full or when the flush() method is called. In your code you need to add:
    bw.flush();
    
    above
    bw.close();

    Theres more I can comment on but start with this and reply back when you've made changes.

    PS: PLEASE USE [code] and closing code tags it makes everything much more tidy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Hi MT - I stuck am afraid - i input the changes (i think - i not sure if you meant for me to delete everything but your changes??? - please advise) - but it prints the menu to the screen ok, but exits when any key is pressed???? - i also setup the class Employee and put the 4 attributes in with no values - is that right - anyways here is the updated code - thanks again for all this - i picking more things up off yourself than i have off our teacher over 3 weeks.... thanks again....

    public static void main(String[] args){

    String s;

    //use the Scanner
    Scanner scan = new Scanner(System.in);

    // menu options for user
    System.out.println("What would you like to do?");
    System.out.println("1) Enter a new employees details");
    System.out.println("2) Search for an employee");
    System.out.println("3) Exit\n");


    int i = 0;
    if(i == 1){

    try{ // use BufferedWriter to write the users details on file called "Employees.txt"
    BufferedWriter bw = new BufferedWriter(new FileWriter("Employees.txt"));

    System.out.println("Please enter an Employee ID Number");
    int ID = scan.nextInt(); //this line of code reads in the users input

    System.out.println("Please enter an Employee Name");
    String name = scan.next();

    System.out.println("Please enter an Employee Address");
    String address = scan.next();

    System.out.println("Please enter an Employee start date\n");
    String date = scan.next();

    bw.write(ID+" "+name+" "+address+" "+date+"\n");

    // this is to call the flush method
    bw.flush();

    // to close the BufferedWriter
    bw.close();

    //use the BufferedReader now to read the written file called "Employees"
    BufferedReader br = new BufferedReader(new FileReader("Employees.txt"));

    s = br.readLine();
    while(s != null){
    System.out.println();

    s = br.readLine();
    }
    br.close(); // this will close the buffered reader
    }catch(IOException e){
    System.out.println(e);
    }
    //} else if( == 2){


    // } else if( == 3){

    }
    }
    }


  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    PLEASE USE
    and closing code tags it makes everything much more tidy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    PLEASE USE [code] and closing code tags it makes everything much more tidy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    PLEASE USE [code] and closing code tags it makes everything much more tidy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    Ok first off,
    after the option menu, we want to read in an int of what the user wants to do.
    In this case you have called your int "i", and set a value of 0, the problem is this value is always 0, we need it to read in from the command line so it should be like this:
    
    [code]
    int i = scan.nextInt();
    

    The next change I made is the code
    // use the BufferedReader now to read the written file called
    				// "Employees"
    				BufferedReader br = new BufferedReader(new FileReader(
    						"Employees.txt"));
    
    				s = br.readLine();
    				while (s != null) {
    					System.out.println();
    
    					s = br.readLine();
    				}
    				br.close(); // this will close the buffered reader
    

    does not need to be apart of writing a new employee to the text file. Rather this code should be used for searching for the employee in the text file aka task 2 of the program. So I have moved this code to below
    } else if (i == 2) {
    

    Lastly the 3rd task of the code is to exit when the action id 3 is recieved, this method call is:
    System.exit(0);
    
    The alternative is to reach the end of the main method but in the code i've provided below the System.exit call is made.

    PLEASE USE
    and closing code tags it makes everything much more tidy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    [code]
    
    import java.util.Scanner;
    import java.io.*;
    
    public class EmployeeManagementSystem {
    	public static void main(String[] args) {
    
    		String s;
    
    		// use the Scanner
    		Scanner scan = new Scanner(System.in);
    
    		// menu options for user
    		System.out.println("What would you like to do?");
    		System.out.println("1) Enter a new employees details");
    		System.out.println("2) Search for an employee");
    		System.out.println("3) Exit\n");
    
    		[COLOR="Red"]int i = scan.nextInt();[/COLOR]
    		if (i == 1) {
    
    			try { // use BufferedWriter to write the users details on file
    					// called "Employees.txt"
    				BufferedWriter bw = new BufferedWriter(new FileWriter(
    						"Employees.txt"));
    
    				System.out.println("Please enter an Employee ID Number");
    				int ID = scan.nextInt(); // this line of code reads in the users
    											// input
    
    				System.out.println("Please enter an Employee Name");
    				String name = scan.next();
    
    				System.out.println("Please enter an Employee Address");
    				String address = scan.next();
    
    				System.out.println("Please enter an Employee start date\n");
    				String date = scan.next();
    
    				bw.write(ID + " " + name + " " + address + " " + date + "\n");
    
    				// this is to call the flush method
    				bw.flush();
    
    				// to close the BufferedWriter
    				bw.close();
    
    			} catch (IOException e) {
    				System.out.println(e);
    			}
    		[COLOR="red"]} else if (i == 2) {[/COLOR]
    			try {
    				//the employee ID the user is searching for
    				[COLOR="red"]int searchId = scan.nextInt();[/COLOR]
    				// use the BufferedReader now to read the written file called
    				// "Employees"
    				BufferedReader br = new BufferedReader(new FileReader(
    						"Employees.txt"));
    
    				s = br.readLine();
    				while (s != null) {
    					System.out.println();
    
    					s = br.readLine();
    				}
    				br.close(); // this will close the buffered reader
    			} catch (IOException e) {
    				System.out.println(e);
    			}
    		} else [COLOR="red"]if (i == 3)[/COLOR] {
    			[COLOR="Red"]System.exit(0);[/COLOR]
    		}
    	}
    }
    

    Most functions are implemented in this code you just have to figure out how to get searching for an employees ID number working (try typing out how you do it in English as it may help). You also need to call the constructor of your Employee class and pass in the values that are written to the file Employees.txt

    Also do you know what methods / functions are?


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Hi MT.
    Sorry for delay in getting back to you but i got tied up.......not literally....
    Can you give me an example of what you mean when you say: -
    PLEASE USE [code] and closing code tags it makes everything much more tidy
    as i am only a novice.....thanks
    As regards Methods - are you on about calling methods and returning values to the method we called in our main method????
    If so we did it briefly....
    I will re-do assignment with your code and come back to you - thanks again for everything - i will owe you a pint or ten...
    S.


  • Advertisement
  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    It doesn't help anyone to do their homework for them...
    It doesn't help them if they later walk into a position and cannot code
    It doesn't help their classmates who they're competing against


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    CROO....
    I agree with you - however i am not getting anyone to do my homework - i am merely asking him to review my code and to let me know where i am going wrong - as well as pointing me in the right direction - WHAT IS WRONG WITH THAT?????:rolleyes:


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    mad turnip wrote: »
    no one will write code for you,

    You must be new here... people providing code in response to these sorts of requests, are extremely regular and irritating.


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    I could imagine they are and in no way do i intend on irritating anyone - a little guidance is all i ask for.....as i new to programming - as in BRAND NEW.....


  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    shanard wrote: »
    however i am not getting anyone to do my homework
    MT effectively wrote your first assignment and is on his way to doing the same again. I know he just wants to help... but in the end he's not.
    shanard wrote: »
    WHAT IS WRONG WITH THAT?????:rolleyes:
    Like I said. When you're done with your course you might get a nice grade but you won't be able to code.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    croo wrote: »
    MT effectively wrote your first assignment and is on his way to doing the same again. I know he just wants to help... but in the end he's not.


    Like I said. When you're done with your coarse you might get a nice grade but you won't be able to code.

    This, in the end its bad for everyone.


  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    I agree somewhat.


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    I agree also....Somewhat................ Somewhat being the operative word!!!!!

    How else is anyone meant to learn to code correctly and to use the correct codes / syntax if no one helps them!!!!


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,110 Mod ✭✭✭✭Tar.Aldarion


    I have less of a problem with this than some other examples, you are the code up and having problems, many just look for an answer. I'd prefer if you were just told the mistake instead of having the code written out though. In any case my adavice is to code it up from scratch after it's working and see if you have the same problems.


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    Code tagged samples, what you'd tried and error messages from the compiler will usually be enough for me to help.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    I think you need to re-read some of the material you have covered and attempt to understand what is being discussed in more detail.


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Thanks all for your advice - constructive or not - however, being new to programming, and in particular the type of course i am doing, basically we had to learn the basics of java in 3 weeks (3 and half days a week) - and although our lecturer is highly qualified in what he does, but is no teacher, and subsequently trying to get answers after college hours in more or less impossible as it roughly takes him 3 days to get back to anyone with problems. I feel with MT giving me advice, whether it is re-writing what i had already started doing, and by the way he breaks it down, i feel i can pick it up quicker this way in the few posts Mt replied to compared to the 3 weeks in class..... Also prior to getting in touch with MT i reviewed my notes on moodle over and over and if you seen them, to a novice they make no sense as all they are is bullet points and doesnt explain anything in a way it should do for a novice.....
    Hope this explains things!!!!


  • Registered Users, Registered Users 2 Posts: 1,082 ✭✭✭Feathers


    shanard wrote: »
    I agree also....Somewhat................ Somewhat being the operative word!!!!!

    How else is anyone meant to learn to code correctly and to use the correct codes / syntax if no one helps them!!!!

    If you make an error in the syntax, the compiler will give you an error. If you learn to understand these messages, you'll be able to fix syntax errors on your own - much more useful than having to ask someone every time.

    No-one is saying don't ask for help, it's just there's another way you could ask questions that means you'll learn more.

    Know that your lecturer must be frustrating to deal with, but when you get a job coding you'll be surrounded by senior devs, a lot of whom will be exactly like your lecturer - extremely talented, maybe not great teachers & with little time for what they see as basic, broad questions.

    The two biggest skills of a developer are knowing how to debug a problem to a specific cause & being able to ask a succinct question about that problem once you have found it.

    If you show people that you've put in the effort to narrow down your problem & tell them what you've tried so far, they'll be a lot more receptive.


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Cheers Feathers,

    Yes sorry for being a little vague - what i really meant to say regarding the syntax errors, i do not really have a problem, as more times than not i can debug them using the compiler errors which are detailed below my code - however, why i started this whole topic in the first instance was that i literally got STUCK in the middle of a question, and recently in the middle of an assignment - i had referred to our notes prior to making any contact with anyone and hadnt any replies from my lecturer either....

    The only example i can give is i am accountant by trade but trying to change careers into programming, so if i gave someone a tax computation to do, (detailed comp) and asked them to do it from start to finish after only 3 weeks teaching (not great) - you would find that most people would run literally into a wall and wouldnt know where to go to......

    Dya know what i mean???

    S.:confused:


  • Registered Users, Registered Users 2 Posts: 1,082 ✭✭✭Feathers


    shanard wrote: »
    Cheers Feathers,

    Yes sorry for being a little vague - what i really meant to say regarding the syntax errors, i do not really have a problem, as more times than not i can debug them using the compiler errors which are detailed below my code - however, why i started this whole topic in the first instance was that i literally got STUCK in the middle of a question, and recently in the middle of an assignment - i had referred to our notes prior to making any contact with anyone and hadnt any replies from my lecturer either....

    The only example i can give is i am accountant by trade but trying to change careers into programming, so if i gave someone a tax computation to do, (detailed comp) and asked them to do it from start to finish after only 3 weeks teaching (not great) - you would find that most people would run literally into a wall and wouldnt know where to go to......

    Dya know what i mean???

    S.:confused:

    Yeah, definitely. & just to say again, no one here is saying don't ask questions or don't ask beginner questions. But if you had given a junior a tax computation to do, would you prefer if he came back & said "I'm stuck" or

    "I'm stuck on C. I've completed A & B no problem, but now I'm not sure what to do. I tried X, but that ended up at Y & I know that was wrong because M, N, O. So then I tried Z & it seems halfway right, but its now caused P & I don't know how to fix that. So how can I fix P?"

    (my lack of accounting knowledge makes this a little too abstract :) ). Now you might've gone off on the complete wrong track to begin with, but like learning a foreign language, the locals appreciate it a lot if they see you making an effort :)


  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    I agree that MT’s explanations were very good.

    The problem I see is that the actually coding syntax, while it might seem important after 3 weeks, is actually not the most important skill to be learned. The real skill is reading the requirements, understanding the real problem and then designing the solution.

    Everyone feels like you do when they start learning to code and when someone explains the solutions as MT does then you think “Ah yes, that makes sense. I could do that now”... but *usually* you cannot. You cannot because like all skills you need to practise… and perhaps I was wrong but it looked to me like you were quickly coming to the point of “I’m stuck! So what next?”, when really you need to learn, the hard way, how to read carefully the requirements and structure your thoughts before sitting down and typing in a lot of code.

    There was very little syntactically wrong with your examples and correcting those is not a problem. But to be given complete answers is not really helping you and is also not fair to your fellow students.


  • Registered Users, Registered Users 2 Posts: 800 ✭✭✭a fat guy


    I know that you're just a beginner, but you might want to look at installing an IDE (Integrated Development Environment) for Java, the most popular one for Java being Eclipse.

    It's been AGES since I've had to install it, but I remember hearing that it can be difficult. The advantage to using Eclipse is that it will warn you, as you are actually writing the code itself, when you make a mistake. I think you'd find this very useful with regards to syntax (semi-colons, braces/brackets, etc. Small things that you'll take for granted later on.).

    And asking for help is fine, but looking for the solution yourself is where you'll really make some progress. It might take you three hours of googling and messing around with code until everything "clicks", but it's worth it in the long run.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    a fat guy wrote: »
    I know that you're just a beginner, but you might want to look at installing an IDE (Integrated Development Environment) for Java, the most popular one for Java being Eclipse.

    I'm not sure if its the most popular, but it certainly is not the best ;)

    OP do yourself a favor and install http://www.jetbrains.com/idea/


  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,666 Mod ✭✭✭✭TrueDub


    ChRoMe wrote: »
    I'm not sure if its the most popular, but it certainly is not the best ;)

    Opinion, not fact... :)
    ChRoMe wrote: »
    OP do yourself a favor and install http://www.jetbrains.com/idea/

    Excellent, but not free...


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,731 ✭✭✭GreenWolfe


    a fat guy wrote: »
    It's been AGES since I've had to install it, but I remember hearing that it can be difficult.

    You just download the appropriate zip here (Eclipse Standard is fine for a beginner) for your OS and CPU type (32 bit/64 bit) and you're good to go. There's no need for an install, just unzip the downloaded archive and get started, as long as you have a JDK installed of course.

    You can bolt on any other capability via plugins and you can maintain multiple Eclipse directories for different things. It reduces the chance of a plugin collision and you won't have to wait minutes for one huge Eclipse install to start up every single time.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    TrueDub wrote: »



    Excellent, but not free...

    The community edition is free.


  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    TrueDub wrote: »
    Excellent, but not free...
    There is a free (& open source) community edition. I don't know how the commercial edition compares - often support is the only difference. The fact that it's not java specific is probably Eclipse's strongest asset. I do use Eclipse mostly because I have a long history with it but I found netbeans okay too - now that oracle own it I'm not sure if it has any future.

    I do hear lots of good things re IntelliJ from people who specialize in java so have tried a few times - but I'm just used to eclipse.

    After saying all that, I'm not sure that an IDE is a good place for a beginner to start. They may end up spending a lot of time learning the IDE application instead of learning to code. Something simple like jedit (written in java) might be more appropriate. Though notepad++ seems to be much more popular but I really like the split screen functionality in jEdit... and of course th fact it's written in java means I can use it on windows/linux or mac.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    croo wrote: »

    I do hear lots of good things re IntelliJ from people who specialize in java so have tried a few times - but I'm just used to eclipse.

    Spend a day or two getting used to it and you will wonder how the **** you ever used Eclipse in the first place.

    I think I've converted about 10-15 developers over the years to it, I've also imposed it on all of my team members. Who have all thanked me for insisting on it once they were used to it.


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,110 Mod ✭✭✭✭Tar.Aldarion




  • Moderators, Society & Culture Moderators Posts: 12,548 Mod ✭✭✭✭Amirani



    Plus one here.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    Eclipse is used everywhere though, its a great development tool for C++ and to top it all off its free and employers can avoid paying even more people money. For the sheer fact that its so widely used I would use eclipse although I tried using IntelliJ for a few days and my god, I wanted to rip my hair out it just ****s about doing things I do not want it to do would never consider going back to use it again!


  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,666 Mod ✭✭✭✭TrueDub


    I didn't see the community option for IntelliJ - makes it more attractive then.

    I'm an Eclipse user, haven't had a need to move for a while so not really worried about the other options.

    However, my opinion on all of them is this: they're tools. Screwdrivers, if you will. Having a favourite is fine, most people do, but the holy wars fought over these things leave me bemused.


  • Registered Users, Registered Users 2 Posts: 760 ✭✭✭mach1982


    OP , did you try and Google, the is tons information on java

    http://www.learnjavaonline.org/

    also this a very good book http://www.amazon.com/dp/0071420401


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    TrueDub wrote: »
    However, my opinion on all of them is this: they're tools. Screwdrivers, if you will. Having a favourite is fine, most people do, but the holy wars fought over these things leave me bemused.

    I like that my hammer has extra features that make it much harder to hit my thumb.....


  • Registered Users, Registered Users 2 Posts: 800 ✭✭✭a fat guy


    ChRoMe wrote: »
    I like that my hammer has extra features that make it much harder to hit my thumb.....

    Oh yeah? Well my hammer can accidentally delete projects that are due the next day!

    Beat that!

    On a side-note, Eclipse actually did that to me once when I CTRL + Z'd a project I had just copied. Deleted the original too, and I was absolutely livid. It's apparently a known bug.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 10,906 ✭✭✭✭28064212


    ChRoMe wrote: »
    I like that my hammer has extra features that make it much harder to hit my thumb.....
    But what if I want to hit my thumb?


    :)

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users, Registered Users 2 Posts: 79 ✭✭leinad


    28064212 wrote: »
    But what if I want to hit my thumb?


    :)

    Used Eclipse for 6 years then intelliJ for 6 months and have to say if you know what you are doing intelliJ is a far superior faster less buggy and more helpful IDE


  • Registered Users, Registered Users 2 Posts: 72 ✭✭shanard


    Ok folks - In particular MT - i have finished my code for my assignment and all works grand apart from when the user say inputs any other number that is not on the menu - i want it to say "Please enter numbers 1,2 or 3" - which i have, but when they press a key it comes out of the program?????

    Another thing i was wondering if anyone knows if it is possible and if so how do i do it - it is the assignment specifically says that the ID should be 6 digits - so if the user selects option 1 to enter Employee details and enters say less than or more than 6 digits - can i get something to say - "Invalid - Please enter 6 digit IDs only!!".....

    Thanks folks - assignment has to be in by close of business today...

    [code]
    import java.util.Scanner;
    import java.io.*;

    public class EmployeeManagementSystem{
    public static void main(String[] args){

    Employee emp = new Employee();

    String s;

    //use the Scanners
    Scanner scan = new Scanner(System.in);
    Scanner scan2 = new Scanner(System.in); // used 2nd Scanner as was not reading in data as per below

    // menu options for user
    System.out.println("**************************************");
    System.out.println("| What would you like to do? |");
    System.out.println("| 1) Enter a new employees details |");
    System.out.println("| 2) Search for an employee |");
    System.out.println("| 3) Exit |");
    System.out.println("**************************************");

    int i = scan.nextInt();

    if(i >=4){
    System.out.println("Invalid Option, Please enter numbers 1, 2 or 3.");

    }else if(i == 1){

    try{ // use BufferedWriter to write the users details on file called "Employees.txt"
    BufferedWriter bw = new BufferedWriter(new FileWriter("Employees.txt", true));

    System.out.println("Please enter an Employee ID Number");
    int ID = scan.nextInt(); //this line of code reads in the users input
    emp.setID(ID); // this sets the ID Number

    System.out.println("Please enter an Employee Name");
    String name = scan2.nextLine();
    emp.setName(name); // this sets the Name

    System.out.println("Please enter an Employee Address");
    String address = scan2.nextLine();
    emp.setAddress(address);

    System.out.println("Please enter an Employee start date");
    String date = scan2.nextLine();
    emp.setDate(date);

    bw.write(ID+" "+name+" "+address+" "+date+System.getProperty("line.separator"));

    // this is to call the flush method
    bw.flush();

    // to close the BufferedWriter
    bw.close();
    }
    catch(IOException e){
    System.out.println(e);
    }

    }else if(i == 2){
    //}while(!(Integer.toString(searchID).length()==6)){ // this is used to verify user types in 6 digit ID no. only...

    try {
    System.out.println("Please enter the Employees ID Number:");

    //the employee ID the user is searching for
    int searchID = scan.nextInt();

    //use the BufferedReader now to read the written file called "Employees"
    BufferedReader br = new BufferedReader(new FileReader("Employees.txt"));

    s = br.readLine();
    String ID = Integer.toString(searchID);
    while(s != null){ // this will loop through my textfile i set up called Employees.txt

    //english - if s contains searchID, print s
    if (s.contains(ID)){
    System.out.println(s);
    }
    s = br.readLine();
    }
    br.close(); // this will close the buffered reader

    } catch (IOException e) {
    System.out.println(e);
    }
    } else if(i == 3){
    System.exit(0);
    }
    }
    }


  • Registered Users, Registered Users 2 Posts: 710 ✭✭✭mad turnip


    shanard wrote: »
    Ok folks - In particular MT - i have finished my code for my assignment and all works grand apart from when the user say inputs any other number that is not on the menu - i want it to say "Please enter numbers 1,2 or 3" - which i have, but when they press a key it comes out of the program?????

    Another thing i was wondering if anyone knows if it is possible and if so how do i do it - it is the assignment specifically says that the ID should be 6 digits - so if the user selects option 1 to enter Employee details and enters say less than or more than 6 digits - can i get something to say - "Invalid - Please enter 6 digit IDs only!!".....

    Thanks folks - assignment has to be in by close of business today...


    ARGHGHGHGH MAKE THEM CODE TAGS WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Another thing i was wondering if anyone knows if it is possible and if so how do i do it - it is the assignment specifically says that the ID should be 6 digits

    The easiest way to do this is to convert the integer to a string and then check the length of that string using the length() method for example if I had the word: test in a string like so:
    String s = "test";
    int stringLength = s.length();//this will be 4
    

    To convert an int to a string can be done like so:
    String intStr = "" + intName;
    
    inputs any other number that is not on the menu
    To do this you can't use the method scanner.readInt(), you need to read a string then convert this to an int. See the example below:
    String someNum = "586974";
    int thatNum = Integer.parseInt(someNum);
    

    the Integer.parseInt method will take a string as an argument and return an int, it will throw an exception if the string is not an integer or contains whitespace on either end of the string. Handling this exception is how you know if the string is an integer or not.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    leinad wrote: »
    Used Eclipse for 6 years then intelliJ for 6 months and have to say if you know what you are doing intelliJ is a far superior faster less buggy and more helpful IDE

    Innit, its in a completely different league!


Advertisement