Results 1 to 8 of 8
  1. #1
    Kolby is offline Member
    Join Date
    Jan 2015
    Posts
    4
    Rep Power
    0

    Question Building a registration system

    I'm assigned along with two others to make this program for a project.

    We need to store data to the program by adding them such as user_id among the 5 criterias that are needed. Lets say I want a new user, I need the program to give me that option and then I would type in the user id and the program would store that data information

    As far as I'm aware, boolean, screentokenizer and scanner is involved in the making of this program.

    I'm still new to Java so please bear with me, I'm currently looking at --> [Moderator edit: link removed] hoping for it to give me an idea of what to do..
    Last edited by DarrylBurke; 01-18-2015 at 06:34 PM. Reason: Removed irrelevant link

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    311
    Rep Power
    10

    Default Re: Building a registration system

    As far as I'm aware, boolean, screentokenizer and scanner is involved in the making of this program.
    I believe you were thinking of StringTokenizer? Well that is some start, carry on, give us some code. And questions..

  3. #3
    Kolby is offline Member
    Join Date
    Jan 2015
    Posts
    4
    Rep Power
    0

    Default Re: Building a registration system

    Ok so I acquired this code from my lecturer. However, there are bits and pieces that I needed to add and remove from this code in particular the printing and generate data section. For now, I just want to know how do I add new messages and data for ‘Printing’ and 'Generate Data' as I have tried to do it myself but to no avail I had failed to do so. Can you tell me how do I add data correctly to my code in order for it to show what I want? Thanks. Please refer to data.txt



    Again I just want to add another line for the 'Printing data' and 'Generate' data and I will try to figure out from there on
    Last edited by Kolby; 01-23-2015 at 03:46 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Building a registration system

    You will get more help if you post the code here on the forum. Many of us do not follow links to download code.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Kolby is offline Member
    Join Date
    Jan 2015
    Posts
    4
    Rep Power
    0

    Default Re: Building a registration system

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package JavaApplication19;
    import java.util.*;
    import java.util.StringTokenizer;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    /**
     *
     * @author Kolby
     */
    public class JavaApplication19{
    
        /**
         * @param args the command line arguments
         */
        static Scanner s = new Scanner(System.in);
        public static void main(String[] args) throws IOException{
            // TODO code application logic here
           
     
      
        BufferedReader br = null;
     
    	try {
     
    		String line;
     
    		br = new BufferedReader(new FileReader("c:/test.txt"));
     
    		while ((line = br.readLine()) != null) {
    		   System.out.println(line);
     
    		   StringTokenizer stringTokenizer = new StringTokenizer(line, "|");
     
    		   while (stringTokenizer.hasMoreElements()) {
     
    		    Integer id = Integer.parseInt(stringTokenizer.nextElement().toString());
    		    Double price = Double.parseDouble(stringTokenizer.nextElement().toString());
    		    String username = stringTokenizer.nextElement().toString();
                        String lastname = stringTokenizer.nextElement().toString();
                        String contact = stringTokenizer.nextElement().toString();
                        String email = stringTokenizer.nextElement().toString();
                        String carnumber = stringTokenizer.nextElement().toString();
                        String datereg = stringTokenizer.nextElement().toString();
     
    			StringBuilder sb = new StringBuilder();
    			sb.append("\nStudent Id : " + id);
    			sb.append("\nPrice : " + price);
    			sb.append("\nFirst Name : " + username);
                            sb.append("\nLast Name: " + lastname);
                            sb.append("\nContact Number: " + contact);
                            sb.append("\nE-Mail Address: " + email);
                            sb.append("\nCar Number: " + carnumber);
                             sb.append("\nDate Registered: " + datereg);
    			sb.append("\n*******************\n");
     
    			System.out.println(sb.toString());
    		   }
    		}
     
    		System.out.println("Done");
     
    	} catch (IOException e) {
    		e.printStackTrace();
    	} finally {
    		try {
    			if (br != null)
    				br.close();
     
    		} catch (IOException ex) {
    			ex.printStackTrace();
    		}
    	}
     
    	}
    }
    So what I want to do now is make a method that asks user for input(questions) based on the data mention above (for now) and save it into the txt file

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Building a registration system

    make a method that asks user ...
    What have you tried? Where are you having problems?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Kolby is offline Member
    Join Date
    Jan 2015
    Posts
    4
    Rep Power
    0

    Default Re: Building a registration system

    I was wondering if someone can tell me which code to use? I tried to change a few variables on another code which was this one but that one uses array and I have failed to incorporate it to my current code(I'm not sure if arrays are compatible with buffermethod?). If you refer to line 23(generate options for user), 57(asks user to input data into console command and auto-save it) and line 112(shows current data that was registered), those are exactly what I wanted but again I've tried modifying this code to suit my data but that failed so I was wondering should I find another type of method/code to use?
    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package version1;
    import java.util.*;
    import java.io.*;
    /**
     *
     * @author anon
     */
    public class Version3 {
    
        /**
         * @param args the command line arguments
         */
        static Scanner s = new Scanner(System.in);
            public static void main(String[] args) throws IOException{
            // TODO code application logic here
            login("James");
            String[][] data = generateData();        
            while(true){
                System.out.println("\n1 for printing");
                System.out.println("2 for charges");
                System.out.println("3 for payment");
    	    System.out.println("4 for adding a new account");
                System.out.println("0 to exit");
                System.out.print("What you want to do: ");
                int input = 0;
                try{
                    input = Integer.parseInt(s.nextLine());
                } catch(NumberFormatException e){
                    System.out.println("Wrong input, must enter an integer!");
                    continue;
                }
                if (input == 0){
                    printToFile(data);
                    break;
                } else{
                    switch(input){
                        case 1: printing(data);
                                break;
                        case 2: charges(data);
                                break;
                        case 3: payment(data);  
                                break;
    		    case 4: add(data);
    			    data = generateData(); 
    			    break;
                        default: System.out.println("Wrong input, must enter 0-4!");
                    }
                }
            }
        }
        public static void add(String[][] x) throws IOException{
    	System.out.print("Enter the account name: ");
    	String a = s.nextLine();
    	System.out.print("Enter the account id: ");
    	String b = s.nextLine();
    	System.out.print("Enter the account balance: ");
    	String c = s.nextLine();
            int counter = x.length;
            File data = new File("data.txt");
    	PrintWriter y = new PrintWriter(data);
            y.println(counter+1);
    	for(int i=0; i<counter; i++){
                y.println();
                y.println(x[i][0]);
                y.println(x[i][1]);
                y.println(x[i][2]);
    	}
    	y.println();
            y.println(a);
            y.println(b);
            y.println(c);
            y.close();		
        }
        public static void printToFile(String[][] x) throws IOException{
            int counter = x.length;
            File data = new File("data.txt");
    	PrintWriter y = new PrintWriter(data);
            y.println(counter);
    	for(int i=0; i<counter; i++){
                y.println();
                y.println(x[i][0]);
                y.println(x[i][1]);
                y.println(x[i][2]);
    	}
            y.close();
        }
        public static void login(String password){
            System.out.print("Enter your password: ");
            String input = s.nextLine();
            int i = 0;
            while(true){
                if( !(input.equals(password)) ){
                    System.out.println("Wrong password!");
                    if(i==1){
                        System.exit(0);
                    }
                    System.out.println("Last chance!");                
                    System.out.print("Enter your password: ");
                    input = s.nextLine();
                    i++;
                } else{
                    break;
                }
            }
        }
        public static String[][] generateData() throws IOException{
            File x = new File("data.txt");
    	Scanner y = new Scanner(x);
            int counter = Integer.parseInt(y.nextLine());
            String[][] data = new String[counter][3];
            for(int i=0; i<counter; i++){
                y.nextLine();
                data[i][0] = y.nextLine();
                data[i][1] = y.nextLine();
                data[i][2] = y.nextLine();
    	}
            y.close();
            return data;
        }
        public static void printing(String[][] data){
            int length1 = data.length;
            int length2 = data[0].length;
            for(int i=0; i<length1; i++){
                System.out.println(data[i][0]+" (ID "+Integer.parseInt(data[i][1])+"), your balance is: "+Double.parseDouble(data[i][2])+"!");
            }
        }
        public static void charges(String[][] data){
            int length1 = data.length;
            for(int i=0; i<length1; i++){
                System.out.println((i+1)+" for "+data[i][0]);
            }
            System.out.print("Who you want to charge: ");
            int input = Integer.parseInt(s.nextLine());
            System.out.print("How much you want to charge "+data[input-1][0]+": ");
            data[input-1][2] = ""+(Double.parseDouble(data[input-1][2]) + Double.parseDouble(s.nextLine()));
        } 
        public static void payment(String[][] data){
            int length1 = data.length;
            for(int i=0; i<length1; i++){
                System.out.println((i+1)+" for "+data[i][0]);
            }
            System.out.print("Who want to pay: ");
            int input = Integer.parseInt(s.nextLine());
            System.out.print("How much "+data[input-1][0]+" want to pay: ");
            data[input-1][2] = ""+(Double.parseDouble(data[input-1][2]) - Double.parseDouble(s.nextLine()));
        }    
    }

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Building a registration system

    Work on one part of the program at a time. You asked about a method to get user input.
    What does that method need to do? What should it return?
    It shouldn't take 150+ lines of code.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: 03-10-2013, 11:00 PM
  2. help in registration
    By katrinax_caren02 in forum JDBC
    Replies: 1
    Last Post: 09-27-2009, 03:46 PM
  3. building a complete online evaluation system
    By pmminov in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 04-07-2009, 09:04 PM
  4. Registration Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 11:22 AM

Posting Permissions

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