Recap - Making Comparisons
Part of the Fundamentals section of Coddy's Dart journey — lesson 27 of 94.
Challenge
EasyYou're building a system for a spaceship that determines if passengers can board based on various criteria. Create a program that:
- Declares the following variables:
- An
intvariablepassengerAgewith value25 - A
doublevariableticketPricewith value149.99 - A
boolvariablehasBoardingPasswith valuetrue - A
boolvariablehasLuggagewith valuefalse - A
varvariablepassengerTypewith value"Regular"
- An
- Create a boolean variable
isAdultthat checks ifpassengerAgeis greater than or equal to 18 - Create a boolean variable
isDiscountedthat checks ifticketPriceis less than 150.0 - Create a boolean variable
canBoardNormallythat is true only if:- The passenger is an adult AND has a boarding pass AND the ticket price is not equal to 0.0
- Create a boolean variable
needsAssistancethat is true if:- The passenger is NOT an adult OR has luggage
- Create a boolean variable
isValidPassengerTypethat checks ifpassengerTypeis of typeString - Create a boolean variable
isNotNumberthat checks ifpassengerTypeis NOT of typeint - Print all the variables with appropriate labels as shown in the expected output
Your output must match the exact format shown below.
Try it yourself
void main() {
// 1. Declare the passenger variables here
int passengerAge = ?;
double ticketPrice = ?;
bool hasBoardingPass = ?;
bool hasLuggage = ?;
var passengerType = ?;
// 2. Check if passenger is an adult
bool isAdult = ?;
// 3. Check if ticket is discounted
bool isDiscounted = ?;
// 4. Check if passenger can board normally
bool canBoardNormally = ?;
// 5. Check if passenger needs assistance
bool needsAssistance = ?;
// 6. Check if passengerType is a String
bool isValidPassengerType = ?;
// 7. Check if passengerType is not an int
bool isNotNumber = ?;
// 8. Print all variables with appropriate labels
print("Passenger Information:");
print("Age: $passengerAge");
print("Ticket Price: $ticketPrice");
print("Has Boarding Pass: $hasBoardingPass");
print("Has Luggage: $hasLuggage");
print("Passenger Type: $passengerType");
print("\nBoarding Checks:");
print("Is Adult: $isAdult");
print("Has Discounted Ticket: $isDiscounted");
print("Can Board Normally: $canBoardNormally");
print("Needs Assistance: $needsAssistance");
print("Valid Passenger Type: $isValidPassengerType");
print("Passenger Type is Not a Number: $isNotNumber");
}All lessons in Fundamentals
4Operators Part 2
Comparison OperatorsLogical ANDLogical ORLogical NOTType Test OperatorsRecap - Making Comparisons7Working with Strings
String ConcatenationString InterpolationMulti-line StringsString PropertiesBasic String Methods10Collections - Maps Basics
What are Maps?Creating a MapAccessing Values by KeyKey-Value PairsGetting Map SizeGetting KeysGetting ValuesChecking if a Key Exists13Null Safety In Depth
Understanding NullNullable TypesNon-Nullable TypesNull Assertion OperatorLate InitializationRecap - Handling Null Safely16Fundamentals Challenges
Challenge: List of calculationChallenge: Sum of numbersChallenge: Find product2Variables and Basic Data Types
What are Variables?StringsIntegers (int)Doubles (double)Booleans (bool)Type Inference with 'var'Final VariablesConstant VariablesNaming ConventionsBasic Null SafetyRecap - Declaring Variables8Control Flow - Loops
The 'for' LoopThe 'while' LoopThe 'do-while' LoopUsing 'break' in LoopsUsing 'continue' in LoopsRecap - Repeating Code3Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorIncrement and DecrementAssignment ShortcutsRecap - Simple Calculations6Control Flow - Decision Making
The 'if' StatementThe 'else' StatementThe 'else if' StatementRecap - Simple DecisionsNested 'if' StatementsThe 'switch' Statement9Collections - Lists Basics
What are Lists?Creating a ListAccessing by IndexGetting List LengthAdding ElementsRemoving ElementsChecking if a List is EmptyIterating Over a List12Functions Advanced
Optional Positional ParametersNamed ParametersRequired Named ParametersDefault Parameter ValuesRecap - Function Parameters15Project: Simple Calculator
Setting UpDeclaring Number