Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is my code. I am totally stumped. help /* * To change this license header, choose License Headers in Project Properties. * To change

here is my code. I am totally stumped. help

/*

* 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_3;

import java.util.Scanner;

/**

*

* @author j0nny

*/

public class PRG215_Week_3 {

@SuppressWarnings({"empty-statement", "UnusedAssignment"})

public static void main(String[] args) {

//Create eh items names and item costs arraus

String[] itemNames = {"Tennis Shoes", "Shirts", "Coats", "Belts", "Pants"};

double[] itemCosts = {45.89, 25.55, 89.99, 15.00, 25.99};

//variables to for the financial calculations

double totalAmount = 0.0;

double taxRate = 0.081;

//Discounts for large purchases

double discountRate = 0.025; //2.5%

double amountToQualifyForDiscount = 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 < itemNames.length; i++)

{

//Display each item in the array

System.out.println(" " + (i + 1) + "." + itemNames[i] + "for$" + itemCost[i] + "each");

}

System.out.println("");

//Create a keyboard input object

Scanner keyboard = new Scanner(system.in);

//Display on the console - ask for the customer's name

System.out.print("Please enter your name:");

//Get the customer name from the keyboard and store it in the String object "customerName"

String customerName = keyboard.next();

System.out.println("");

//Display the customer's name and provide instructions

System.out.println("Ok," + customerName + ", please enter the product ID (the number to the left of the item name that you wish to purchase. Enter 0 when you are finished.");

//Loop until the user enters 0

@SuppressWarnings("UnusedAssignment")

int itemID; //Set the condition to 0

itemID = 0;

int itemCounter = 1; //No longer the loop condition counter, now used for display do // We're using a different type of loop structure now

{

//Prompt the user

System.out.print("Plese enter item ID number " + (itemCounter) + "(enter 0 to exit.):");

itemID = keyboard.nextInt();

//If the user has not entered 0, then add to the total

if(itemID > 0)

{

//Add to the total

totalAmount = totalAmount + itemCosts[itemID + 1];

//Increment the item display counter

itemCounter ++;

}

}

while(itemID != 0); //Check if exit condition has been met

//The loop is complete, calculate the discount and taxes and then display the results

if(totalAmount >= amountToQualifyForDiscount)

{

disountAmount = totalAmount * discountRate;

}

else

{

discountAmount = 0;

}

//Calculate the taxes

double taxAmount = (totalAmount - discountAmount) * taxRate;

//Display the results

System.out.println("");

System.out.println("You selected" + itemCounter + "items to purchase.");

System.out.println("Your sales total $" + totalAmount);

System.out.println("Your discount amount is $" + discountAmount);

System.out.println("Your sales tax is $" + taxAmount);

System.out.println("The total amount due is $" + (totalAmount - discountAmount + taxAmount));

System.out.println("");

}

}

here is the error message

run: The following clothing items are available for purchase. Exception in thread "main" java.lang.NullPointerException at week_3.PRG215_Week_3.main(PRG215_Week_3.java:42) C:\Users\j0nny\AppData\Local\NetBeans\Cache\11.1\executor-snippets un.xml:111: The following error occurred while executing this line: C:\Users\j0nny\AppData\Local\NetBeans\Cache\11.1\executor-snippets un.xml:94: Java returned: 1 BUILD FAILED (total time: 0 seconds)

I am lost

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions