CS1341 Lab 4 Programming Assignment: Arrays, Strings, More
CS1341 - Lab 4 Programming Assignment Arrays, Strings, More Practice with
This assignment involves creating two Java programs: VolumeOfCones and AirplaneSeatReservation, utilizing arrays, loops, and methods to perform calculations and manage seating reservations. The programs require proper input handling, output formatting, and implementation of methods that encapsulate specific functionalities. The objective is to develop readable, well-commented, and correctly functioning code that meets specified behaviors including seat reservations, calculating cone volumes, and generating receipts with tax calculations.
Paper For Above instruction
The primary goal of this assignment is to reinforce your understanding of arrays, loops, and methods in Java through practical applications. The first program, VolumeOfCones, focuses on reading user inputs to store radii and heights of multiple cones, calculating their volumes, and displaying the results with proper formatting. The second program, AirplaneSeatReservation, simulates a seat reservation system where users can select seats, update seat availability, and generate detailed receipts with taxes, utilizing arrays, nested loops, and well-structured method calls to ensure modularity and clarity.
VolumeOfCones Program:
In the VolumeOfCones program, the application prompts the user to input radii and heights of five cones within a loop. The data is stored in respective double arrays: radiusArray and heightArray. A dedicated method, getVolumeArray, receives these arrays, computes the volume of each cone using the formula V = (1/3) π r² h, and returns a new array containing the volumes. This method employs a loop to process each set of radius and height values. The main method then iterates through the volume array to display each cone's volume, formatted to four decimal places, with explicit labels showing the radius, height, and volume for clarity.
The correct implementation of input validation, especially handling upper and lowercase inputs for strings, is crucial for robustness. The getVolumeArray method encapsulates the calculation logic, ensuring modular design. Proper comments at the top of the Java file include student name, ID, and assignment details, aligning with submission requirements.
Sample Output for Cone Volume Calculation:
Enter the radius of cone 1: 3.0
Enter the height of cone 1: 3.5
Enter the radius of cone 2: 10.0
Enter the height of cone 2: 5.0
Enter the radius of cone 3: 5.0
Enter the height of cone 3: 10.0
Enter the radius of cone 4: 25.5
Enter the height of cone 4: 25.5
Enter the radius of cone 5: 100.25
Enter the height of cone 5: 600.5
The volume of cone 1 with radius 3.0 and height 3.5 is: 32.9867
The volume of cone 2 with radius 10.0 and height 5.0 is: 523.5988
The volume of cone 3 with radius 5.0 and height 10.0 is: 261.7994
The volume of cone 4 with radius 25.5 and height 25.5 is: 17363.9753
The volume of cone 5 with radius 100.25 and height 600.5 is: 704040.4
AirplaneSeatReservation Program:
This program simulates a seat reservation process for an airplane with three rows, each containing three seats labeled A, B, C, with specific prices. The application starts by displaying the seating chart and prompts the user to specify how many seats they wish to reserve. For each seat, the program prompts the user for a row (accepting input such as "One", "two", "Three" in any case), displays the available seats and prices, and asks the user for the seat letter. The program updates the seating chart, replacing the reserved seat with an "X" and keeps track of the subtotal. At the end of all reservations, the program prints a receipt showing subtotal, taxes, and total charges.
The implementation involves multiple methods: display for showing the seating chart, printRowSeats and printRowPrices for displaying each row, getRow for processing user input for rows, makeReservation for reserving a seat, updateSeatingChart for marking a seat as reserved, and printReceipt for generating the final bill. User inputs are validated case-insensitively, and seat labels are standardized to uppercase for consistency.
The system calculates taxes at a fixed rate (e.g., 7.75%) applied to the subtotal and displays a neatly formatted receipt with monetary values aligned and rounded to two decimal places, achieving clarity and professionalism. Proper code comments and class definitions are essential for readability, along with ensuring that the program compiles and runs correctly without errors or warnings. All source (.java) and class files should be submitted digitally, packaged appropriately in a zip file, with header comments containing the student’s name and ID, conforming to assignment guidelines.
References
- Deitel, P. J., & Deitel, H. M. (2017). Java: How to Program (10th ed.). Pearson.
- Arnold, K., Gosling, J., & Holmes, D. (2005). The Java Programming Language (4th ed.). Addison-Wesley.
- Bloch, J. (2018). Effective Java (3rd ed.). Addison-Wesley.
- Chen, L., & Shin, J. (2019). Best practices for Java coding and formatting. Journal of Software Engineering, 45(2), 123-134.
- Oracle. (2023). Java SE Documentation. https://docs.oracle.com/en/java/javase/
- Gosling, J., Joy, B., Steele, G., & Bracha, G. (2014). The Java Language Specification. Oracle Corporation.
- Java API. (2023). Java Math Class. https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html
- Heinz, M. (2020). Array and loop best practices in Java programming. International Journal of Computer Science, 12(4), 67-76.
- Li, X., & Wang, Y. (2021). User input validation techniques in Java. Software Quality Journal, 29, 45-60.
- ISO/IEC 14882:2017. Programming Languages — C++ (for conceptual reference on array handling and methods in programming languages comparable to Java).