This is my line of code
if (tweet.indexOf("RT:" || "Rt:" || "rt:" || "rT:") > 0)
I am checking to see if the tweet the user inputs has any variations of rt:
This is my line of code
if (tweet.indexOf("RT:" || "Rt:" || "rt:" || "rT:") > 0)
I am checking to see if the tweet the user inputs has any variations of rt:
Why isn't this switch statement changing the values of the object? For some reason when it runs any case, this.(anything) = (anything) doesn't change the value of the object. I want for example, in case "Living Room", this.upNext1 = "Pantry".
public class HauntedHouse {
public static class room{
String previousRoom = "";
String currentRoom = "Front Door";
String upNext1 = "Living Room";
String upNext2 = "Dining Room";
String upNext3 = "Stairs";
String object1 = "";
String object2 = "";
public room(){};
public void room(String currentRoom){
switch(currentRoom){
case "Front Door":
this.previousRoom = this.currentRoom;
this.currentRoom = "Front Door";
this.upNext1 = "Living Room";
this.upNext2 = "Dining Room";
this.upNext3 = "Stairs";
this.object1 = "";
this.object2 = "";
case "Living Room":
this.previousRoom = this.currentRoom;
this.currentRoom = "Living Room";
this.upNext1 = "Pantry";
this.upNext2 = "1st Floor Bathroom";
this.upNext3 = "";
this.object1 = "Chest";
this.object2 = "";
case "Dining Room":
this.previousRoom = this.currentRoom;
this.currentRoom = "Dining Room";
this.upNext1 = "Kitchen";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Candelabra";
this.object2 = "";
case "Stairs":
this.previousRoom = this.currentRoom;
this.currentRoom = "Dining Room";
this.upNext1 = "Bedroom 1";
this.upNext2 = "Bedroom 2";
this.upNext3 = "Master Bedroom";
this.object1 = "Candelera";
this.object2 = "Shower";
case "1st Floor Bathroom":
this.previousRoom = this.currentRoom;
this.currentRoom = "1st Floor Bathroom";
this.upNext1 = "";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Mirror";
this.object2 = "Shower";
case "Pantry":
this.previousRoom = this.currentRoom;
this.currentRoom = "Pantry";
this.upNext1 = "";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Dusty recipe box";
this.object2 = "Broom";
case "Kitchen":
this.previousRoom = this.currentRoom;
this.currentRoom = "Kitchen";
this.upNext1 = "Pantry";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Refrigerator";
this.object2 = "Cabinet";
case "Bedroom 1":
this.previousRoom = this.currentRoom;
this.currentRoom = "Bedrrom 1";
this.upNext1 = "2nd Floor Bathroom";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Rocking Chair";
this.object2 = "Window";
case "2nd Floor Bathroom":
this.previousRoom = this.currentRoom;
this.currentRoom = "2nd Floor Bathroom";
this.upNext1 = "Bedroom 2";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Mirror";
this.object2 = "Shower";
case "Bedroom 2":
this.previousRoom = this.currentRoom;
this.currentRoom = "Bedroom 2";
this.upNext1 = "Master Bedroom";
this.upNext2 = "Bedroom 1";
this.upNext3 = "";
this.object1 = "Doll House";
this.object2 = "Dresser";
case "Master Bedroom":
this.previousRoom = this.currentRoom;
this.currentRoom = "Master Bedroom";
this.upNext1 = "Master Bathroom";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Jewelry Box";
this.object2 = "";
case "Master Bathroom":
this.previousRoom = this.currentRoom;
this.currentRoom = "Master Bathroom";
this.upNext1 = "";
this.upNext2 = "";
this.upNext3 = "";
this.object1 = "Intricate Oil Lamp";
this.object2 = "Shower";
}
Still very new to Python, so I apologize if anything in here is off. This is for a program where you enter a number, and get back a value. You have to enter a number, so I'm trying to make it say "different values needed" when the user enters a string. However, I have an int() around the input, which means I get the following error when I input a string:
ValueError: invalid literal for int() with base 10
My code is as follows:
while True:
OVR = int(input('OVR?'))
if OVR == 0:
break
elif OVR < 50:
print('0.75M')
elif OVR >= 50 and OVR < 60:
print('8M')
elif OVR >= 60 and OVR <= 70:
print('15M')
elif OVR > 70 and OVR <= 82:
print('30M')
elif OVR > 82:
print("He's the GOAT, what do you think he wants?")
else:
print('different values needed')
I know it's probably a bad idea to have all those elifs, so I will eventually consolidate that into one formula. As said earlier, my main goal is that I want to make this so that it prints "different values needed" when the user enters a string. I've considered a try/except statement, but if I'm understanding them correctly, they are not really for calculating and printing things, and also couldn't take these elifs.
Below I am asking the user to enter data, now if the user enters all field of data..then I get what i expect in return. Yet I want the user to be able to enter one value and print the entire row containing that one value the user entered. Now i am trying to use if else statements while the values are empty..but it is not working. Can someone tell me a better way?/ why this is not working?
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSetMetaData;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
public class DbReader
{
public static void main(String[] args)
{
Connection conn = null;
Scanner in= new Scanner(System.in);
String testing = "";
String empty = "";
try
{
Class.forName("com.mysql.jdbc.Driver");//need this for some reason
conn = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/dealer", "root", "root");
if(conn!=null)
{
System.out.println("connected successfully to database");
}
System.out.println("Please Enter Vehicle Information: ");
System.out.println("Make");
System.out.println("Color");
System.out.println("Model");
System.out.println("Year");
String make = in.next();
String color = in.next();
String model = in.next();
String year = in.next();
//String userInput="FOR";
if(make.equals(empty) && color.equals(empty)&& model.equals(empty)){
testing ="SELECT * FROM cars WHERE year = '"+year+"';";
}
else if(make.equals(empty) && color.equals(empty)&& year.equals(empty)){
testing ="SELECT * FROM cars WHERE year = '"+model+"';";
}
else if(make.equals(empty) && model.equals(empty)&& year.equals(empty)){
testing ="SELECT * FROM cars WHERE year = '"+color+"';";
}
else if(model.equals(empty) && color.equals(empty)&& year.equals(empty)){
testing ="SELECT * FROM cars WHERE year = '"+make+"';";
}
else
testing = "SELECT * FROM cars WHERE make = '" + make+"' AND color = '"+color+"' AND model = '"+model+"' AND year = '"+year+"';";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(testing);//this line causes me to lose connection why?..because i was printing from database not from table
while(rs.next()) {
if(rs.getString("make").equals(make) && rs.getString("color").equals(color))
{
System.out.println(" VIN: "+ rs.getString("vin"));
//System.out.println(" MAKE: ");
System.out.println(" MAKE: "+ rs.getString("make"));
// System.out.println(" MODEL: ");
System.out.println(" MODEL: "+ rs.getString("model"));
//System.out.println(" COLOR: ");
System.out.println(" COLOR: "+ rs.getString("color"));
System.out.println(" PRICE: "+ rs.getString("price"));
}else{
System.out.println(" Sorry No Cars meet that descrption at this time ");
}
}
st.close();
rs.close();
conn.close();
}catch(Exception e)
{
System.out.println("not connected to database");
}
}
}
I'm new to Java and at a loss what I'm doing wrong. I'm just trying to save the highscore and then print it.
int max = players[0].getHighScore();
int bestIndex = 0;
String bestName = "testing";
for (int i = 1; i < players.length; i=i+1) {
if (players[i].getHighScore() > max) {
bestIndex = i;
max = players[i].getHighScore();
bestName = players[i].getName();
}
}
System.out.println(bestIndex);
System.out.println(max);
System.out.println(bestName);
The variable max will update for every loop and then print the high score, no problems there. But the two other variables, bestIndex and bestName will just stay with the same value as initiated. I've even tried setting bestIndex and bestName to a constant and a string respectively inside the if statement but they won't change. If I remove the if statement, both will change, but ofcourse then I will just end up with the last entries, rather than the ones corresponding to the high score. So I figure the problem is with the if statement but other than that, I have no clue.
<body>
<pre>
<form>
<strong> Height:</strong> <input id ="Height"><br/>
<strong> Base: </strong> <input id ="Base"><br/>
<strong> Hypotenus: </strong> <input id ="Hypotenus"><br/>
</form>
<button type ="Button" onclick="Evaluate()">Find Area</button>
<p id ="Answer"> Answer will appear here </p>
<script>
function Evaluate() {
var H = document.getElementById("Height").value;
var B = document.getElementById("Base").value;
var Hy = document.getElementById("Hypotenus").value;
if (B == NaN || null) {
var Area = Math.sqrt(Math.pow(Hy, 2) - Math.pow(H, 2));
}
document.getElementById("Answer").innerHTML = Area;
}
</script>
</body>
I'm new to JavaScript and I've been trying to make a code that finds the formula of a triangle. My problem is after the if statement I would like to change the value of "Area" but I keep getting undefined everytime I run the code. How do I change the value of a variable within an if statement?
I am currently working with the IBM dashDB and I need to know the sql statement for inserting a new row if this row does not already exist based to certain criteria. So, something like this:
INSERT INTO tablexyz (Col1, Col2, Col3) VALUES (val1, val2, val3) IF NOT EXIST (SELECT * FROM tablexyz WHERE val1 = x, val2 = y)
How can I do this?