Java Programming Exercise 9-7 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. Add get methods for the invoice number and sale amount fields so their values can be used in comparisons. Next, write a program that declares an array of five Purchase objects and prompt a user for their values. Then, in a loop that continues until a user inputs a sentinel value of Z, ask the user whether the Purchase objects should be sorted and displayed in invoice number order or sale amount order. Do not use numbers for accepting options from user. Use below characters Mandatory Sorting Oder Options: I - Invoice Sorting S - Sale Amount Z - Exit
Please find the code below:::
Purchase.java
package classes1;
public class Purchase {
private int invoiceNumber;
private double amountOfSale;
private double amountOfSaleTax;
public Purchase() {
super();
this.invoiceNumber = 0;
this.amountOfSale = 0;
this.amountOfSaleTax = 0;
}
public Purchase(int invoiceNumber, double
amountOfSale, double amountOfSaleTax) {
super();
this.invoiceNumber =
invoiceNumber;
this.amountOfSale =
amountOfSale;
this.amountOfSaleTax =
amountOfSaleTax;
}
public int getInvoiceNumber() {
return invoiceNumber;
}
public void setInvoiceNumber(int invoiceNumber)
{
this.invoiceNumber =
invoiceNumber;
}
public double getAmountOfSale() {
return amountOfSale;
}
public void setAmountOfSale(double amountOfSale)
{
this.amountOfSale =
amountOfSale;
}
public double getAmountOfSaleTax() {
return amountOfSaleTax;
}
public void setAmountOfSaleTax(double amountOfSaleTax)
{
this.amountOfSaleTax =
amountOfSaleTax;
}
}
PurchaseTest.java
package classes1;
import java.util.Scanner;
public class PurchaseTest {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
Scanner scChoice = new
Scanner(System.in);
String choice = "";
System.out.println("Enter details
of five purchase product");
Purchase items[] = new
Purchase[5];
for(int i=0;i<5;i++){
System.out.println("Enter details for item # "+(i+1));
System.out.print("\tEnter invoice number : ");
items[i] = new
Purchase();
items[i].setInvoiceNumber(sc.nextInt());
System.out.print("\tEnter amount of sale : ");
items[i].setAmountOfSale(sc.nextDouble());
System.out.print("\tEnter amount of sale tax : ");
items[i].setAmountOfSaleTax(sc.nextDouble());
}
while(true){
System.out.println("Select an option");
System.out.println("I - Invoice Sorting");
System.out.println("S - Sale Amount ");
System.out.println("Z - Exit");
System.out.print("Enter your choice : ");
choice =
scChoice.nextLine();
if(choice.equalsIgnoreCase("I")){
for(int i=0;i<5;i++){
for(int
j=i+1;j<5;j++){
if(items[i].getInvoiceNumber()>items[j].getInvoiceNumber()){
Purchase temp = items[i];
items[i] = items[j];
items[j] = temp;
}
}
}
System.out.printf("%-20s%-20s%-20s\n","Invoice
Number","Sale Tax Amount","Sale Tax Amount Tax");
for(int i=0;i<5;i++){
System.out.printf("%-20s%-20s%-20s\n",items[i].getInvoiceNumber(),items[i].getAmountOfSale(),items[i].getAmountOfSaleTax());
}
}else
if(choice.equalsIgnoreCase("S")){
for(int i=0;i<5;i++){
for(int
j=i+1;j<5;j++){
if(items[i].getAmountOfSale()>items[j].getAmountOfSale()){
Purchase temp = items[i];
items[i] = items[j];
items[j] = temp;
}
}
}
System.out.printf("%-20s%-20s%-20s\n","Invoice
Number","Sale Tax Amount","Sale Tax Amount Tax");
for(int i=0;i<5;i++){
System.out.printf("%-20s%-20s%-20s\n",items[i].getInvoiceNumber(),items[i].getAmountOfSale(),items[i].getAmountOfSaleTax());
}
}else
if(choice.equalsIgnoreCase("Z")){
System.out.println("Bye Bye....");
break;
}else{
System.out.println("Please select an valid
option...");
}
}
}
}
output:
Java Programming Exercise 9-7 In the exercises in Chapter 6, you created a class named Purchase....
Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...
Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due Friday, February 9th, 2017 @ 11:59PM EST Directions Create a List object. Using the following definition (List.h file is also in the repository for your convenience) for a list, implement the member functions (methods) for the List class and store the implementation in a file called List.cpp. Use an array to implement the list. Write the client code (the main method and other non-class...
Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...
Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...
Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...
CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...