Menu
Coddy logo textTech

Recap - Making Comparisons

Part of the Fundamentals section of Coddy's Dart journey — lesson 27 of 94.

challenge icon

Challenge

Easy

You're building a system for a spaceship that determines if passengers can board based on various criteria. Create a program that:

  1. Declares the following variables:
    • An int variable passengerAge with value 25
    • A double variable ticketPrice with value 149.99
    • A bool variable hasBoardingPass with value true
    • A bool variable hasLuggage with value false
    • A var variable passengerType with value "Regular"
  2. Create a boolean variable isAdult that checks if passengerAge is greater than or equal to 18
  3. Create a boolean variable isDiscounted that checks if ticketPrice is less than 150.0
  4. Create a boolean variable canBoardNormally that is true only if:
    • The passenger is an adult AND has a boarding pass AND the ticket price is not equal to 0.0
  5. Create a boolean variable needsAssistance that is true if:
    • The passenger is NOT an adult OR has luggage
  6. Create a boolean variable isValidPassengerType that checks if passengerType is of type String
  7. Create a boolean variable isNotNumber that checks if passengerType is NOT of type int
  8. 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