Practise reading from and writing to the console

Assignment Help JAVA Programming
Reference no: EM132356888

Assessment Objectives:

• To practise using the String class. (Lecture/Workshop 2 and Lab 2)
• To practise using if, if-else statements (Lecture 5 and 6, Lecture/Workshop 3)
• To practise reading from and writing to the console and reading from a text file.
In all the Tasks that follow, the String for State maybe empty (how you can detect this is described below). If the State String is empty, then the text "No State Listed" is assigned to the State String.

Task 1 - Task1.java

Write a Java program called Task1.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:

Airport-code)Airport-name)City)State)Country

where

Airport-code is the IATA airport code. This code uniquely identifies any airport in the world. It is always text, a String.
The Airport code is followed by a ')' character, there are no spaces
before or after the ')'.

Airport-name is the name of the airport associated with the IATA code. The Airport name will have at least 2 words in the name, but can have any number of words ,2 or more.
The Airport name is followed by a ')' character, there are no spaces before or after the ')'.

City, is the name of the city of the airport.
This is a String (text) and maybe than one word.
The City is followed by a ')' character, there are no spaces before or after the ')'.

State, is the name of the state, or province, that the airport is in. This is a String (text) and maybe more than one word.
The State may also be empty, it would look like this ))
The State is followed by a ')' character, there are no spaces before or after the ')'.

Country, is the name of the country, that the airport is in. This is a String (text) and maybe more than one word.
The Country is the end of the String, there is only a newline character (not seen)
after Country, as this is the end of the line.

An example of some of the lines of this file might be:

CHN)Jeonju Airport)Jeonju))South Korea FSZ)Shizuoka Airport)Shizuoka)Honshu)Japan CIY)Comiso Airport)Comiso)Sicily)Italy

The input file may have 0 to any number of records. The format of the input file is guaranteed to be correct. Your program does not have to check the format.

Also, your program must work with any file name of the correct format.
(Do NOT hard code the file name. See question 3, lab 3)
Once this file has been opened, the user is then prompted (asked) for an Airport Code

The program then reads through the file. If a matching Airport Code is found in the file, all the information for that airport is displayed to the screen. The order of display is shown in the example runs below. This means that you must break up the line into its parts,
as we did in lab2. Just printing the line straight out of the file will get very low marks.

Airport codes are unique, so once we have found a match and displayed the result, we can close the file and close the program.

User entered Airport codes must be case insensitive, that is, any combination of uppercase and lowercase letters must give the same result. This applies to all user input except, of course, file names which must be entered exactly as the file name on latcs8.

If the entire contents of the file have been read and no matching Airport code is found, then an appropriate message is displayed to the screen.

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 Task1
Enter file name >> a.dat Enter airport code >> WSY Code = WSY
Country = Australia State = Queensland
City = Airlie Beach / Shute Harbour Airport = Whitsunday Airport

> java Task1
Enter file name >> a.dat
Enter airport code >> ZZZ
No Airport was found with the code ZZZ

> java Task1
Enter file name >> x.dat
"x.dat" is an empty file, program closing
Input files for all Tasks to help you develop your programs may be copied from the csilib area

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

Task 2 - Task2.java

Write a Java program called Task2.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 (lines).

Each record has the same format as Task 1

The input file may have 0 to any number of records. The format of the input file is guaranteed to be correct. Your program does not have to check the format.
Also, your program must work with any file name of the correct format.
(Do not hard code the file name.)

Once this file has been opened, the program checks if this file is empty (you may assume that the user always enters a valid file name). If the file is empty the program displays
an appropriate message to the screen and closes, without using System.exit( ). This is the same as Task 1.
If the file is not empty, then the user is prompted (asked) to enter a Country.

The program then displays to the screen all the details of Airports from this country (the complete record). This time you must read the entire file as there may be more than one Airport in the file for the user entered Country.

User input is case insensitive, that is Bahamas and bAHamaS should produce the same result.

If the entire file has been searched and no matches have been found, then an appropriate message is displayed to the screen.

