dimanche 27 novembre 2016

Inaccessible returned Strings in Java

I keep getting the error that the Strings cannot be passed from method to method and I need to do that. The goal of the program is to return two Strings and an integer to the main to access another method that will randomly generate a name based off of the given factors. NameGenerator.java:12: error: cannot find symbol String rappername = rappername(firstname, lastname, color); symbol: variable firstname location: class NameGenerator 1 error

import java.util.*; public class NameGenerator{

  public static void main(String[] args) {
  Scanner console= new Scanner(System.in);
  firstname(console);
  lastname(console);
  color(console);
  String firtname = firstname(console);
  String lastname = lastname(console);     
  int color = color(console);
  String rappername = rappername(firstname, lastname, color);
  }

  public static String firstname(Scanner console) {
  System.out.println("Welcome to my Program!");
  System.out.println("I'm going to tell you your rapper name.");
  System.out.println("What is your first name? (Type stop to quit) ");
  String firstname;
   firstname = console.nextLine();
  if (firstname.equals("stop")) {
     System.exit(0);
  }
  else {
  return firstname;
    }
 }

 public static String lastname(Scanner console) {
  String lastname;
  System.out.println("What is your last name? ");
   lastname = console.nextLine();
  return lastname;
  }

  public static int color(Scanner console) {
  int color;
  System.out.println("Pick the number to your color of choice");
  System.out.println("Blue (1)");
  System.out.println("Red (2)");
  System.out.println("Purple (3)");
  color = console.nextInt();
  return color; 
  }

public static String rappername(String firstname, String lastname, int color)  `       {    
  System.out.println(firstname+lastname+color);
  }  
  }

if variable might not have been initialized [duplicate]

This question already has an answer here:

it's give me error on netbeans

could anyone help me. thanks.

double d;
double v;
double p;
String input;

input = JOptionPane.showInputDialog("Please enter the value : ");
v = Double.parseDouble(input);

if (v > 99){
    if(v < 200){
        d = v * 0.05;
        p = v - d;
    } else if (v < 300){
        d = v * 0.10;
        p = v - d;
    } else if (v < 400){
        d = v * 0.15;
        p = v - d;
    } else if (v < 500){
        d = v * 0.20;
        p = v - d;            
    } else if (v > 499){
        d = v * 0.25;
        p = v - d;            
    }

    JOptionPane.showMessageDialog(null , "you\'r discount is : " + d + "\n you have to pay : " + p );

} else{
    // zero 
    JOptionPane.showMessageDialog(null, "there is no discount. ");
}

Use of the if statement

I'm beginner in Java, and I'm learning the if statement without else, can please the community check my code to improve?

/* Code made by edu.

In this code we use only the if statement to practice. Here you need to enter your age to enter to the bar with hot girls, if your age is above to 18, you can enter. if it is below 18 you can't enter.

*/

import java.util.Scanner;

public class Main { public static void main(String[] args){

    Scanner input = new Scanner(System.in);

    int age;

    // Ask the age
    System.out.println("Please write your age to enter to the bar:");
    age = input.nextInt();

    // Equal to
    if(age == 18){
        System.out.println("Your age " + age + " it's equal to 18, you can enter");
    }

    // Not equal to
    if(age != 18){
        System.out.println("Your age " + age + " it's not equal to 18");
    }

    // Greater than
    if(age > 18){
        System.out.println("Your age " + age +  " " + "is greater than 18, you can enter");
    }

    // Less than
    if(age < 18){
        System.out.println("Your age " + age + " " + "is less than 18, you can't enter");
    }

    // Greater than or equal to
    if(age >= 18){
        System.out.println("Your age " + age + " is greater than or equal to 18, you can enter");
    }
    // Less than or equal to
    if(age <= 18){
        System.out.println("Your age " + age + " is less than or equal to 18, you can't enter");
    }
}

}

why does the order of my if statement affect what gets printed? python [duplicate]

This question already has an answer here:

I am new to programming and i have come across this when i have been trying to make a simple game. You have to guess a letter and if it is in the word it should response with that letter is in the word and if it isn't then it should say it isn't. Instead is just prints the first if statement result no matter what the input is. i switched the if and elif order around and it still only printed the first if statement result. How do i fix this? Here is my code:

    response2 = input("What is your first letter or guess at the word?")
    b = str(response2)
    if b != "s" or "n" or "a" or "k" or "e":
        print("That letter is not present. You have 6 lives remaining.")
        lives -= 1
    elif b == "s" or "n" or "a" or "k" or "e":
        print("That letter is in the word!")
    elif b == "snake":
        print("You won! That was quick!") 

No matter what the input is here is prints "That letter is not present." swapping the order meant that what ever the input it said "That letter is present" even when it didn't fix the if statement.

(Java) Read list of int values, (sentinel -1), print only occurrences of 2 followed by 3

I need to write a program that reads the input from the user of a list of integers and prints only occurrences of 2 followed by 3, using while loop and if statements.

Thank you!

Convert values to a number using excel vba if statement

I have a column in excel that has two values "Disqualified" and "Open".

I want to use an If Statement using VBA to change the disqualified values to 0 and the Open values to 1.

Here is the excel formula that shows what I want to do

=IF(H:H="Disqualified","0","1")

I think I need a for loop to loop through all the values in column H but can't seem to get this to work. Thanks

IF OR Function in jQuery on a PHP site

Can anyone tell me what's wrong and how to fix this bit of code...

I am trying to bring up a message and not go to the next page, if the #send_country box has either nothing in it or says "Send From..." (as its the placeholder).

This is the bit of code I am having issues with:

 if (country == '0' || country == "Send From...") {
                error = 1;
                jQuery('.msg').text("Please Select A Country.");
            }

I think I have an issue with the OR function as it works without the || country == "Send From...". Thanks

<script>
    jQuery(document).ready(function(){
        jQuery('.submit').click(function() {

            var error = 0;
            var country = jQuery('#send_country').val();
            var countrys = jQuery('#delv_country').val();
            var idsa = jQuery('.size').val();

            if (country == '0' || country == "Send From...") {
                error = 1;
                jQuery('.msg').text("Select A Country.");
            }
            if (countrys == '0') {
                error = 1;
                jQuery('.msg').text("Select A Country.");
            }

            if (error) {
                return false;
            } else {
                return true;
            }

        });

    });
    </script>