Assignemnt #31 Compound Boolean
Code
Name: Iaroslav Titov
Period: 7
Project Name: ShallowGrandmother
File Name: ShallowGrandmother.java
Date: 10/2/2015
import java.util.Scanner;
import java.util.InputMismatchException;
public class ShallowGrandmother
{
public static void main( String[] args )
{
try
{
Scanner keyboard = new Scanner(System.in);
int age;
double income, attractiveness;
boolean allowed;
System.out.print( "Enter your age: " );
age = keyboard.nextInt();
System.out.print( "Enter your yearly income: " );
income = keyboard.nextDouble();
System.out.print( "How attractive are you, on a scale from 0.0 to 10.0? " );
attractiveness = keyboard.nextDouble();
allowed = ( age > 25 && age < 40 && ( income > 50000 || attractiveness >= 8.5 ) );
}
catch (InputMismatchException e)
{
System.out.println( "YOU CAN'T EVEN TYPE IN THE INPUT RIGHT, SO FORGET ABOUT MY GRANDCHILD!!" );
allowed = false;
}
System.out.println( "You are allowed to date my grandchild: " + allowed );
/*
This turned out to be interesting how bitwise AND and OR work
Operator compares each digit of the binary representation of a number to the other one's digits
int a = 60; 60 = 0011 1100
int b = 13; 13 = 0000 1101
int c = 0;
c = a & b; 12 = 0000 1100
System.out.println("a & b = " + c );
c = a | b; 61 = 0011 1101
System.out.println("a | b = " + c );
*/
}
}
Picture of the output