Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Programming Stuck!!

    So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.
    Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong...
    This is slightly challenging for me, and I need help.

    Code SO Far:

    Java Code:
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.InputStreamReader;
    
    
    public class File_Read {
    	public File_Read() {	//File_Read is the Interactive object
    	
    	iSR = new InputStreamReader(System.in);
    	bRead = new BufferedReader(iSR);
    	}
    	public void Out(String a) {
    		this.action(a);
    	}
    	public String inputRead(String a) throws Exception {
    		this.action(a);
    		return bRead.readLine();	
    	}
    	public void createF (String a) throws Exception {
    		String	Input;
    		this.action("Please Enter The Name of the File To Create...");
    		Input = bRead.readLine();
    		File oFile = new File(Input);
    		
    	}
    	public void read (String a) throws Exception {
    		String result = inputRead("1. 1 + 1 = ?");
    		if (result.equals("2")) {
    			
    		}
    		String result2 = inputRead("1. 3 + 1 = ?");
    		if (result2.equals("4")) {	
    			
    		}
    		String result3 = inputRead("1. 8 + 1 = ?");
    		if (result3.equals("9")) {	
    			
    		}
    	}
    	public void ask (String a) {
    		
    		
    		
    		
    	}
    	public void action (String a) {
    		System.out.println(a);
    		System.out.flush();
    	}
    	private InputStreamReader iSR;
    	private BufferedReader bRead;
    }
    I need help with what to put
    (result.equals("2")) {
    HERE!!!
    }
    So that it puts the Correct or Wrong into the file.



    Thanks in Advance,
    Sam
    GODLIKE!!!!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    What is supposed to be written to the file when that if statement is true?

    Where is the code for writing to a file? I'd suggest that you write a small test program that uses a loop and writes some things to the file from inside the loop, before trying to add code to this program to write to a file.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    Ok,
    thx
    GODLIKE!!!!

  4. #4
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    Norm, what do I put into the Print Stream so the String : result, result2 or result3 will show?
    EXP
    My printstream is "ps"
    so ps.println(result);
    ????
    P.S. the printstream is to the file.
    GODLIKE!!!!

  5. #5
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    In addition, I think it would help you knowing that the result part is below the printstream part.
    GODLIKE!!!!

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    If you are having problems with your code, please post the code and explain what the problems are. Also post the full text of any error messages.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    Java Code:
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    
    
    public class File_Read {
    	public File_Read() {	
    	
    	iSR = new InputStreamReader(System.in);
    	bRead = new BufferedReader(iSR);
    	}
    	public void Out(String a) {
    		this.action(a);
    	}
    	public String inputRead(String a) throws Exception {
    		this.action(a);
    		return bRead.readLine();	
    	}
    	public void createF (String a) throws Exception {
    		File newFile = new File("C:/Samuel/Input.txt");
    		FileOutputStream		fos = new FileOutputStream (newFile);
    		PrintStream				ps = new PrintStream (fos);
    		//Stuck Here!!
    		String	Input;
    		this.action("Please Enter The Name of the File To Create...");
    		System.out.flush();
    		Input = bRead.readLine();
    		
    	}
    	public void read (String a) throws Exception {
    		String result = inputRead("1. 1 + 1 = ?");
    		if (result.equals("2")) {
    		//What to put here?	
    		}
    		String result2 = inputRead("1. 3 + 1 = ?");
    		if (result2.equals("4")) {	
    			//What to put here?
    		}
    		String result3 = inputRead("1. 8 + 1 = ?");
    		if (result3.equals("9")) {	
    			//What to put here?
    		}
    	}
    	public void writeTo (String a) {
    		
    		
    		
    		
    	}
    	public void action (String a) {
    		System.out.println(a);
    		System.out.flush();
    	}
    	private InputStreamReader iSR;
    	private BufferedReader bRead;
    }
    Last edited by Ark3; 07-14-2014 at 09:25 PM.
    GODLIKE!!!!

  8. #8
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    the parts i'm stuck on are the "Stuck Here!" parts,
    and the "What to put here?" parts
    GODLIKE!!!!

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    the "Stuck Here!" parts, and the "What to put here?" parts
    Describe what the program is supposed to do in those places.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    for the stuck here, i'm supposed to use the print stream, and do something like ps.println("?")
    and the ? would then print something like Question 1: Correct.
    I want it to use the Strings such as result in the "?" area.

    Second, the what to put here part, is something like a true or false statement. So, if the user inputs the right answer, then it will determine wether to print out correct or incorrect in the file. In addition, I want to use the String: result in the PrintStream print ln part.


    SO, when fully finished, the strings result,result2,result3, will determine what goes into the file. Like test answers and results.
    GODLIKE!!!!

  11. #11
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    Except I don't know, or haven't learned how to do the printstream part that incorporates the string in the parenthesis.
    Plus, I just started using if, so I don't know a thing about how to do anything.
    GODLIKE!!!!

  12. #12
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    I just need you to tell me what to put in there,
    and explain.
    GODLIKE!!!!

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    i'm supposed to use the print stream, and do something like ps.println("?")
    What happened when you tried that in the small test program I suggested you write to learn how to write files?

    will determine wether to print out correct or incorrect in the file
    You could use an if statement to determine what to write. If it's true, write "correct", else write "incorrect"
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    sadly, I don't know how to do the true or else thing...
    could you give me an example?
    GODLIKE!!!!

  15. #15
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    Second of all, I've created files before and used OutputStream and printStream and all that, it's just how do i put the result string into the println.

    I was trying things like
    ps.println(result +" is Correct");
    that type of thing.
    I don't know how to use the result in the println.
    GODLIKE!!!!

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    See the tutorial on how to write an if statement: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    I don't know how to use the result in the println.
    Post the small test program showing what you have tried.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    Norm, there is not a notEqual thing.
    theres only equal!
    How do I say incorrect if the thing doesn't equal let's say 2.
    GODLIKE!!!!

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    How do I say incorrect if the thing doesn't equal let's say 2.
    if the thing doesn't equal 2
    System.out.println("incorrect");
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    Ark3 is offline Member
    Join Date
    Jun 2014
    Posts
    59
    Rep Power
    0

    Default Re: Programming Stuck!!

    No, not that, what do i put here,

    else if(result HERE 2)
    System.out.println(Incorrect!)

    The here is not equal.
    GODLIKE!!!!

  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Programming Stuck!!

    Use the NOT operator: ! to change a boolean's value: !true = false
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 09-27-2014, 02:24 AM
  2. Replies: 3
    Last Post: 05-24-2014, 09:26 PM
  3. help..stuck w/ a java programming assignment
    By clemsontigers in forum New To Java
    Replies: 16
    Last Post: 02-19-2014, 05:16 AM
  4. Stuck on Programming
    By tabchas in forum New To Java
    Replies: 3
    Last Post: 05-01-2011, 12:33 AM
  5. Replies: 2
    Last Post: 12-10-2008, 05:40 PM

Posting Permissions

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