As in Task 1, the output must be on one line, even though it might be shown on more than one line in this document. Equally, a file that exists, but is empty, must have an appropriate message displayed.

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 Task2
Enter file name >> a.dat
Enter country >> Bahamas

Code = ATC Country = Bahamas
City = Arthur's Town State = Cat Island
Airport = Arthur's Town Airport

Code = CCZ Country = Bahamas City = Chub Cay
State = Berry Islands
Airport = Chub Cay International Airport

> java Task2
Enter file name >> a.dat
Enter country >> OOF Land
No Country was found with the name OOF Land

> java Task2
Enter file name >> x.dat
"x.dat" is an empty file, program closing

Task 3 - Task3.java

Write a Java program called Task3.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 (lines).

Each record has the same format as Task 1

The input file may have 0 to any number of records. The format of the input file is guaranteed to be correct. Your program does not have to check the format.

Also, your program must work with any file name of the correct format.
(Do not hard code the file name.)

Once this file has been opened, the program checks if this file is empty (you may assume that the user always enters a valid file name). If the file is empty the program displays
an appropriate message to the screen and closes, without using System.exit( ). This is the same as Task 1.
If the file is not empty, there is no further user input in this Task3.

The program then displays to the screen all the details of all Airports that have no State. That is the State String is an empty String, it just has the opening ')' immediately followed by the closing ')'. Read the top of page 4 again for the output (display) of empty State Strings.

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 Task3
Enter file name >> a.dat

Code = AFS
Country = Uzbekistan City = Zarafshan
State = No State Listed Airport = Zarafshan Airport

Code = AQB
Country = Guatemala City = Quiche
State = No State Listed Airport = Quiche Airport

Code = IXM Country = India City = Tamil Nadu
State = No State Listed Airport = Madurai Airport

Code = JHB
Country = Malaysia City = Johor Bahru

State = No State Listed
Airport = Senai International Airport

Code = CHN
Country = South Korea City = Jeonju
State = No State Listed Airport = Jeonju Airport

> java Task3
Enter file name >> x.dat
"x.dat" is an empty file, program closing

Task 4 - Task4.java

Write a Java program called Task4.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 (lines).

The records (lines) in this text file are different to the lines in Tasks 1 - 3
This time, each line is the record of an airline code, the name of the airline and the airport code that is the code for the airport that the airline is based at.

The format of the file is

