Question

Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt with good data and after
Submission Name yo Java source code file SalesReportArrayAppXXX.java, where XXX is your initials Submit your java file using
Specifications for Project 4 The logic for this project is similar to your last, so much of it will look familiar to you. How
. Use a separate for loop to display the property information This loop will look exactly like the previous-but this way all
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

import javax.swing.JOptionPane;
public class SalesReportArrayApp {

   public static void main(String[] args) {
       //declare variables, arrays, and constants
       int total = 0;
       int numProperties;
       int counter;
       String runAnother;
       String[] propertyAddress;
       int[] propertyPrice;
       final String HEADING1 = "MONTH_END SALES REPORT";
       final String HEADING2 = "Address\t\t\tPrice";
      
       //initialize outer loop
       runAnother = "Y";
       //test outer loop - loop while user chooses to enter another report
       while(runAnother.equalsIgnoreCase("Y"))
       {
           //reset total to zero each time through the loop
           total = 0;
           //ask user how many properties they want to enter
           numProperties = Integer.parseInt(JOptionPane.showInputDialog(null,"How many properties would you like to enter?","Input", JOptionPane.INFORMATION_MESSAGE));
           //validate numProperties is >= 1 and <= 10
           while(!(numProperties >= 1 && numProperties <= 10))
           {
               numProperties = Integer.parseInt(JOptionPane.showInputDialog(null,"** ERROR: Please enter a number between 1 and 10.\nHow many properties would you like to enter?",
                       "Input", JOptionPane.INFORMATION_MESSAGE));
           }
           //construct arrays based on numProperties input from user
           propertyAddress = new String[numProperties];
           propertyPrice = new int[numProperties];
           //display headings
           System.out.println(HEADING1);
           System.out.println("\n" + HEADING2 + "\n");
           //use a for loop (remember to INITIALIZE, TEST, ALTER)
           //to loop the number of times the user requested to get user input
           //populate the 2 arrays and calculate total
           for(int i = 0; i < numProperties; i++)
           {
               //get user input and populate the arrays
               propertyAddress[i] = (JOptionPane.showInputDialog(null,"Enter the address for Property " + (i+1) + ":","Input", JOptionPane.INFORMATION_MESSAGE));
               propertyPrice[i] = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the value of Property " + (i+1) + ":", JOptionPane.INFORMATION_MESSAGE));
               // validate propertyPrice is greater than zero
               while(propertyPrice[i] < 0)
                   propertyPrice[i] = Integer.parseInt(JOptionPane.showInputDialog(null,"ERROR: Please enter a number greater than 0.\nEnter the value of Property " + (i+1) + ":"
                           ,"Input", JOptionPane.INFORMATION_MESSAGE));
               // calculate total by adding on current propertyPrice
               total = total + propertyPrice[i];
           }
          
           // use a for loop to display all property information in the arrays
           for(int i = 0; i < numProperties; i++)
           {
               System.out.println(propertyAddress[i] + "\t\t" + propertyPrice[i]);
           }
           //display total
           System.out.println("\n\nTotal\t\t\t" + total);
           //alter outer loop- see if user wants to run another report
           runAnother = JOptionPane.showInputDialog(null,"Would you like to run another report? ","Input", JOptionPane.INFORMATION_MESSAGE);
           //validate runAnother
           while(!(runAnother.equalsIgnoreCase("y") || runAnother.equalsIgnoreCase("n")))
               runAnother = JOptionPane.showInputDialog(null,"ERROR: Please enter either \"Y\" or \"N\"\nWould you like to run another report? ",
                       "Input", JOptionPane.INFORMATION_MESSAGE);
       }
          
   }

}

Output:

Input How many properties would you like to enter? 5 OK CancelInput Enter the address for Property 1: 287 Acron St ¡ OK CancelInput Enter the value of Property 1: 150000 OK CancelInput Enter the address for Property 2: 12 Maple Ave OK CancelInput Enter the value of Property 2: 310000 OK CancelInput Enter the address for Property 3: B736 Marie Ln i OK CancelInput Enter the value of Property 3: 65500 OK CancelInput Enter the address for Property 4: 222 Acron S ¡ OK CancelInput Enter the address for Property 5: 29 Bahama Way ¡ OK CancelInput Enter the value of Property 5: 450000 OK CancelConsole X terminated> SalesReportArrayApp Java Application] C:1Program FilesJavaire1 MONTH END SALES REPORT Address Price 287

Program Screenshots:

1 import javax.swing.J0ptionPane; 2 public class SalesReportArrayApp 4 public static void main(String[] args) //declare varia//use a for loop (remember to INITIALIZE, TEST, ALTER) //to loop the number of times the user requested to get user input /po

Let me know if you have any concerns with the above solution.

Add a comment
Know the answer?
Add Answer to:
Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt...
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
  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • in java Write an application called Squaring that will: • Prompt the user to enter an...

    in java Write an application called Squaring that will: • Prompt the user to enter an integer greater than 1. Your code for this should be type-safe and validate the number, meaning that your code should re-prompt the user for another entry if they enter anything other than an integer that is greater than 1. • Repeatedly square the integer until it exceeds 1 million, outputting the value each time after squaring. • Output the number of squarings required to...

  • CIS 1111 Programming Files

    Description:In this assignment, you will write a program in C++ that uses files and nested loops to create a file for real estate agents home sales and then read the sales from the file and calculates the average sale for each agent. Each agent sold 4 homes.  Use a nested loop to write each agent’s sales to a file. Then read the data from the file in order to display the agent’s average sale and the average for all sales....

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Write a program that prompts the user to input daily rainfalls and display the total and...

    Write a program that prompts the user to input daily rainfalls and display the total and average rainfall. Use a sentinel controlled loop with sentinel value of -1.   Your output values should only have three digits after the decimal point. Test your program with following input data. 0.31 0.0 0.52 0.79 1.15 1.23 0.93 0.0 0.0 -1 The output of the program should be: The total rainfall is : 4.930 The average rainfall is : 0.547 Copy and paste your...

  • It's my python assignment. Thank you You wrote a program to prompt the user for hours...

    It's my python assignment. Thank you You wrote a program to prompt the user for hours and rate per hour to compute gross pay. Also your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Enter Hours: 45 Enter Rate: 10 Pay: 475.0 (475 = 40 * 10 + 5 * 15) Rewrite your pay program using try and except so that your program handles non-numeric input gracefully. Enter Hours: 20 Enter...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • need done in java An experiment was conducted and resulted in a series of pH measurements....

    need done in java An experiment was conducted and resulted in a series of pH measurements. The number of samples is known ahead of time. Have your program prompt the user to enter that number of measurements. Validate the number to ensure it's in the range of 2 to 100 measurements, inclusive. If it is out range, display an error message, Error: valid range is 2 to 100 If it's within the range, then use the number of measurements to...

  • The objective of this project is to provide experience working with user interface menus and programmed...

    The objective of this project is to provide experience working with user interface menus and programmed decision making. Modify the C++ source you created in Project # 2 to incorporate the following requirements: 1. Present a menu to the user which includes: a. Enter checking account transaction b. Enter savings account transaction c. Quit 2. If the user selects a., request the checking account balance, the checking account transaction date, the checking account description, and the checking account amount from...

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