Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
What is wrong with this code and how do I fix it.
What is wrong with this code and how do I fix it. I have also included the customer exception file and the itemsForSale exceptions file
MAIN PROGRAM
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package week_1;
import java.util.Scanner;
/**
*
* @author DAM
*/
public class PRG215_Week_1 {
public static void main(String[] args) {
//Constant for the total number of items for sale
final int TOTAL_ITEMS = 6;
//Create the items object arrays
ItemsForSale[]items=new ItemsForSale[TOTAL_ITEMS];
//Loop an instantiate each object - you must always create the individual object
for(int i=0; i<TOTAL_ITEMS;i++)
{
items[i] = new ItemsForSale();
}
//Use the PopulateItem method from the ItemsForSale class to inser the properties of each item object for sale
items[0].PopulateItem("Tennis Shoes", 45.89,true);
items[1].PopulateItem("Shirts", 25.55, true);
items[2].PopulateItem("Coats", 89.99, true);
items[3].PopulateItem("Belts", 15, true);
items[4].PopulateItem("Pants", 25.99, true);
items[5].PopulateItem("Donation", 10, false);
//variables to for the financial calculations
double totalAmount = 0.0;
double totalTax = 0.0;
double taxRate = 0.081;
//Discounts for large purchases
final double DISCOUNT_RATE = 0.025; //2.5%
final double AMOUNT_TO_QUALIFY_FOR_DISCOUNT = 100;
double discountAmount = 0;
//Display items for sale on the console
System.out.println("The following clothing items are available for purchase:");
for(int i=0;i<items.length;i++)
{
//Display each item in the array
System.out.println(" "+(i+1)+"."+items[i].itemName+ "for $"+items[i].itemCost+"each");
}
System.out.println("");
//Create keyboard input object
Scanner Keyboard = new Scanner(System.in);
//Create new customer object
Customer newCust = new Customer();
//Get the customer last name from the keyboard and store it in the new Cust object's.firstName property
newCust.firstName=keyboard.next();
//Display on the console - ask for the customer's last name
System.out.print("Please enter your last name: ");
//Get the customer last name from the keyboard and store it in the newCust object's.lastName property
newCust.lastName =keyboard.next();
System.out.println("");
//Display the csutomer's full name (a method in the customer class) and provide instructions
System.out.println("Ok,"+newCust.FullName()+",Please enter the product ID (the numberto the left of the item "
+ "name) that you wish to purchase. Enter 0 when you are finished.");
//Loop until the user enters 0
int itemID = 0;//Set the condition to 0
int itemCounter = 1; //No longer the loop condition counter, now used for display
do
{
//Prompt the user
System.out.print("Please enter item ID number"+(itemCounter)+":");
//Wrap input in a TRY/CATCH block to capture any user data entry exceptions
try
{
itemID=keyboard.nextInt();
//Test the user did not enter the exit condition
if(itemID>0)
{
totalAmount=totalAmount+items[itemID-1].itemCost;
//Moved tax calculation to hear since we might not charge tax on a ll items
if(items[itemID-1].taxable==true)
{
totalTax=totalTax+(items[itemID-1].itemCost*taxRate);
}
//Increment the item display counter
itemCounter++;
}
}
//User entered a number outside the size of the array
}
}
private static class Customer {
public Customer() {
}
}
}
CUSTOMER FILE
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DAM
*/
public class Customer extends Exception {
public String firstName;
public String lastName;
public String FullName()
{
return this.firstName+""+this.lastName;
}
/**
* Creates a new instance of <code>Customer</code> without detail message.
*/
public Customer() {
}
/**
* Constructs an instance of <code>Customer</code> with the specified detail
* message.
*
* @param msg the detail message.
*/
public Customer(String msg) {
super(msg);
}
}
ITEMS FOR SALE FILE
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package week_1;
/**
*
* @author DAM
*/
public class ItemsForSale extends Exception {
public String itemName;
public String itemCost;
public boolean taxable;
public void PopulateItem(String iName, double iCost, boolean canTax)
{
this.itemName=iName;
this.itemCost=iCost;
this.taxable=canTax;
}
/**
* Creates a new instance of <code>ItemsForSale</code> without detail
* message.
*/
public ItemsForSale() {
}
/**
* Constructs an instance of <code>ItemsForSale</code> with the specified
* detail message.
*
* @param msg the detail message.
*/
public ItemsForSale(String msg) {
super(msg);
}
}