Airline code(Airline name(Airport code

where:

Airline code is the code for the Airline. This code is unique and is always text
The Airline code is followed by a '(' character, there are no spaces before or after the '('.

Airline name is the name of the Airline. This is always text and can be any number of words (1 or more)
The Airline name is followed by a '(' character, there are no spaces before or after
the '('.

The Airport code is the same Airport code that we have been using in Tasks 1 - 3

The Airport code is always text. As it is the end of the String, there is nothing after the Airport code except the end of line (newline) marker.

Some example lines of this file

SND(Air Samarkand(AFS
FEA(Far Eastern Air Transport(RMQ IIC(Inter Island Air Charter(CCZ

The input file may have 0 to any number of records. The format of the input file is guaranteed to be correct. Your program does not have to check the format.

Also, your program must work with any file name of the correct format.
(Do not hard code the file name.)

Once this file has been opened, the program checks if this file is empty (you may assume that the user always enters a valid file name). If the file is empty the program displays an appropriate message to the screen and closes, without using System.exit( ).

If the file is not empty, then the user is prompted (asked) to enter an Airline code. The program then reads the airline codes input file, until it finds the matching Airline code in the input. If the program finds a match for the Airline code then

all three parts of the line are saved in separate Strings. This is just breaking up the line as we have done in Tasks 1 to 3

If a matching Airline code is not found, then an appropriate message is displayed to the screen and the program closes.

Regardless of match or not, remember to close the airline codes file. Now we open the Airports code file, just as we done in Tasks 1 - 3 Each record has the same format as Task 1
The same conditions apply to an empty input file as in Tasks 1 - 3

If the Airport codes file is not empty, then the program searches through the Airport codes input file, using the Airport code String from the Airlines code input file as the search key.

If a match for the Airport code is found, then the details of both the Airline codes and the Airport codes record is displayed to the screen. The format is shown below in the example runs.

If no match is found for the Airport code, an appropriate message is displayed to the screen.

Note the output format in the examples below
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 Task4
Enter Airlines input file name >> b.dat
Enter the airline code >> PNP
Please enter the airport codes input file >> a.dat Airline: Pineapple Air IATA code: PNP is based at Chub Cay International Airport (CCZ) in Bahamas

> java Task4
Enter Airlines input file name >> b.dat
Enter the airline code >> AFL
Please enter the airport codes input file >> a.dat
No airport with the code SVO was found

> java Task4
Enter Airlines input file name >> b.dat
Enter the airline code >> ABC
No airline with the code ABC was found Program closing

> java Task4
Enter Airlines input file name >> x.dat
"x.dat" is an empty file, program closing

> java Task4

Enter Airlines input file name >> b.dat
Enter the airline code >> QFA
Please enter the airport codes input file >> x.dat The airport codes input file x.dat is an empty file Program closing

Attachment:- Java Assignment.rar

Reference no: EM132356888

Questions Cloud

How the scientific method is being used to solve the problem : Identify a current problem in physics by searching for news articles and current events. One reputable source of news in physics is Phys.org.
What are blind spots : What are blind spots? How are they created? What steps can leadership take to avoid/resolve them?
Briefly summarise why data mining is used in business : Title: Data Mining in Business. Recommended word length for this posting is 500 words. Briefly summarise why data mining is used in business
Analyze the major curriculum designs : Analyze the major curriculum designs (e.g., subject-centered designs, learner-centered designs, and problem-centered design) discussed in the textbook.
Practise reading from and writing to the console : CSE1OOF - Object-Oriented Programming Fundamentals - La Trobe University - Write a Java program firstly, prompts the user to enter an input file name
Evaluate the legal framework of the organization : Evaluate the legal framework of the organization of public and private education. Recognize and discuss political factors affecting the educational system.
Evaluate degree to which learning influenced by psychology : Evaluate the degree to which learning is influenced by psychology, growth, and development as well as learning in and out of formal settings.
What is the difference between creativity and innovation : What is the difference between creativity and innovation? Provide APA reference.
Business innovators include internal locus of control : Some of the characteristics attributed to business innovators include internal locus of control

Reviews

len2356888

8/13/2019 12:21:18 AM

You are free to solve the Tasks below in any way, with one exception and one condition. Any assignment that uses code that is outside what has been presented to this point must be fully explained at the marking execution test. Not being able to fully explain code outside what has been presented in the subject so far will result in the assignment being awarded a mark of 0, regardless of the correctness of the program. Submitting an assignment with code outside what has been presented so far and not attending the marking execution test will result in an automatic mark of 0, regardless of the correctness of the submission. An example would be the split( ) method in the String class. The reason being that this method returns an array and we haven't studied arrays yet. So using the split( ) method would require you to be prepared to explain to the marker how arrays worked in Java, plus anything else that maybe involved in getting split( ) to compile and run.

len2356888

8/13/2019 12:21:05 AM

Submission Details: Full instructions on how to submit electronic copies of your source code files from your latcs8 account are given at the end. If you have not been able to complete a program that compiles and executes containing all functionality, then you should submit a program that compiles and executes with as much functionality as you have completed. (You may comment out code that does not compile.) Note you must submit electronic copies of your source code files using the submit command on latcs8. Ensure you submit all required files, one file at a time. Please also note carefully that whilst we encourage innovation and exploring Java beyond what has been presented in the subject to date, above all, we encourage understanding. All of the Tasks that follow can be solved using techniques that have been presented in lectures, lecture / workshops and labs so far. These are the techniques and knowledge that will later be examined later in the Real Time Test (20%) and the exam (50%).

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd