https://imgur.com/a/wmUMo Question 1: Write an if statement that assigns 13 to n
ID: 3723041 • Letter: H
Question
https://imgur.com/a/wmUMo
Question 1: Write an if statement that assigns 13 to num when var is equal to 4 Quesiton 2: Write an if-else statement that assigns 9.5 to dec2 when dec1 is equal to 3.2, otherwise dec2 is 4.5 Question 3: Using the following chart, write an if-else-if statement that assigns 4%, 5%, or 6% to commission rate, depending on the value in sales Sales Up to $15,000 $15,000 to $40,000 Over $40,000 Commission Rate 4% 5% 6% Question 4: Write nested if statement that perform the following tests: If amount1 is greater than or equal to 15,000 and amount2 is greater than and equal to 20,000, and if amount1 is less than amount2 then display the message: "Sale the product 2 better" otherwise display the message: "Sale the product 1 better". But if amount1 is less than 15,000 or amount2 is less than 20,000 then display the message: "Sale is not good" Question 5: Write an if statement that prints the message “The grade is B" if the average is greater or equal to 80 and less than and equal to 90 Question 6: Write an if statement that prints the message 'The value is valid" if the temparature is within the range -32 through 273 Question 7 Notes: In java, to compare 2 Strings, we use the method compareTo) string1.compareTo(string2)-0 string! and string2 are the same string1.compareTo(string2) > 0 stringl is greater thant string 2 string1.compareTolstring2)Explanation / Answer
1)
if(var==4)
num=13;
2)
if(dec1==3.2)
dec2=9.5;
else
dec2=4.5;
3)
if(sales<15000)
rate=0.04;
else if(sales>=15000 && sales<=40000)
rate=0.05;
else if(sales>40000)
rate=0.06;
4)
if(amount1>=15000 && amount2>=20000)
{
if(amount1<amount2)
System.out.println("Sale the product 2 better");
else
System.out.println("Sale the product 1 better");
}
else if(amount1<15000 || amount2<20000)
System.out.println("Sale is not good");
5)
if(average>=80 && average<=90)
System.out.println("The grade is B");
6)
if(temperature>=-32 && temperature<273)
System.out.println("The value is valid");
7)
if(str1.compareTo(str2)==0)
System.out.println("str1 and str2 are the same");
else if(str1.compareTo(str2)>0)
System.out.println("str1 is greater than str2");
else
System.out.println("str1 is less than str2");
8)
switch(choice)
{
case 1: System.out.println("You selected 1");
break;
case 2: System.out.println("You selected 2");
break;
case 3:
case 4: System.out.println("You selected 3 or 4");
break;
default:
System.out.println("Select again please.");
}
9)
a)
if(n>m)
x=5;
else
x=8;
b)
if(a==b)
y=2;
else
y=4;
c)
if(u<=v)
z=6;
else
z=12;
10)
DecimalFormat df=new DecimalFormat("0.000");
System.out.println(df.format(0.01432));
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.