Computing.Net > Forums > Programming > help with code

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

help with code

Reply to Message Icon

Name: jillsmith09
Date: May 16, 2009 at 23:15:29 Pacific
OS: Windows XP
Subcategory: Java
Comment:

I can not find my mistake... Can you help? Thank you ...

import java.util.Scanner; //import scanner

public class Assignment10_2 {
public static void main(String[] args) {
//create a scanner
Scanner input = new Scanner(System.in);

//Get number of items in inventory
System.out.print("Please enter the total number of items in inventory: ");
int numberOfItemsInInventory = input.nextInt();

//Array prices
int[]price = new int[numberOfItemsInInventory]; //array prices
int best = 0; //highest price
char inventory; //inventory

//read the price and find the best price
for (int i = 0; i < price.length ; i++) {
System.out.print("Please enter a price: ");
price[i] = input.nextInt();

if (price[i] > best)
best = price[i];
}

//Declaring and initializing output string
String output = " ";

// assign and display inventory pricing catagory
for (int i = 0; i < price.length ; i ++){
if (price[i] >= best - 33)
inventory = "H"; //High end inventory

else if (price[i] >= best - 66)
inventory = "M"; //middle end inventory

else
inventory = "L"; //low end inventory

output += "inventory " + i + "price " +
price[i] + "and inventory is" + inventory + "\n";

}
//Display the results
System.out.println(output);
}
}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: help with code

Help with debugging C++ code www.computing.net/answers/programming/help-with-debugging-c-code/13083.html

Help with a piece of code!! www.computing.net/answers/programming/help-with-a-piece-of-code/6023.html

Vba help with coding www.computing.net/answers/programming/vba-help-with-coding/13121.html