1. Engineering
  2. Computer Science
  3. java the purpose of my assignment is to create a...

Question: java the purpose of my assignment is to create a...

Question details

Java:

The purpose of my assignment is to create a program that will book flight tickets. The program is meant to find the starting and ending point for the flight, which class the user wants to travel and the amount of bags they will carry, and it will then print the sum.

I'm running into two issues right now: One, I'm getting errors on my if statements for the variable TravelClass and subsequently the variable bags. And secondly, for my city inputs that have two words, such as New York for example, the program stops and doesn't proceed to the next step. I'm struggling on how to fix that.

This is a partial code that I have:

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        String start;
        String end;
        int TravelClass;
        int bags;
        double charge;
        double cost;
        double sum;
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter your starting point: ");
        start = scan.next();

            if (start.equals("Houston")) {
                System.out.println("Enter your endpoint: ");
                end = scan.next();
                if (end.equals("Austin")) {
                    System.out.println("Enter travel class (1 - First, 2 - Business, or 3 - Economy: ");
                    TravelClass = scan.nextInt();
                    if TravelClass = 1 {
                      charge = 956;
                      System.out.println("How many bags will you carry: ");
                      bags = scan.nextInt();
                      if (bags <= 3) {
                          cost = 0;
                        }
                      if (bags >=4) {
                          cost = 200;
                        }
                      sum = charge + cost;
                      System.out.println("Total cost of ticket from Houston to Austin: $" + sum);
                    }
                    }
                }
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution