vendredi 26 août 2016

JAVA: If condition is met, yet it acts as though it isn't [duplicate]

This question already has an answer here:

I'm writing a java "guess my number" sort of game. In the first part of the game, the player selects the difficulty of the game (Easy, Medium, Hard). My problem is that when I play, the game will return "Invalid Response" regardless of what I type into the text box. I know what I'm typing in matches a valid response, but it doesn't seem to think so. What am I doing wrong?

I've attached the first part of the game code below, where the player selects the difficulty. This is process then eventually determines the variable "guessThis0," which is the number to guess during the actual game...

//Guess My Number Game

import java.util.Scanner;
import javax.swing.JOptionPane;

public class playGuessMyNumberGame {

@SuppressWarnings({ "unused", "resource" })
public static void main(String[] args)
{

    boolean gameOver = false;  //becomes 'true' when player WINS or LOSES
    boolean playAgain = true;  //decides if player would like to play again
    boolean setUpDone = false; //for player setup loop
    int guessThis0;  //Target number
    int guessesRemaining = 12;  //Player starting guesses
    int highLimit = 500;  //Highest the Answer can be. Set by (player-chosen) difficulty

    //PLAYER SETUP
    while(setUpDone == false)
    {
        /*
        Scanner playerDifficulty0 = new Scanner(System.in);
        String playerDifficulty = playerDifficulty0.next();
        */
        String playerDifficulty = JOptionPane.showInputDialog("CHOOSE DIFFICULTY \nPlease Enter: 'Easy,' 'Medium,' or 'Hard.' ");
        if(playerDifficulty == "Easy")
        {
            highLimit = 250;
            setUpDone = true;
        }
        if(playerDifficulty == "Hard")
        {
            highLimit = 1500;
            setUpDone = true;
        }
        if(playerDifficulty == "Moderate")
        {
            highLimit = 750;
            setUpDone = true;
        }
        else //This is what it returns regardless of what I type in:
        {
            System.out.println("Not a valid response. Please try again. \n");
        } // ^ This is what it return regardless of what I type in ^
    }
System.exit(0);
guessThis0 = 0 + (int)(Math.random() * highLimit);

//PLAY GAME
}
}

use if-statement to recognize arraylist data in android

i want to use condition " if " for my array list

here is my code in (activity 1) to send string in textview with button to static variable that is in (exchange activity) :

    Button btn1 = (Button) findViewById(R.id.btn1);
    final TextView text = (TextView) findViewById(R.id.txt1);

    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            exchange.in =text.getText().toString();

        }
    });

here is my static variable in (exchange activity)

public static String in;

and here is my (activity 2) code that i use array list in it to receive & store string from (activity 1) that is in static variable (exchange.in)

    ListView list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayList<String> web = new ArrayList<String>(10);
        for (int i = 0; i < 10; i++) {
            web.add("");
        }

        CustomList adapter = new
        CustomList(activity_main.this, web);
        list = (ListView) findViewById(R.id.list);
        list.setAdapter(adapter);


    }

now i don't know how to store data from (exchange.in) to arraylist and then use if condition to recognize that, if arraylist(0) was full, put data that is in (exchange.in) to arraylist(1) and it will continue like this...

is anyone know about this?

R - How to Create Custom Ifelse function that repeats

I am quite familiar with R's standard ifelse statement, and how to create nested ifelse statements. I however want to create a "better" version, so that I dont have to copy / paste ifelse so many times.

Take this nested ifelse statement for example:

df$a <- ifelse(df$b == 1,1,
        ifelse(df$b == 2,2,
        ifelse(df$b == 3,3,4)))

Instead, what I would like to do is create a function like I could call like this:

df$a <- myFunction(df$b == 1,1,
                   df$b == 2,2,
                   df$b == 3,3,4)

I would want the function to be able to pick up how many arguments I have entered, and thus know how many ifelse statements to include and then plug the arguments into the correct position, up to however many I want.

There is still some repetition, but when creating longer nested ifelse statements it would be nice to not have to repeat that piece of code, and then try to keep track of ending paren's.

Greater-than PowerShell operator giving inaccurate results

For some reason, when I debug - $debug is equal to 1, yet when the debugger hits if(numUsers -gt 2), it enters the if block...

function numUsers()
    {@(query user /server:$server).Count - 1
    }

$debug = numUsers

if(numUsers -gt 2)
    {#true
    }
else
    {#Nothing
    }

Am I using the -gt operator properly? Am I missing something really obvious?

Appreciate any insight

SQL - SHOW DATA OF TABLE1(PK) WITHOUT HAVING DATA IN TABLE 2(FK)

there are two tables Customer and Fees (PK customer.CustomerID -> Fees.CustomerId FK) there are customers in Customer table. where in table Fees there is no data of current month. without inserting data in Fees table of current month i want to show the Customer details from Customer table of whom have not paid the fees of current month.

something like:

if(Convert(varchar(3),MonthFee, 109) != convert(varchar(3),getdate(),109))
BEGIN
select Customer.CustomerId as ID, Customer.CustomerName as Name, Customer.Phone as [Phone No], 'UnPaid' as [Pay Status], convert(varchar(3),getdate(),109) as [Month], YEAR(GETDATE()) as [Year]
from Customer inner join Fees on Customer.CustomerId = Fees.CustomerId Where FeeMonth = null

END

Help will be appreciated, thanks.

Sending a file's data to multiple other files in Shell

I'm trying to send the data from a file to multiple other files based on the Date of the following database:

100:Clinton Mcdaniel:16/04/2016
101:Patience Mccarty:18/03/2013
102:Carol Holman:24/10/2013
103:Roth Lamb:11/02/2015
104:Chase Gardner:14/06/2014
105:Jacob Tucker:05/11/2013
106:Maite Barr:24/04/2014
107:Acton Galloway:18/01/2013
108:Helen Orr:10/05/2014
109:Avye Rose:07/06/2014
110:Xerxes Richmond:13/11/2015
111:Illana Campos:22/07/2016
112:Ruby Baker:21/01/2015
113:Mark Lynn:21/06/2014
114:George Tyson:03/10/2014
115:Heather Sweeney:26/11/2015
116:Zahir Hines:08/10/2014
117:Cleo Decker:12/06/2014
118:Cyrus Best:07/01/2015
119:Dominique Goodwin:19/12/2015
171:Laura Mercado:06/06/2013
165:Kai Nash:16/07/2015
184:Oren Flores:27/09/2013
123:Rogan Rowe:05/12/2014
146:Vivian Stevens:20/01/2014
130:Anne Lawson:23/04/2015
196:Willow Powers:11/11/2015
167:Megan Caldwell:04/05/2016
195:Megan Long:03/10/2015
126:Castor Rhodes:19/06/2015
190:Anne Sullivan:12/01/2013
159:Lars Keith:28/10/2015

What i want to do is to send each line to an specific file depending on the year, if the lines has they year 2013 on the date i want to add it to a file named Year2013.txt, if the date colum has 2014 than i want it to go to the file Year2014.txt, etc etc.

Ive been trying to use the if statement together with AWK but it isnt working as i expected. It usually only saves the year or the date but not the entire line of the database.

I tried codes like

$awk -F":" '{if($3.7==2013)print $0 > "Year2013.txt"}}' IDNameDate

But they usually don`t work

Excel VBA Select a row based on its multi-column data matching criteria in multiple userform comboboxes

This is a solution I am interested in implementing but I am unsure of my syntax, I will provide an example of what I have below. I believe a similar result can be found using an AutoFilter method, but I wish to avoid this if possible. I am basing my attempts so far on a suggestion from Søren Holten Hansen in this post that uses nested if statements to return the row number that matches criteria contained within TextBoxes.

For background, I currently have a UserForm1 that contains five ComboBoxes and two Command Buttons.

Each ComboBox pre-populates with the contents of a named range housing data that corresponds to data on Sheet1, such as "Fruits" in ComboBox1 and Column A of Sheet1, "Vegetables" in ComboBox2 and Column B of Sheet1, and so on.

My goal is to use nested If statements when CommandButton1 is clicked to find and Select the entire row on Sheet 1 which contains an exact match to the value of each ComboBox. For example, if the user selects 'Apple' from ComboBox1, 'Potato' from ComboBox2, 'Farm' from ComboBox 3, 'Monkey' from ComboBox4, and 'Supermarket' from ComboBox5, the entire row on Sheet1 that contains 'Apple' in Column A, 'Potato' in Column B, 'Farm' in Column C', 'Monkey' in Column D, and 'Supermarket' from Column E is then selected.

What I have so far is the following, assigned to CommandButton1:

Dim i As Long, GetRow As Long
    For i = 2 To Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
        If Sheets("Sheet1").Cells(i, 1).Value = Me.ComboBox1.Value Then
            If Sheets("Sheet1").Cells(i, 2).Value = Me.ComboBox2.Value Then
                If Sheets("Sheet1").Cells(i, 3).Value = Me.ComboBox3.Value Then
                    If Sheets("Sheet1").Cells(i, 4).Value = Me.ComboBox4.Value Then
                        If Sheets("Sheet1").Cells(i, 5).Value = Me.ComboBox5.Value Then
                    GetRow = i
                End If
            End If
        End If
    End If
End If
Next i
Rows(i).EntireRow.Select
End Sub

I believe the desired result can be achieved using nested If statements, but I am unsure of my formatting in this example.

Thank you.