Help I am a student and have no idea how to sort this program by Product

First class:
// CheckPoint: Inventory Program Part 1
// Display product information
public class Product1 //declare class
//declare instance variables
private int productNumber,
inStock;
private String productName; // List of instance variables unique to object
private double unitPrice;
//constructor to handle no input and set defaults
public Product1()
//constructor to handle input parameters
public Product1( int number, String name, int stock, double perPrice )
productNumber = number;
productName = name;
inStock = stock;
unitPrice = perPrice;
public void setProductNumber( int number ) //stores product number
productNumber = number;
public void setProductName( String name ) //stores product name
productName = name;
public void setInStock( int stock ) //stores amount of product in stock
inStock = stock;
public void setUnitPrice( double perPrice ) //stores the unit price of product
unitPrice = perPrice;
public int getProductNumber() //allows a call to retrieve product number
return productNumber;
public String getProductName() //allows a call to retrieve the product name
return productName;
public int getInStock() //allows a call to retrieve stock info
return inStock;
public double getUnitPrice() //allows a call to retrieve unit price
return unitPrice;
public double getInventoryValue()
return ( (double)inStock * unitPrice );
public String toString()
return productName + " - " + unitPrice;
Second Class:
import java.text.DecimalFormat;
public class Inventory1
private final int maxInventory = 30;
private Product1 items[] = new Product1[ maxInventory ];
DecimalFormat formatter = new DecimalFormat( "$##,###.00" );
public void addProduct( Product1 item )
for ( int i = 0; i < maxInventory; i++ )
if (items[i] == null)
items[i] = item;
return;
public double getTotalInventoryValue()
double sum = 0.0;
for ( Product1 item : items )
if ( item != null )
sum += item.getInventoryValue();
return sum;
public void displayInventory()
boolean hasItems = false;
for ( Product1 item : items )
if ( item != null)
hasItems = true;
System.out.printf( "%8d%12s%11d%13.2f%14.2f", item.getProductNumber() , item.getProductName(), item.getInStock(), item.getUnitPrice(), item.getInventoryValue() );
System.out.println( "" ); // display space
System.out.println("");
Part 3:
import java.text.DecimalFormat;
public class InventoryTest1
static DecimalFormat formatter = new DecimalFormat( "$##,###.00" );
public static void main( String args[] )
Product1 item1 = new Product1( 001, "Staples", 5, 2.99 );
Product1 item2 = new Product1( 002, "Books", 10, 15.00 );
Product1 item3 = new Product1( 003, "Printers", 20, 55.00 );
Inventory1 myInventory1 = new Inventory1();
System.out.println("");
System.out.printf( "%s%12s%11s%13s%14s", "Product#", "Name", "In Stock", "Unit Price", "Stock Value" );
System.out.println("");
System.out.println("");
myInventory1.displayInventory();
myInventory1.addProduct( item1 );
myInventory1.addProduct( item2 );
myInventory1.addProduct( item3 );
myInventory1.displayInventory();
System.out.println( "" ); // display space
System.out.println("");
System.out.println( "Total value of inventory is: " );
System.out.println ( formatter.format(myInventory1.getTotalInventoryValue() ) );
I have no idea where to put the sort statement and how to implement it.

Sorry about that. Before i proceed with the code I will say that I need help trying to determine where to put a sort statement and what sort statement should I use. I have three classes and have no idea how to sort the items by Product name. For instance, I have staples, books, and printers in my code. How do I get it to display these names and all of the corresponding information in alphabetical order. So with that said, here is the code.
First program:
// CheckPoint: Inventory Program Part 1
// Display product information
public class Product1 //declare class
//declare instance variables
private int productNumber,
inStock;
private String productName; // List of instance variables unique to object
private double unitPrice;
//constructor to handle no input and set defaults
public Product1()
//constructor to handle input parameters
public Product1( int number, String name, int stock, double perPrice )
productNumber = number;
productName = name;
inStock = stock;
unitPrice = perPrice;
public void setProductNumber( int number ) //stores product number
productNumber = number;
public void setProductName( String name ) //stores product name
productName = name;
public void setInStock( int stock ) //stores amount of product in stock
inStock = stock;
public void setUnitPrice( double perPrice ) //stores the unit price of product
unitPrice = perPrice;
public int getProductNumber() //allows a call to retrieve product number
return productNumber;
public String getProductName() //allows a call to retrieve the product name
return productName;
public int getInStock() //allows a call to retrieve stock info
return inStock;
public double getUnitPrice() //allows a call to retrieve unit price
return unitPrice;
public double getInventoryValue()
return ( (double)inStock * unitPrice );
}

Similar Messages

  • Help! I am trying to load my itunes on my husbands laptop and have no idea how to do this. Does anyone know?

    I never transferred my old itunes account to my laptop. It's my husband's laptop and he had his itunes on it. We have just deauthorized his account but HAVE NO IDEA how to load my account on it. Please give me any tips you have. Thanks! Carmen

    Try the instructions mentioned here: How to set up an iTunes Store account and this one about authorizing : About iTunes Store authorization and deauthorization

  • I have a game on my xbox one that is telling me I need to open ports in order to play it I am not all that tech savvy and have no idea how to do this

    I have an airport extreme and I am trying to play a new game on my xbox one and it keeps kicking me I have comcast internet that is more than fast enough so I went to the games site and it says I need to either create a static ip or to open ports no idea how to do either of these or what that does any help would be appreciated.

    There are heaps of posts here about how to open ports on apple routers specifically for xboxes.
    AirPort Extreme and xbox 360

  • Help- I have no idea how to use this program.

    Hi All,
    I am really at a loss at the moment. I am hoping to create a flash document for work in order to present an idea I have. What I am basically wanting to do is to create an interactive workbook for clients on occupational health and safety.
    The problem is, I can visualise what I want but just cannot work out this programme (i mean to the extent I don't even know how to pull in the documents I want) let alone make it interactive.
    I know this is a long shot but is there anyone willing to help me get started with this???
    Thanks,
    Tianna

    check flashbuilder.  it's a program that's easier to use than flash pro and which you can use to create swf projects, too.

  • HT4759 i need to update my ipad and have no idea how to begin this

    I need help updating my ipad i am working with 4.3.5

    Connect your iPad to your computer and launch iTunes. You'll most likely be prompted to update. If not click the "check for update" button on the summary tab for the device in iTunes. For more information and full details, see the section titled "Update your device using iTunes" in this support article:
    http://support.apple.com/kb/HT4623
    You should read this article as well:
    http://support.apple.com/kb/HT4972
    Regards.
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question.

  • I'm trying to order a calendar off iphoto and have never had any issues, now it wont allow me to input a canadian address for ordering  help help help this is an xmas gift and i have no idea how to fix this have tried numerous things

    I'm trying to order a calendar off iphoto and have never had any issues, now it wont allow me to input a canadian address for ordering  help help help this is an xmas gift and i have no idea how to fix this have tried numerous things

    No I didn't even read through your post, to long.
    You said that "No matter what program I try to install, as soon as the installer opens it crashes". Were you talking about the install for this/these 3D programs or ANY program? As it is worded it sounded like ANY program. That tells me there is a problem with your Mac, software or hardware.
    Now you say others install programs, which is it. Programs other then the 3D ones install or no programs install?
    Could simply be your Mac is to old to run these programs and the installer knows that. You never said what model or year Mac it is.

  • I need help I can't remember my iTunes Security Questions and have no idea how to change them just used a $20 gift card

    I need help I can't remember my iTunes Security Questions and have no idea how to change them just used a $20 gift card

    If you have a rescue email address (which is not the same thing as an alternate email address) on your account then you can use that to reset them : http://support.apple.com/kb/HT6170
    If you don't have a rescue email address (you won't be able to add one until you can answer your questions) then you will have to contact Support in your country to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    If your country isn't on that page then try this form and explain and see what they reply with : https://ssl.apple.com/emea/support/itunes/contact.html
    When they've been reset (and if you don't already have a rescue email address) you can then use the steps on this page to add a rescue email address for potential future use : http://support.apple.com/kb/HT5620
    Or, if it's available in your country, you could change to 2-step verification : http://support.apple.com/kb/HT5570

  • Hi.. I have a new apple computer and have no idea how to find stuff on here... Can someone tell me how to find my search history? Thanks

    Hi.. I have a new apple computer and have no idea how to find stuff on here... Can someone tell me how to find my search history? Thanks

    In addition to Japib's suggestion check out
    OS X Yosemite: See your files in the Finder
    OS X Yosemite: Finder preferences
    OS X Yosemite: Ways to quickly see and open items
    OS X Yosemite: Search with Spotlight
    OS X Yosemite: Rename files, folders, and disks
    OS X Yosemite: Folder basics
    OS X Yosemite: Ways to organize files on your desktop
    One more thing:
    Search history is a term generally referring to what sites you have visited via your browser (e.g. Safari)
    To see your Safari search history just open Safari and go to the top menu and select from Show History from the History
    See two pics below

  • In my email all the messages from one person bunch together and I would like to separate them. I have done this before on my iPhone but just recently got an iPad and its doing it on this, so does anyone have any ideas how to fix this issue?

    In my email all the messages from one person bunch together and I would like to separate them. I have done this before on my iPhone but just recently got an iPad and its doing it on this, so does anyone have any ideas how to fix this issue?

    Settings >> Mail, Contacts. Calendars >> Organise by Thread. Switch to OFF to see every individual email in the Inbox.

  • I have downloaded adobe reader but it still says i need to accept the end user license agreement, i have searched everywhere and i have no idea how to "accept" this agreement

    i have downloaded adobe reader but it still says i need to accept the end user license agreement, i have searched everywhere and i have no idea how to "accept" this agreement

    yes i have for sure launched it this is what it looks like at the bottom of my computer, it says by downloading adobe you already agree to the license agreement but I've tried googling, "how to accept the end users license agreement" and it brings me to the agreement but there is no link or button to press on in order to accept it

  • HT1386 purchased new songs from itunes and when I clicked on the Sync button those new songs are not added to my ipod nano. Have any idea how to resolve this problem?

    purchased new songs from itunes and when I clicked on the Sync button those new songs are not added to my ipod nano. Have any idea how to resolve this problem?

    Do you have the right boxes checked to sync the music to your iPod?
    iTunes: Syncing media content to iOS devices and iPod
    Do they play in iTunes on the computer?
    Have you successfully synced music form this iTunes library/computer before?

  • Firefox crashes before it can be open, just started today and have no idea how to fix it.

    I was using Firefox when it first crashed, now when I try to restart it the Motzilla Crash Reporter window opens. I have no idea how to fix this. I tried to follow directions on-line (I'm not very computer savvy) but my signature/ID what ever is c27da8ef-4370-4963-9c18-cb5d52100726
    == Crash ID(s) ==
    c27da8ef-4370-4963-9c18-cb5d52100726
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.2; .NET4.0C; .NET CLR 1.1.4322)

    Run Software Update. Install all the recommended updates. Read: http://support.apple.com/kb/HT5244

  • I have no idea how I did this on my  ipad but everything on my screen is in negative view. How do I switch it back to positive or for me , normal view?

    I have no idea how I did this on my new ipad 2 but everything on my screen is in negative view. How do I switch it back to positive or for me , normal view?
    Thanks, joney

    Yes, you probably have the tripple-click Home button option off.
    Just visit the Accessibility pane under General settings (as described by King_Penguin above) and choose to assign what you need for your tripple click command, in this case toggling the black & white option.
    You can also tell it to 'ask' you what you want from that command each time.
    Hope this helps.

  • Hi, my facebook app on my Ipad3 has stopped allowing me to put comments on. Does anyone have any ideas how to correct this? Don't know if it is a problem with the Ipad or just the facebook app. Thanks.

    Hi, my facebook app on my Ipad3 has stopped allowing me to put comments on. Does anyone have any ideas how to correct this? Don't know if it is a problem with the Ipad or just the facebook app. Thanks.

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime: Set-up, Use, and Troubleshooting Problems
    http://tinyurl.com/32drz3d
    I saw one post where a user said dust got inside the small microphone hole. Using a vacuum cleaner removed the dust and restored the audio.
     Cheers, Tom

  • Several days ago some of the links in my Apple Mail messages stopped working. Specifically, the links going to some variation of "response beacon" don't work. All I see is a blank screen. Does anyone have any idea how to fix this?

    Several days ago some of the links in my Apple Mail messages stopped working. Specifically, the links going to some variation of "response beacon" don't work. All I see is a blank screen. Does anyone have any idea how to fix this?

    * "Clear the Cache": Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    * "Remove the Cookies" from sites that cause problems: Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

Maybe you are looking for

  • TS3297 I find the instructions to use automatic date/time in ts3297 to be totally unacceptable.

    I do things on my MBP (software builds) that REQUIRE consistent timestamps. I also travel extensively, which frequently results in "going backwards in time' (flying east to west). Updating date/time automatically causes total confusion for my builds,

  • Wine & Labview Executable​s?

    Is it possible to run LabView executables under wine? Has anyone ever attempted to do this? Thanks for any information. Regards, Ken

  • File Extension changing

    Hi, I have a file with the extension .mif in that I need to find and replace some tags and also save the file with another extension say .fm Could you please help me???

  • Can B1 groups 50 SOs in one BOL then issue separate invoice for each SO

    Customer wants to use Grouping feature for 40-50 sales orders in one Delivery Note and print the BOL (bill of lading) display all their order numbers, but they want to issue each invoice against each sales order.  Can B1 do this?

  • Update a column of a large table

    I have a table containing 33.430.648 records. I need to add a column of varchar2(1) data type with a default 'N' specification. Which is the best method to add this column? It takes very much time if i issue: alter table my_Table add my_column varcha