Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2.2 Construct a logical expression to represent each of the following conditions

ID: 641154 • Letter: 2

Question

2.2 Construct a logical expression to represent each of the following conditions:
a. x is between 3 and 15 but not equal to 10.
b. x is between 10 and 20 but not odd.
c. y is divisible by 5 but not by 40.
d. str is a lowercase or uppercase letter.

Write an Algorithm to decide which is cheaper car or bus for a travel:
You want to decide whether you should drive your car to work or take the bus. You know the one-way distance from your home to your place of work, and the fuel efficiency of your car (in miles per gallon). You also know the one-way price of a train ticket. You assume the cost of gas at $4 per gallon, and car maintenance at 5 cents per mile. Write an algorithm to decide which commute is cheaper.

Write a program that simulates a simple calculator. It reads two integers and a character. If the character is a +, the sum is printed; if it is a -, the difference is printed; if it is a *, the product is printed; if it is a /, the quotient is printed; and if it is a %, the remainder is printed.

Explanation / Answer

2.2 Construct a logical expression to represent each of the following conditions:
a. x is between 3 and 15 but not equal to 10.
   if(x>=3&&x<1=5&&x!=10)
b. x is between 10 and 20 but not odd.
   if(x>=10 && x<=20 && (x%2!==0)
c. y is divisible by 5 but not by 40.
   if(y%5==0 && y%s!==40)
d. str is a lowercase or uppercase letter.
isUpper(str)......isLower(str)


3)
Calculator.java

import java.util.*;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args)
{
System.out.println("Enter first and second number:");
Scanner inp= new Scanner(System.in);
int num1,num2;
num1 = inp.nextInt();
num2 = inp.nextInt();
int ans;
System.out.println("Enter your selection: + for Addition, - for substraction * for Multiplication and / for division:");
int choose;
choose = inp.nextString();
switch (choose){
case '+':
System.out.println(add( num1,num2));
break;
case '-':
System.out.println(sub( num1,num2));
break;
case '*':
System.out.println(mult( num1,num2));
break;
case '%':
System.out.println(div( num1,num2));
break;
default:
System.out.println("Illigal Operation");


}

}
public static int add(int x, int y)
{
int result = x + y;
return result;
}
public static int sub(int x, int y)
{
int result = x-y;
return result;
}
public static int mult(int x, int y)
{
int result = x*y;
return result;
}
public static int div(int x, int y)
{
int result = x/y;
return result;
}

}

2)
enter distance in miles
gallons_required = miles; //in us conversion
cost_car = 4*100*gallons_required+5*miles;
enter train ticket
if(ticket<cost_car){
   print train is better
}
else{
   car is better
}