mardi 28 avril 2020

Joptionpane and equalstoignorecase is giving me an invalid output

My JOption Pane show messagedialog keeps on giving me a weird output. My if else statement with equalstoignore also doesnt work. The JOptionPane is giving me a long pane with text such as Name:Javax.swing.JtextField[,0,18,294,19,invalid,layout.............. and its so long i. it doesnt output my desired output like i use on toString.


    public static void main(String[] args)
    {
        ArrayList<PreSchool> PSList = new ArrayList<PreSchool>();
        JTextField  field1 = new JTextField();
        JTextField  field2 = new JTextField();
        JTextField  field3 = new JTextField();

        Object[] fields = {
            "Please Enter Name:",field1,
            "Please Enter Race(Malay/Chinese/Indian):", field2,
            "Please Enter Age:", field3
        };

        for(int i = 0; i < 5;i++){
            JOptionPane.showConfirmDialog(null, fields,"Enter Information for Children " + i,JOptionPane.OK_CANCEL_OPTION );
            String name = field1.toString();
            String race = field2.toString();
            int age = Integer.parseInt(field3.getText());
            PSList.add(new PreSchool(name,race,age));
        }

        StringBuilder builder = new StringBuilder();
        builder.append("Index: 0\n");
        builder.append(PSList.get(0).toString());
        builder.append("Index: 1\n");
        builder.append(PSList.get(1).toString());
        builder.append("Index: 2\n");
        builder.append(PSList.get(2).toString());
        builder.append("Index: 3\n");
        builder.append(PSList.get(3).toString());
        builder.append("Index: 4\n");
        builder.append(PSList.get(4).toString());

        JOptionPane.showMessageDialog(null,builder);

        int malay =0;
        int chinese = 0;
        int indian = 0;
        for(int i = 0; i < 5; i++)
        {
            if(PSList.get(i).getRace().equalsIgnoreCase("Malay"))
            {
                malay++;
            }
            else 
            {
                if(PSList.get(i).getRace().equalsIgnoreCase("Chinese"))
                {
                    chinese++;
                }
                else
                {
                    indian++;
                }
            }

        }
        JOptionPane.showMessageDialog(null,"Number of Malay:" + malay + "\nNumber of Chinese:" + chinese + "\nNumber of Indian:" + indian);


    }


}

Here is my Object class

    String name;
    String race;
    int age;

    public PreSchool()
    {
        name = " ";
        race = " ";
        age = 0;
    }

    public PreSchool(String n, String r,int a)
    {
        name =n;
        race =r;
        age = a;
    }

    public String getName() {
        return name;
    }

    public String getRace() {
        return race;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Name:" + name + ", race:" + race + ", age:" + age + '\n';
    }


}

Tax calculator in javascript

How do I split the result for the income tax brackets to auto display the right tax due when the gross pay affected is in a particular tax bracket.

Income Tax Bands    Tax Rates     Tax Due
3,300.00 and Below         0%        0
3,300.01 – 4,100.00        25%       0
4,100.01 – 6,200.00        30%       0
6,200.00 and Above         37.5%     0

Undefined element of forEach inside if condition [closed]

I try to make next code:

if(parseInt(e.target.value) === 1){            
            e.target.nextSibling.childNodes.forEach(element => {
                element.classList.add('disable')
            });            
        }
        else if(parseInt(e.target.value) === 2){
            e.target.nextSibling.childNodes.forEach(element,index => {
                index === 0 ?
                element.classList.remove('disable')
                :element.classList.add('disable')
            });
        }

and in second condition it throw me error 'element' is not defined but in first it works fine. But I cant understand why if statment make my element is undefined?

Is it possible to have multiple conditions in a function which includes a for loop in Python?

I'm new to programming with Python. Currently, I'm working on a program/algorithm to determine maintenance (combined replacement of multiple items) based on these items their condition. To be precise, I want to replace these items when one item's condition is below a predetermined threshold (for example 10%). The problem I have with my code, see below, is when this threshold is met all items are replaced.

def maintenance_action(self):
    do_repair = False
    for i in item:
        if i.condition[-1] <= 10:
            do_repair = True     
            break

    if do_repair:
        for i in items:
            i.repair()

However, I want to include an additional threshold (let's say 50%) which excludes all items with a condition > 50% from the maintenance action. It is important that the first threshold is met (because this item must be replaced) before the second one 'kicks in' (the items I want to include). I hope someone can help me.

Thanks!

Is there any mistake in my condition statement? [closed]

These are my snipped code below. When i input 2, which is the feline type, it was supposed to either output Feline doesnt want to roam at all today if the feli is 0 or Roaming for total range of 0 in 12 minutes if the feli is not 0. But, in my output which i attached the picture below, it also prints the roaming for total range of 0 in 12 even if the feli is zero. Is there any mistake on my condition statement? Any help is appreciated. Thank you.

void take(){
        int choose;
        int roam;
        int roaming;
        int p = anm.nama.size();
        if(p==0){
            view();
        }
        else{
            view();

            do{
                System.out.print("Choose animal to take for a stroll [1 - " + p+ "]: ");
                choose = scan.nextInt();
            }while(choose<1||choose>p);

            do{
                System.out.print("Roaming time [0-50]: ");
                roam = scan.nextInt();
            }while(roam < 0 || roam > 50 );

            if(roam==0)roaming = 60;
            else roaming = roam;

            for(int i=0; i<anm.nama.size(); i++){
                if(fel.genuss.get(i).equals("feline")){
                    int batas = 2;
                    Random rand = new Random();
                    int feli = rand.nextInt(batas);

                    if(feli == 0){
                        System.out.println("Feline doesn't feel like roaming at all today..");
                        break;
                    }
                    else{
                        int duration = 0;
                        if(roaming == 30)
                            {
                            duration = 30;
                            System.out.println("Roaming for total range of " + anm.range() +" in " + duration +" minutes");
                            }
                        else System.out.println("Roaming for total range of " + anm.range() +" in " + duration +" minutes");
                        break;
                    }
                }


                else if(can.genuss.get(i).equals("canine")){
                    int duration = 0;
                    if(roaming==0)
                        {
                        duration = 60;
                        anm.range();
                        System.out.println("Roaming for total range of " + can.range() +" in " + duration +" minutes");
                        }
                    else duration = roaming;
                    anm.range();
                    System.out.println("Roaming for total range of " + can.range() +" in " + duration +" minutes");
                }
            }
        }


    }

This is my output

what's the difference on dealing char between where statement and if statement in SAS 9.4M6

Recently, I happen to find an interesting thing:

data test;
    set sashelp.class;
    if _N_ in (2 3 5 7) then name = '';
run;

data test;
    set ;
    where name;
run;

The result is: data Test has 15 observations.

I use SAS 9.4M6 for over a year and don't remember that where statment can deal with char type variable just like boolean type variable. I strightly change where to if and it leads the results: name is not a numeric variable and data Test has 0 observation.

So here is my two questions:
1. Is where name; another way of where name is not missing? if not, what happens when submitwhere name?
2. When did this kind of code(where <variable>;) start be allowed in SAS?

Thanks for any tips.

I am stuck in "If" & "Else" function one of my android app

I my app I am fetch some text data from the server and showing this text data in the TextView. Here is something works fine. I am add an little arrow ImageView right to the TextView and this TextView is expandable so when TextView is more then 2 lines and if anyone click this TextView it expand and again click to shrink and I am also add an little arrow image right to the TextView (so user understant that it is an expandable text), here is everything is fine all code are works perfectly but now I want to remove this litter arrow image when the TextView is under 2 lines and when TextView is more then 2 lines it show. I want to tell you one more thing that I am also add a rotation in the arrow image so when the user click the text the little arrow image rotate the 180 degree and also text is expand and when user click the text second time arrow image again rotate to his previous position and text is shrink in 2 lines.

I want to remove this little arrow when the text is under 2 lies I do not want to remove the arrow image when text line more then 2, I'm guessing you understand.

I am new to the Java Code and I am learning is language so now I want to learn how to do this implementation in my app, I have add my code below so that you can understand batter.

textViewMyVideoTitle.setText(videoLists.get(0).getVideo_title());
my_title_layout_expand.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View view) {
    if (isTextViewClicked) {
      //This will shrink textview to 2 lines if it is expanded.
      textViewMyVideoTitle.setText(videoLists.get(0).getVideo_title());
      myTitleImageView.setRotation(imageView.getRotation() + 0);
      myTitleImageView.setVisibility(View.VISIBLE);
      textViewMyVideoTitle.setMaxLines(2);
      isTextViewClicked = false;
    } else {
      //This will expand the textview if it is of 2 lines
      textViewMyVideoTitle.setText(videoLists.get(0).getVideo_title());
      myTitleImageView.setRotation(imageView.getRotation() - 180);
      myTitleImageView.setVisibility(View.VISIBLE);
      textViewMyVideoTitle.setMaxLines(Integer.MAX_VALUE);
      isTextViewClicked = true;
    }
  }
});

So anybody can help me to achieve this code

enter image description here enter image description here