Explanation of Solution
Program:
File name: “Purchase.java”
//Define a class named Purchase
public class Purchase
{
//Declare the private variables
private int invoiceNumber;
private double saleAmount;
private double tax;
private static final double RATE = 0.05;
//Define a method to set the invoice number
public void setInvoiceNumber(int num)
{
invoiceNumber = num;
}
//Define a method to set the amount of sale
public void setSaleAmount(double amt)
{
saleAmount = amt;
//Calculate the amount of sales tax
tax = saleAmount * RATE;
}
/*Define a method to display the invoice number,
amount of sale, and amount of sales tax*/
public void display()
{
//Print the result
System.out.println("Invoice #" + invoiceNumber +
" Amount of sale: $" + saleAmount + " Tax: $" + tax);
}
}
File name: “PurchaseArray.java”
//Import necessary header files
import java.util.*;
//Define a class named PurchaseArray
public class PurchaseArray
{
//Define a main method
public static void main(String[] args)
{
//Declare a purchases object
Purchase[] purchases = new Purchase[5];
//Declare the variables
int num;
double amount;
String entry;
//Create an object for Scanner class
Scanner input = new Scanner(System.in);
//Declare the variables and initialize the values
int x;
final int LOW = 1000, HIGH = 8000;
//For loop to be executed until x exceeds 5
for(x = 0; x < purchases.length; ++x)
{
purchases[x] = new Purchase();
//Prompt the user to enter an invoice number
System.out.print("Enter invoice number >> ");
num = input...
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
MindTapV2.0 for Farrell's Java Programming with 2021 Updates, 9th Edition [Instant Access], 1 term
- Travel Tickets Company sells tickets for airlines, tours, and other travel-related services. Because ticket agents frequently mistype long ticket numbers, Travel Tickets has asked you to write an application that indicates invalid ticket number entries. The class prompts a ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you drop the last digit of the number, then divide the number by 7, the remainder of the division will be identical to the last dropped digit. Accept the ticket number from the agent and verify whether it is a valid number. Test the application with the following ticket numbers: . 123454; the comparison should evaluate to true . 147103; the comparison should evaluate to true . 154123; the comparison should evaluate to false Save the program as TicketNumber.java.arrow_forwardIn C#, Write a program named CheckZips that is used by a package delivery service to check delivery areas. The program contains an array that holds the 10 zip codes of areas to which the company makes deliveries. (Note that this array is created for you and does not need to be changed.) Prompt a user to enter a zip code, and display a message indicating whether the zip code is in the company’s delivery area. For example if the user enters a zip code in the array, such as 60007, the output should be Delivery to 60007 ok. If the user enters a zip code not in the array, such as 60008, the output should be Sorry - no delivery to 60008.arrow_forwardIn C#, Make any necessary modifications to the RushJob class so that it can be sorted by job number. Modify the JobDemo3 application so the displayed orders have been sorted. Save the application as JobDemo4. An example of the program is shown below: Enter job number 22 Enter customer name Joe Enter description Powerwashing Enter estimated hours 4 Enter job number 6 Enter customer name Joey Enter description Painting Enter estimated hours 8 Enter job number 12 Enter customer name Joseph Enter description Carpet cleaning Enter estimated hours 5 Enter job number 9 Enter customer name Josefine Enter description Moving Enter estimated hours 12 Enter job number 21 Enter customer name Josefina Enter description Dog walking Enter estimated hours 2 Summary: RushJob 6 Joey Painting 8 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $510.00 RushJob 9 Josefine Moving 12 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $690.00 RushJob 12 Joseph Carpet cleaning 5…arrow_forward
- in C#, Make any necessary modifications to the RushJob class so that it can be sorted by job number. Modify the JobDemo3 application so the displayed orders have been sorted. Save the application as JobDemo4. An example of the program is shown below: Enter job number 22 Enter customer name Joe Enter description Powerwashing Enter estimated hours 4 Enter job number 6 Enter customer name Joey Enter description Painting Enter estimated hours 8 Enter job number 12 Enter customer name Joseph Enter description Carpet cleaning Enter estimated hours 5 Enter job number 9 Enter customer name Josefine Enter description Moving Enter estimated hours 12 Enter job number 21 Enter customer name Josefina Enter description Dog walking Enter estimated hours 2 Summary: RushJob 6 Joey Painting 8 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $510.00 RushJob 9 Josefine Moving 12 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $690.00 RushJob 12 Joseph Carpet cleaning 5…arrow_forwardThis class should contain a main method that initiates the program with the display of the following message: ‘Welcome to the Plane Management application’ at the start of the program. Implement the seat management system using standard arrays to keep track of the seats have been sold, and the seats that are still available. Use 0 to indicate that a seat is available, and 1 to indicate that a seat has been sold. At the start of the program all seats should be available (0). Task 2) Add a user menu in your main method that displays the following menu and asks the user to select an option. Option ‘0’ should terminate the program without crashing or giving an error. The rest of the options will be implemented in the next tasks.r selects an option (Lecture Variables and Control Structures) .Task 3) Create a method called buy_seat that asks the user to input a row letter and a seat number. Check that the row and seat entered are valid and that the seat is available (free). Record the seat…arrow_forwardThis is the question I am stuck on - In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Now, write a program that declares an array of five Purchase objects and prompt a user for their values. As each Purchase object is created, continuously prompt until the user enters an invoice number between 1000 and 8000 inclusive and a non-negative sale amount. Prompt the user for values for each object and then display all the values. This is the code that I am unsure where to fully start - public class Purchase { private int invoiceNumber; private double saleAmount; private double tax; private static final double RATE = 0.05; public void setInvoiceNumber(int num) { invoiceNumber = num; } public void setSaleAmount(double amt) { saleAmount = amt; tax = saleAmount * RATE; } public double getSaleAmount() { return…arrow_forward
- THIS IS JAVA PROGRAMMING When the user enters 4 at the menu prompt, your program will access all objects in the array to calculate and display only the largest number of coin denomination, and the total number of coins for the largest denomination. If there are more than one coin denominations having equal amount, you will need to list down all of them. After processing the output for menu option 4, the menu is re-displayed. For example: Customer: Jane 65 cent Change: 50 cent: 1 10 cent: 1 5 cent: 1 Customer: John 75 cent Change: 50 cent: 1 20 cent: 1 5 cent: 1 Menu option 4 should return as follows.arrow_forwardCreate a program named SalesTaxDemo that declares an array of 10 Sale objects. Prompt the user for data for each object and display the 10 objects. The program should accept input and display output in the same format as the sample program output below. Data fields for Sale objects include: InventoryNumber - An inventory number (as a string) amount - Amount of the sale (as a double) tax - Tax owed (as a double) Include a property with get and set accessors for the first two data fields, but make the tax owed a read-only property. The tax should be calculated whenever the amount of the sale is set. Assume that the tax rate is 8 percent for the first $100 and 6 percent for any amount greater than $100. In C#arrow_forwardCreate an application containing an array that stores eight integers. The application should call five methods that in turn (1) display all the integers, (2) display all the integers in reverse order , (3) display the sum of the integers, (4) display all values less than a limiting argument, and (5) display all values that are higher than the calculated average value.arrow_forward
- A registration officer in an academic institution wants to display the Student transcript in a given semester after entering the required student details. A student is characterized by an ID, full name, the semester in which he/she is registered and other details. The student can take from 3 to 4 modules every semester and has two assessments in each module. You are requested to write the program that will help the officer to display the indicated transcript using Classes, methods, arrays and various control statements. The following shows an example of execution of this program. Question What is the role of a normal constructor? Create the class Student, which must have a normal constructor and at least 5 attributes. Note: The attributes must include all the details mentioned in the scenario and others of your choice. The marks of the student in different modules must be stored using arrays. Explain the benefits of encapsulation in Object Oriented Programming. Include proper methods…arrow_forwardThe Spider Game Introduction: In this assignment you will be implementing a game that simulates a spider hunting for food using python. The game is played on a varying size grid board. The player controls a spider. The spider, being a fast creature, moves in the pattern that emulates a knight from the game of chess. There is also an ant that slowly moves across the board, taking steps of one square in one of the eight directions. The spider's goal is to eat the ant by entering the square it currently occupies, at which point another ant begins moving across the board from a random starting location. Game Definition: The above Figure illustrates the game. The yellow box shows the location of the spider. The green box is the current location of the ant. The blue boxes are the possible moves the spider could make. The red arrow shows the direction that the ant is moving - which, in this case, is the horizontal X-direction. When the ant is eaten, a new ant is randomly placed on one of the…arrow_forwardIn C# language using Microsoft Visual Studio in Windows Forms App (.NET Framework) A slot machine is a gambling device that the user inserts money into and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money, which the slot machine dispenses back to the user. Design a program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. Create an application that simulates a slot machine. The application should let the user enter into a TextBox the amount of money he or she is inserting into the machine. When the user clicks the Spin button, the application should display three randomly selected symbols. (Slot machines traditionally display fruit symbols.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,