Concept explainers
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 set method that takes the invoice number
public void setInvoiceNumber(int num)
{
//Assign the value
invoiceNumber = num;
}
//Define a set method that takes the amount of sale
public void setSaleAmount(double amt)
{
//Assign the value
saleAmount = amt;
//Compute the sales tax
tax = saleAmount * RATE;
}
//Define a get method that returns the amount of sale
public double getSaleAmount()
{
//Return the value
return saleAmount;
}
//Define a get method that returns the invoice number
public int getInvoiceNumber()
{
//Return the value
return invoiceNumber;
}
/*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: “SortPurchasesArray.java”
//Import necessary header files
import java.util.Scanner;
//Define a class named SortPurchasesArray
public class SortPurchasesArray
{
//Define a main method
public static void main(String[] args)
{
//Declare an array of five Purchase objects
Purchase[] purchases = new Purchase[5];
//Declare the variables
int i;
String message;
char choice;
final char QUIT = 'Z';
int number;
double price;
//Create an object for Scanner class
Scanner keyboard = new Scanner(System.in);
//For loop to be executed until i exceeds 5
for(i = 0; i < purchases.length; ++i)
{
//Prompt the user to enter the invoice number
System.out.print("Enter invoice number >> ");
number = keyboard.nextInt();
//Prompt the user to enter the amount of sale
System.out.print("Enter sale amount >> ");
price = keyboard.nextDouble();
purchases[i] = new Purchase();
//Function call
purchases[i].setInvoiceNumber(number);
purchases[i].setSaleAmount(price);
}
keyboard.nextLine();
/*Prompt the user to enter whether the Purchase objects
should be sorted and displayed in invoice number
order or sale amount order*/
System.out.print("\nSort Purchases by (I)nvoice number, or (S)ale amount? ");
choice = keyboard.nextLine()...
Want to see the full answer?
Check out a sample textbook solution- I need to develop and run a program that prompts the user to enter a positive integer n, and then calculate the value of n factorial n! = multiplication of all integers between 1 and n, and print the value n! on the screen. This is for C*.arrow_forwardI need to develop and run a C* program to sum up integers from 1 to 100, and print out the sum value on the screen. Can someone help please?arrow_forwardGiven the schema below for the widgetshop, provide a schema diagram. Schema name Attributes Widget-schema Customer-schema (stocknum, manufacturer, description, weight, price, inventory) (custnum, name, address) Purchased-schema (custnum, stocknum, pdate) Requestedby-schema (stocknum, custnum) Newitem-schema (stocknum, manufacturer, description) Employee-schema (ssn, name, address, salary) You can remove the Newitem-schema (red).arrow_forward
- True or False: Given the sets F and G with F being an element of G, is it always ture that P(F) is an element of P(G)? (P(F) and P(G) mean power sets). Why?arrow_forwardCan you please simplify (the domain is not empty) ∃xF (x) → ¬∃x(F (x) ∨ ¬G(x)). Foarrow_forwardHistogramUse par(mfrow=c(2,2)) and output 4 plots with different argument settings.arrow_forward
- (use R language)Scatter plot(a). Run the R code example, and look at the help file for plot() function. Try different values for arguments:type, pch, lty, lwd, col(b). Use par(mfrow=c(3,2)) and output 6 plots with different argument settings.arrow_forward1. Draw flow charts for each of the following;a) A system that reads three numbers and prints the value of the largest number.b) A system reads an employee name (NAME), overtime hours worked (OVERTIME), hours absent(ABSENT) and determines the bonus payment (PAYMENT).arrow_forwardScenario You work for a small company that exports artisan chocolate. Although you measure your products in kilograms, you often get orders in both pounds and ounces. You have decided that rather than have to look up conversions all the time, you could use Python code to take inputs to make conversions between the different units of measurement. You will write three blocks of code. The first will convert kilograms to pounds and ounces. The second will convert pounds to kilograms and ounces. The third will convert ounces to kilograms and pounds. The conversions are as follows: 1 kilogram = 35.274 ounces 1 kilogram = 2.20462 pounds 1 pound = 0.453592 kilograms 1 pound = 16 ounces 1 ounce = 0.0283 kilograms 1 ounce = 0.0625 pounds For the purposes of this activity the template for a function has been provided. You have not yet covered functions in the course, but they are a way of reusing code. Like a Python script, a function can have zero or more parameters. In the code window you…arrow_forward
- make a screen capture showing the StegExpose resultsarrow_forwardWhich of the following is not one of the recommended criteria for strategic objectives? Multiple Choice a) realistic b) appropriate c) sustainable d) measurablearrow_forwardManagement innovations such as total quality, benchmarking, and business process reengineering always lead to sustainable competitive advantage because everyone else is doing them. a) True b) Falsearrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning