Yes.
The sales manager of the car lot will let you buy the car if:
Say that "outstanding debts" means debts more than $1,000. Here is a program that makes the car buying decision:
// Sports Car Purchase
// New $25,000 red Miata sports car.
// You need cash or credit with no debts .
//
import java.io.*;
class HotWheels2
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin =
new BufferedReader ( new InputStreamReader( System.in ) );
String inData;
int cash, credit, debt ;
// get the cash
System.out.println("How much cash?");
inData = stdin.readLine();
cash = Integer.parseInt( inData );
// get the credit line
System.out.println("How much credit do you have?");
inData = stdin.readLine();
credit = Integer.parseInt( inData );
// determine the debts
System.out.println("How much much do you owe?");
inData = stdin.readLine();
debt = Integer.parseInt( inData );
// check that at least one qualification is met
if ( cash >= 25000 || ( credit >= 25000 && debt < 1000 ) )
System.out.println("Enough to buy this car!" );
else
System.out.println("Have you considered a Yugo?" );
}
}
The boolean expression of the if
statement correctly implements the
car buying rules.
The expression includes both &&
and ||
.