Question

- Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...

- Part 1 – 4 Debugging Exercises – there are things wrong – either logic or syntax errors.  Correct the pseudocode and one Java program. Add the corrected code in BOLD and change the corrected color to RED.  

Debugging 4:  Add the missing code in bold and red.

import java.util.Scanner;

public class Airline

{

            public static void main(String args[])

            {

                        Scanner s = new Scanner(System.in);

                        String passengerName = ""     

                        String ageString = ""  

                        int passengerAge = 0

                        System.out.println("Enter passenger's name: ");

                        passengerName  = s.nextLine();

                        System.out.println("Enter passenger's age: ");

                        ageString  = s.nextLine();

                        

                        passengerAge = Integer.parseInt(ageString)

                                                            

                        if(passengerAge <=6 || passengerAge = 65)

                        {

                           System.out.println("Passenger name: " + passengerName);                         

                           System.out.println("Passenger age : " + passengerAge)

                           System.out.println("This passenger is eligible for a 25% discount.");

                        }

                        else

                        {

                           System.out.println("Passenger name: " + passengerName);                         

                           System.out.println("Passenger age : " + passengerAge)

                           System.out.println("This passenger is not eligible for a 25% discount.");

                        }

                        System.exit(0);

            }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Airline

{

            public static void main(String args[])

            {

                        Scanner s = new Scanner(System.in);

                        String passengerName = "" ;   

                        String ageString = "" ;

                        int passengerAge = 0 ;

                        System.out.println("Enter passenger's name: ");

                        passengerName  = s.nextLine();

                        System.out.println("Enter passenger's age: ");

                        ageString  = s.nextLine();

                        

                        passengerAge = Integer.parseInt(ageString) ;

                                                            

                        if(passengerAge <=6 || passengerAge == 65)

                        {

                           System.out.println("Passenger name: " + passengerName);                         

                           System.out.println("Passenger age : " + passengerAge);

                           System.out.println("This passenger is eligible for a 25% discount.");

                        }

                        else

                        {

                           System.out.println("Passenger name: " + passengerName);                         

                           System.out.println("Passenger age : " + passengerAge);

                           System.out.println("This passenger is not eligible for a 25% discount.");

                        }

                        System.exit(0);

            }

}

public static void main(String args[]) { Scanner s = new Scanner(System.in); 8 9 10 11 12 13 14 15 16 String passenger Name =

Add a comment
Know the answer?
Add Answer to:
- Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Making Multiple Comparisons in Decision Statements in Java Q Sear Making Multiple Airline java Comparisons in...

    Making Multiple Comparisons in Decision Statements in Java Q Sear Making Multiple Airline java Comparisons in Decision Statements 1 /1 Atrline. java - Thts progran deterntnes tf an atrline passenger 2! // eligible for a 25% discount. 4 inport java. util.Scanner; 6 public class Atrltne 8 public static void nain(String args[1) Summary In this lab, you complete a partially written Java program for an airline that offers a 25 percent discount to passengers who are 6 years old or younger...

  • DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

    DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo {    public static void main (String args[])    {       Scanner kb = new Scanner(System.in);       int num1, num2;             System.out.print("Enter an integer >> ");       num1 = kb.nextInt();       System.out.print("Enter another integer >> ");       num2 = kb.nextDouble();       displayTwiceTheNumber(num1);       displayNumberPlusFive(num1);       displayNumberSquared(num1)       displayTwiceTheNumber(num2);       displayNumberPlusFive(num2);       displayNumberSquared(num2);    }   ...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • This is my code but my overtime calculation is wrong and I cant figure out how...

    This is my code but my overtime calculation is wrong and I cant figure out how to round to two decimal places import java.util.Scanner; public class HourlyWage { public static void main(String[] args) { //Variables double totalWage; double totalOvertimePay; double totalPay; String name; double overtimeHours = 0.0; double hoursWorked = 0.0; double hourlyWage = 0.0; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter your name "); name = keyboard.next(); System.out.println("Please enter your hourly wage "); hourlyWage = keyboard.nextDouble(); System.out.println("How many hours...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT