Question

Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input...

Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input file name. This is the name of a text file that can contain any number of records. A record in this file is a single line of text in the following format: Num of passengers^range^name^manufacturer^model

where:

Num of passengers is the total number of people in the plane. This represents an integer number, but remember that it is still part of the String so each "digit" is actually a character. It is not an integer until it is extracted from the String and converted into an actual integer. The Num of passengers is followed by a '^' character, there are no spaces before or after the '^'.

range is the range, in kilometres, of the plane. This represents an integer number, but remember that it is still part of the String so each "digit" is actually a character. It is not an integer until it is extracted from the String and converted into an actual integer. The range is followed by a '^' character, there are no spaces before or after the '^'.   

name, is the name of plane. This is a String (text) and may have spaces in it. The name may be empty as not all planes have "names". The name is followed by a '^' character, there are no spaces before or after the '^'.

manufacturer, is the name of the company that makes the plane. This is a String (text) and may have spaces in it. The manufacturer is followed by a '^' character, there are no spaces before or after the '^'.

model, is the name of the model of the plane. This is a String (text) and may have spaces in it. The model is the end of the String, there is only a newline character (not seen) after model, as this is the end of the line.

An example of some of the lines of this file might be: 1^835^Butcher Bird^Focke-Wulf^Fw 190 853^15700^^Airbus^A380-800 10^3200^Flying Fortress^Boeing^B17-G

Once this file has been opened, the user is then prompted (asked) for a manufacturer and a model. The program then reads through the file. If a matching manufacturer and model is found in the file, all the information for that plane is displayed to the screen. The order of display is shown in the example runs below.

Manufacturer's can be repeated in the file, but, the combination of manufacturer AND model is unique in the file, so there will be at most only one match.

User entered manufacturer's and model's must be case insensitive, that is, any combination of uppercase and lowercase letters must give the same result.

If the entire contents of the file has been read and no match is found, then an appropriate message is displayed to the screen. The data is surrounded by " ". Output is on one line, even though it is shown wrapped around, just to fit on this page.

Some sample runs of the program are included below (user input is in bold): (Note that the sample runs do not necessarily show all the functionality required)

> java Flying

Enter file name >> planes.dat Enter manufacturer >> Sukhoi Enter model >> Su-27 Name: "Flanker" model: "Su-27" manufacturer: "Sukhoi" range: "3530kms" passengers: "1"

> java Flying

Enter file name >> planes.dat Enter manufacturer >> Focke-Wulf Enter model >> Ta-152 No plane with the model "Ta-152" made by the manufacturer "Focke-Wulf" was found

> java Flying

Enter file name >> e.dat The file "e.dat" is an empty file, program closing

An example input file for all Tasks may be copied from the csilib area

cp /home/student/csilib/cse1oof/assignA/a.dat .

cp /home/student/csilib/cse1oof/assignA/f.dat .

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

import java.util.*;

import java.io.*;

public class file {

public static void main(String[] args) throws IOException{

Scanner s=new Scanner(System.in);//for read the data

System.out.println("Enter file name >>");//enter the filename

String file_name=s.nextLine();// read the filename and copied to file_name

System.out.println("Enter manufacturer >>");//enter the manufacture

String man_name=s.nextLine();////for read the manufacture model name and copied to man_name

System.out.println("Enter model >>");// enter the model name

String model=s.nextLine();//for read the model name and copied to "model" variable;

  

FileReader fr=new FileReader(file_name);// file name given input for file reader

BufferedReader br=new BufferedReader(fr);// file reader is given input for BufferedReader

String row;

  

int i=0;int count=0;

while((row=br.readLine())!=null) // to read the all lines from the file

{ i++;

StringTokenizer st=new StringTokenizer(row,"^");// split the line using "^" Delimiter

int pass=Integer.parseInt(st.nextToken()); //to read the passenger name

int range=Integer.parseInt(st.nextToken());// to read the range

String name=st.nextToken();// to read the name

String manufacturer=st.nextToken();// to read the manufacture name

String model1=st.nextToken();// t read the modal name

if(manufacturer.equalsIgnoreCase(man_name) && model.equalsIgnoreCase(model1))//compare the given inputs manufacture

{ count=1;

System.out.println("Name: \""+name+"\"\nmodel \""+model1+"\"\nmanufacturer: \""+manufacturer+"\"\nrange \""+range+" kms\"\npassengers: \""+pass+"\"");

}

}

if(count==0)

System.out.println("No plane with the model \""+model+"\" made by the manufacturer \""+man_name+"\" was found");

if(i==0)

System.out.println("The file \""+file_name+"\" is an empty file, program closing");

br.close();// close buffer reader

fr.close();// close file reader

  

}

}

Add a comment
Know the answer?
Add Answer to:
Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input...
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
  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • In Java, write a program that prompts the user to input a sequence of characters and...

    In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

  • Write a Java program that performs these operations Prompt the user to enter a low height...

    Write a Java program that performs these operations Prompt the user to enter a low height in feet (an integer) Prompt the user to enter a high height in feet (an integer) Prompt the user to enter a low weight in pounds (an integer) Prompt the user to enter a high weight in pounds (an integer) Print a table of Body Mass Index (BMI) for the heights and weights entered, ranging from the low height to the high height (inclusive),...

  • Java Question, I need a program that asks a user to input a string && then...

    Java Question, I need a program that asks a user to input a string && then asks the user to type in an index value(integer). You will use the charAt( ) method from the string class to find and output the character referenced by that index. Allow the user to repeat these actions by placing this in a loop until the user gives you an empty string. Now realize that If we call the charAt method with a bad value...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • (JAVA NetBeans) Write a Java program, which asks the user to enter a string, then (a)...

    (JAVA NetBeans) Write a Java program, which asks the user to enter a string, then (a) reverse the string, (b) change the case of the string (CaT cAt) (c) print the chars at even positions (Object Ojc)

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

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