Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 44

Thread: Please help me

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Please help me

    Question:
    Write a Java program Format.java, to read a passage from an input file passage.txt and
    print to another file newPassage.txt the same passage with the following changes:
     Each sentence should be printed on a new line.
     All numbers should be removed.
    The program should also keep track of and print (to the same file) how many times each
    vowel appears.


    My solution that doesn't work :
    Last edited by Java girl; April 13th, 2014 at 04:10 PM.

  2. #2
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Reading and Writing from files-PLEASE HELP ME

    Question:
    Write a Java program Format.java, to read a passage from an input file passage.txt and
    print to another file newPassage.txt the same passage with the following changes:
     Each sentence should be printed on a new line.
     All numbers should be removed.
    The program should also keep track of and print (to the same file) how many times each
    vowel appears.


    My solution that doesn't work :
    Last edited by Java girl; April 13th, 2014 at 04:09 PM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    doesn't work
    Please explain and be specific about each of the problems.

    One thing I see:
    In binary conditions made up of several sub conditions connected by OR operators, if any ONE sub condition is true, the whole condition is considered true.
    With AND operators ALL the sub conditions must be true for the whole condition to be true.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Please help me

    Question:
    Write a Java program Format.java, to read a passage from an input file passage.txt and
    print to another file newPassage.txt the same passage with the following changes:
     Each sentence should be printed on a new line.
     All numbers should be removed.
    The program should also keep track of and print (to the same file) how many times each
    vowel appears.


    My solution that doesn't work : nothing outputs to the newPassage file

     
    Last edited by Java girl; April 13th, 2014 at 04:09 PM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    The code has lost all of its indentations and needs to be formatted.

    Where does the code write anything to a file?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    What happens when the code executes? Does it exit normally?

    One problem I see is the while() loop. Where is the value of the variable that controls the looping changed INSIDE of the loop? If it never changes the loop won't exit.

    Why is a while used there instead of an if?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Please help me

    When it executes, each sentence should be printed on a new line an digits removed. Also, the number of times each vowel appeared. All this should be outputted to the newPassage file.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me

    Did you see my last post? I asked several questions that you seemed to have skipped answering any of them.

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Please help me

    The while loop inside was changed because I was uncertain. When I run the program the newPassage file stays blank.
    Ok, no problem, thanks for the assistance.

  10. #10
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default HELP required plz

    Create a Java method nextLarger that accepts two positive integer parameters num and n
    and returns the smallest digit within num that is larger than n. For example if num = 3875
    and n = 6, your method should return 7. Write a Java program Numbers.java to test the
    method.

    That was the given question, can someone help with the logic of getting the solution please, I attempted but was unsuccessful.

  11. #11
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    first, arrange your num in ascending order. if num = 3875 it will be num = 3578 after sorting.,
    next start from the lowest, get the number that is higher than n.

  12. #12
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    Thanks, goin to attempt it now. Back in a 10 mins.

    --- Update ---

    hi, i know how to put numbers in ascending number but not how to put digits in a number in ascending order.

  13. #13
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    okay, do you know array?
    you can create an array of integer, array of characters will do also.
    then use the toCharArray method of String to store it in your array.
    then sort it.

  14. #14
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    ok, back with an attempt in 10 mins

  15. #15
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    you better paste your code when you back so we can assist you.

  16. #16
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    Here is my attempt:

     


    --- Update ---

    Is anyone there?
    Last edited by Java girl; April 13th, 2014 at 04:10 PM.

  17. #17
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    int numDigits[] = new int [];
    that is invalid declaration. you must put a length on that
    Example: int numDigits[] = new int[5];
    in your case, you can use the .length() method of String. new int[num.length()]

    base on your code, I think it would be better not to use the toCharArray() method, instead we will use the charAt() method.
    and we will put that on the int array
    Example:
    numDigits[i] = ((int) num.charAt(i)) - 48;

    as you noticed, I used the (int) to cast the character to integer and subtract 48 to convert in number.

    if you a little confused with that algorithm. you can use this
    numDigits[i] = Integer.parseInt(Character.toString(num.chartAt(i) ));
    parsing the character to string and then to integer.

  18. #18
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

     

    I am a total beginner at this so plz forgive if my corrections that i am resubmitting now based on what i interpreted is inaccurate. Make the corrections within the code if u can.
    Last edited by Java girl; April 13th, 2014 at 04:10 PM.

  19. #19
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    there's a lot of errors in your code.
    okay let's fix 1 by 1.
    delete this line first:
    Arrays.sort(numDgits []);
    int i = num; --you already define the variable i in the loop.
    char[] chars = ("" + i).toCharArray();
    System.out.printf (%c,numDigits.charAt(i);

    if(numDigits.charAt(i) >n)
    {
    System.out.printf ("%c",numDigits.charAt(i));
    }

    delete those lines please and paste your new code

  20. #20
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    public static int nextLarger (int num, int  n){
         int numDigits[] = new int [num.length()];
     
         for(int i=0; i<num.length();i++){
     
    	numDigits[i] = ((int) num.charAt(i)) - 48;
     
         }
    }

  21. #21
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    Oh my! ahaha.. Sorry, I did not noticed that the parameter is int. apology.
    in your defining the length of array, num.length is invalid syntax. You must parse it first to string.
    Integer.toString(num).length() sorry..
    since you started with array. let just continue that.
    first create a String and declare its value as the String value of num Integer.toString(num)

  22. #22
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    Miss posted in the group to not use arrays, now checked it lol so now i cant use arrays until she has taught us it well enough. Without arrays what would the code be instead.

  23. #23
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    Okay, its fine not to use array, it would be easier for you not to use that.
    let us start from scratch is it okay with you?
    you have this method right?
    public static int nextLarger (int num, int  n){
     
    }
    let us fill that method with codes.

    we just need to determine the smallest digit in num that is larger than n,
    then we are to need a variable of int, and we are going to put the answer in that int variable.
    next I assumed that you already know how to use if statements, a conditional statement and loop.

    there are many solutions, is it okay to use while loop in your class? did your teacher taught it already?

  24. #24
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: HELP required plz

    yes we did while and if loops

    --- Update ---

    Yes we can start from scratch, hope we figure it out soon, eyes getting tired lol

  25. #25
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: HELP required plz

    Oh my ahaha.
    then create a while loop whose condition is num not equal to zero. what is time now in your country? ahaha

Page 1 of 2 12 LastLast