Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Project Three, Truck Loading Use the sample files, fleet.txt and loading.txt to test your program. To download these files: Right Click on the fleet.txt

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Programming Project Three, Truck Loading

Use the sample files, fleet.txt and loading.txt to test your program. To download these files:

  1. Right Click on the fleet.txt file name.
  2. Click on the "Save Link As..." choice.
  3. Save the fleet.txt file to your computer.
  4. Repeat steps 1, 2, and 3 for the loading.txt file.

Your instructor will execute the program you submit using files named fleet.txt and loading.txt that contain different values than these sample files.

You can either:

  • Write your program so that it assumes both files are located in the C:/Data/ folder, OR
  • Use JFileChooser in your program to allow your instructor to locate the files.

-------------------------------

fleet.txt

12345,ABC-123,7500 56789,ABX-234,7800 24680,BGT-674,80000 13579,FDU-776,6500 22457,BDA-122,7500 31986,TTY-986,4800

loading.txt

A,12345,1013,Toilet paper,10.5,29.97 A,12345,1008,Motor oil,40.5,45.25 A,12345,4567,Machine parts,2000,6789.45 A,56789,9876,Autobile tire set,90,598.75 A,56789,8432,Pickup truck tire set,140,699.89 A,23456,1234,Lag Screws,250,187.49 A,31986,4532,Iron ingots,4800,2786.54 A,31986,5321,Straw,1,12.35 A,24680,6741,Cotton bales,70000,8272.79 R,23456,1234 A,12345,1992,Routers and switches,4275,72745 R,12345,1234 A,22457,7152,Red Solo Cups,0,12345 X,12345,1013 A,22457,9826,Plexiglass sheets,150,0 R,12345,1013 A,22457,8529,Airplane parts,6600,134512 R,12345,1008 A,22457,7643,100 watt LED lightbulbs,0,0 R,12345,1234 A,24680,7295,Barbed Wire,8000,450.25 R,12345,4567 R,54872,4532 R,56789,7854 A,13579,6632,Christmas Trees,4800,2756.42 R,56789,9876
Project Three, Truck Loading . This Programming Project allows you to demonstrate your basic knowledge of Object-Oriented Programming and the use of text files for input and output. Your Java program will simulate loading trucks with various items. You will define and use two classes. The first class will be called Truck. This class will simulate the carrying capacity and contents of a truck. The second class will be called Ilem. The Iler class will be used to simulate the items carried in each truck. You will use information read from two text files. The first file contains the information you will need to create instances of the class named Truck. The second text file contains the information you will need to create instances of the Tton class and load them into the previously created Truck objects. Your program will then use the information in the collection of Truck objects you created and updated to prepare a report written to an output file. The file will summarize the contents and value of each truck in the form of a report. Start by designing a class called Truck. This class contains the following private fields: id_number, unique numeric identification number for each truck. plate, text description of the truck's license plate. contents, collection of Item objects in the truck. capacity, maximum carrying capacity for each truck (in pounds). The Truck class has the following methods: A constructor that can be used to create an instance of the Truck class. The id_number, plale, and capacity fields must be specified as arguments. This method will define the initial value of the contents field as an empty collection, such as an ArrayList. An add tem method that accepts as an argument an Item object. Adding this item to the contents of the truck must not exceed the maximum weight limit of that truck. If adding an item would potentially exceed the weight limit, display a warning, and do not add the item to the truck's contents field. A removeItem method that accepts an ske number as a parameter and attempts to remove the associated Item object from the contents of a truck. If the truck does not contain an item with the sku number, display a warning message, and make no change to the contents. AgetContents method that returns a reference to the contents field. . . . . . . A get-aNnumber method that returns the value of the truck's id number. A getPlate method that returns the value of the truck's o ate. A getCapacity method that returns the value of the truck's capacity. Agot-otal weight method that returns the total weight of all the item objects in the contents collection. Agetrotalvalue method that returns the total dollar value of all the items contained in the truck expressed as dollars and cents. The Ttem class contains the following private fields: sku, the stock keeping unit number for this item. description, the text description of the item. weight, the weight, in pounds, as a floating-point value (double). value, the value of this item in dollars and cents. The Iter class has the following methods: A constructor that can be used to create an instance of the Iter class. All the fields in the class must be specified as arguments. This method will guard against the values of weight and value having a numeric value that is less than or equal to zero. If one or more of the weight or value numeric values is less than or equal to zero, display a warning message and set the offending field value to zero. A golsku method that returns the value of the stock keeping unit number. A getDescription method that returns the value of the item's description. Agel Weight method that returns the weight of the item in pounds. A getValue method that returns the value of the item in dollars and cents. . . Place the class definition for the Truck class in a separate file named "Truck.java". In similar fashion, place the class definition for the Item class in a separate file named "I lem.java". Your Java program will read and process two input files and create a single output file in addition to limited console output. Your program will read the contents of a file named "fleet.txt" and use the contents of this file to initially create and define the empty Truck objects. The "fleet.txt" text file contains the definitions of the Truck objects to be created. Each record in this file holds the following information in this order: 1. ID number 2. plate 3. capacity (in pounds) The fields in this file are comma-delimited. That is, each field is separated from the next field by a comma. Example records for this file look like this: 12345, ABC-123,7500 56789, ABX-234,7800 24680, BGT-674,80000 13579, FDU-776,6500 Consider reading each line of the file as a single string variable. Then use the split method to create an array of strings. Afterwards, strings that need to be converted to numeric values can be converted. After creating instances of the Truck class, display a line reporting how many trucks were created. Your program will then read and process a file named "loading.txt". The "loading.txt" text file contains transactions that will potentially change the contents of individual trucks. These are the transaction codes used for the possible truck loading and unloading activities: "A" Add an Item object to a truck (Creates an Item object). M" Remove an item object (identified by sku) from a truck. There are two types of records within the "loading.txt" text file. To add an item to a truck, the definition of the Item object must be part of the record. Records intended to add an item to a truck contain the following comma- separated fields: 1. Transaction code ("A") 2. Truck ID number 3. Item sku number 4. Item description 5. Item Weight (in pounds) 6. Item value in dollars and cents) Example records intended to add an item to a truck look like this: A, 12345, 1013, Toilet paper, 10.5,29.97 A, 12345,1008, Molor oil,40.5,45.25 1,12345,4567, Machine parts, 2400,6789.45 1,56789,987, Autobile tire set, 90,598,75 A,56789, 9432, Pickup truck tire set, 140, 699.89 The second type of record that is contained in the "loading. Lxl" file is intended to remove an item from a truck. These records need only refer to the truck ID number and the item's sku number. Records intended to remove an item from a truck contain the following comma-separated fields: 1. Transaction code ("R") 2. Truck ID number 3. Item sku number Example records intended to remove an item from a truck look like this: R, 12345,1013 R, 12345,1008 R, 12345, 4567 R, 56789,7854 R, 56789,987 The "oadirg.txt" file will contain both types of records. Process only records in the file that contain a transaction code of "A" or "R". Skip records that do not contain either of these valid transaction codes. Keep track of the total number of records skipped. Process only records in the "loading.txt" file that refer to trucks and items you defined earlier the "fleet.txt" file and the "loading t" file). For example, if a record in the" loading.txt" file refers to a truck that your program did not create, skip that record, and increment the count of skipped records. Likewise, if a record in the "loading.txt" file refers to an item's sku number that is not contained in the specified truck, skip that record, and increment the count of skipped records. Keep track of the total number of records processed as well as the total number of records that were skipped for any reason. After processing the entries in the "loading.txt" file your program can now display two items on the console (screen) using print statements. You will know and can display the total number of transaction records processed as well as the total number of records skipped. The final step in this programming project is to calculate, display, and summarize the loading of the trucks. This information will be written to an output text file named "Report.txt". The first line of your inventory report will contain your full name and a made-up name for the company such as "The Albatross Shipping Company, Ltd." The second line in your inventory report will contain the phrase, "Prepared on:" followed by the current date and time. (This is the one and only thing I want you to look up on the Internet.) The third line will be blank. The fourth line in your report is where the heading information begins. Efficiency is a truck's total load divided by the capacity expressed as a percentage. Your loading report will look as much like this as possible: Joe E. Bagadonutz for the Albatross Shipping Company, Ltd. Prepared On: Monday, Ju-y 27, 2020 at 05:36:15 Truck ID Number License Plate LOADING REPORT Actual Capacity Load Efficiency Value 12345 56789 24680 13579 ABC-23 ABC-234 BGT-674 FDU-776 7,500 7,800 80,000 6,500 6, 200 5,600 45,020 5,400 82.73 71.83 56.33 83.13 $4,311.00 $2,878.89 $21,456.87 $1,897.43 Total 62,220 $30,547.19 Once the loading report is complete, display the overall total weight loaded into all the trucks as well as the dollar worth of all items loaded into all trucks on the screen. Summary of expected screen display messages: NN Trucks have been creatco. XXX Total loading records processed. YY records skipped. Total load carried for a trucks is zz, zzz.zz pounds. Total value for all items in all trucks is $DD, DDD, DD Your program will substitute the number of Truck objects created for NN. The total number of loading records processed will be used in place of xxx. The number of records skipped for any reason will be shown in place of yy. The total weight of all items carried by all trucks will be displayed in place of zz, zzz.zz. The total dollar value of all items carried by all trucks will be shown in place of DD, DDD.DD. For this assignment you will create and submit three (3) files. The first file will be named "Truck.java" and contain the class definition for the Cruck class. The second file will be named "Item.txt" and contain the class definition for the tem class. The third file is the program you wrote to solve this problem. The third file will be named "XY ProjectThree.java", where "X" and "Y" are your first and last initials. For example, a student named Robert Wilberforce will name the file he submits "RWProjectThree.java". Your assignment will be graded by your instructor using different files than the sample data files provided. Your instructor may run their own program to evaluate how well you designed both the Truck class and the tem class. The instructor's program will exercise all the required methods in both the Truck class and the Item class. To receive full credit for this programming assignment, you must: Submit three separate files: o One named "XYProjectThree.java", where "X" and "Y" are your first and last initials, and a second file named "Truck.java", which contains the class definition for the Cruck class, and a third file named "Item.java", which contains the class definition for the tem class. Submit a program that executes correctly. 0 0 . . Grading Guideline: Create a comment containing the student's full name. (5 points) Correctly define all the private fields in the Truck class. (5 points) Correctly define the constructor method for the Truck class. (5 points) Correctly define all the methods in the Truck class. (5 points) Correctly define all the private fields in the Ilem class. (5 points) Correctly define the constructor method for the Ilom class. (5 points) Correctly define all the methods in the item class. (5 points) Create Truck objects by correctly processing the "fleet.txt" file (10 points) Create Item objects and correctly add them to the appropriate trucks by processing the "loadirg.txt" file. (10 points) Correctly report the number of trucks created on the screen. (5 points) Correctly report the total number of records processed in the "loading. LxL" file. (5 points) Correctly report the number of records that were skipped while processing the "loading. xL" file. (5 points) Create the "Report.lx" file with correct title and date and time. (10 points) Calculate and display the total weight and dollar value of all the items in all the trucks. (10 points) Calculate and include the total weight and dollar value of all the items in all the trucks in the report file. (10 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago