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.

Results 1 to 8 of 8

Thread: Working with CSV files

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Working with CSV files

    How to delete a word from the csv file when it is used so as not to have the same question twice with the same word and stop when all the words have been used?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java question

    How to delete a word from the csv file
    Unless you want to parse the csv file yourself, you would need to use a utility class like in the Apache project to read in the lines of the csv file, delete the word and write out the updated csv file.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2021
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java question

    How can I do it I'm a beginner I don't know how to do it?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java question

    It may be a little complicated for a beginner.
    Which way do you want to do it?
    Write your own code to parse a csv
    Use the packages from the Apache project
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2021
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java question

    import extensions.CSVFile;

    CSVFile wordPrice = loadCSV("wordPrice");

    class Word {
     String word;
     int price;
    }

    void play (Word info) {
     
      int RightPrice = info.price;
      int Price;
      println("What is the price of'" + info.word);
     
     
      do{
       counter = counter + 1;
       Price = readInt(); 
       if (Price<RightPrice){
        println("It's +");
       }
             else if (Price>RightPrice) {
        println("It's -");
       }
      }
      while(Price!=RightPrice);

    Word randWord(){
      Word mp = new Word();
         int line = (int)(random() * rowCount(wordPrice)); 
         mp.word = getCell(wordPrice, line, 0);
         String price = getCell(wordPrice, line, 1);
          mp.price = stringToInt(price);
         return mp;
        }

    boolean replay(boolean exit) {
     
    		println("Do you wan to play again (Y : Yes, N : No) ?");
    		char answer = readChar();
     
     
    		if(answer == 'N') {
    			exit = true;
    		}
    		if(answer == 'Y') {
    			exit = false;
    		}
    		return exit;
    	}

    boolean exxite = false;
    while(exxite == false) {
    			Word randWord = randWord();
    			play(randWord);
    			exxite = replay(exxite);
    		}

    csv name: wordPrice
    There are two columns, one with the words and the other with the prices
    Last edited by Alex123456; January 8th, 2022 at 03:47 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java question

    Did you have any questions or comments about the code that you posted?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2021
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java question

    I want to remove a word from the csv file when it is used so that I don't have the same question twice with the same word and stop when all the words have been used but I don't know how to do it

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: java question

    I don't know how to do it
    Can you write a detailed list of the steps that the program needs to take to solve the problem?
    Do not try to write an java code yet.
    When we have agreed on the steps the program needs to take, then pick the first step, write the code for it and test it.
    When the test works, move to the next step and do the same.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java question
    By empms in forum Java Theory & Questions
    Replies: 0
    Last Post: September 30th, 2013, 04:05 PM
  2. Replies: 1
    Last Post: November 1st, 2012, 07:54 AM
  3. Challenging Java Question: Test your Java skill by grouping these terms
    By karthickk3 in forum Java Theory & Questions
    Replies: 3
    Last Post: July 18th, 2012, 10:10 PM
  4. Java EE Question
    By djl1990 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 12th, 2012, 12:42 PM
  5. Java Question
    By NiCKYmcd in forum Java Theory & Questions
    Replies: 1
    Last Post: August 25th, 2010, 08:47 AM