Results 1 to 2 of 2
  1. #1
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default First GUI Assignment

    I am looking for help getting started with my first GUI assignment. Below is the assignment instructions and my code that properly executes. This is my
    second day working on this assignment and have still not written one piece of code because I do not know where to start or what the end result should look like. Can anyone get me started? Thanks for any help you can provide.

    Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and restocking fee.


    Java Code:
    // CheckPoint:  InventoryProgramPart3.java
    // Week 6
    // This program calculates inventory value
    
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class InventoryProgramPart3
    {
    
         // main method begins program execution
         public static void main(String args[] )
         {
              // create Scanner to obtain input from command window
              Scanner input = new Scanner( System.in );
    
              // display a welcome message to the InventoryProgramPart3 user
              System.out.println( "Welcome to Inventory Program Part 3!" );
    
              // office supplies
              
              supplies[] supplies = new supplies[100]; // an array of 100 supplies
              manufacturer[] manufacturer = new manufacturer[100];
                    
              manufacturer notepads = new manufacturer
                   ( 4000, "notepads", 60, 2.75, "Ampad" );
              manufacturer pencils = new manufacturer
                   ( 5000, "pencils", 75, 1.25, "Bic" );
              manufacturer folders = new manufacturer
                   ( 2000, "folders", 30, 4.75, "3M" );
              manufacturer envelopes = new manufacturer
                   ( 1000, "envelopes", 15, 5.25, "Universal" );
              manufacturer markers = new manufacturer
                   ( 3000, "markers", 45, 3.50, "Sanford" );
                                 
              // display the inventories one at a time
              envelopes.showInventory();
              folders.showInventory();
              markers.showInventory();
              notepads.showInventory();
              pencils.showInventory();
    
              // sort supplies by name
              for ( int i = 0; i < args.length; i++ )
              System.out.println( args[i] + ", " );
    
              double array[] = { 82.69, 149.63, 165.38, 173.25, 98.44 };
              double total = 0;
    
              // add each element's value to total
              for ( int counter = 0; counter < array.length; counter++)
                   total += array[ counter ];
              System.out.printf( "\nTotal inventory value is: $%.2f\n", total );
    
              System.out.println( "\nThank you for using Inventory Program Part 3!\n" );
              
         } // end method main
    
    } // end class InventoryProgramPart3     
    
    // Office Supplies
    class supplies
    {
         public int suppliesNumber;
         public String suppliesName = new String();
         public int suppliesUnits;
         public double suppliesPrice;
    
         // set supplies number
         public void setSuppliesNumber( int number )
         {
              this.suppliesNumber = number;
         } // end method set supplies number
    
         // return supplies number
         public int getSuppliesNumber()
         {
              return suppliesNumber;
         } // end method get supplies number
    
         // set supplies name
         public void setSuppliesName( String name )
         {
              this.suppliesName = name;
         } // end method set supplies name
    
         // return supplies name
         public String getSuppliesName()
         {
              return suppliesName;
         } // end method get supplies name
    
         // set supplies in stock
         public void setSuppliesUnits( int units )
         {
              this.suppliesUnits = units;
         } // end method set supplies units
    
         // return supplies units
         public int getSuppliesUnits()
         {
              return suppliesUnits;
         } // end method get supplies units
    
         // set supplies price
         public void setSuppliesPrice( double price )
         {
              this.suppliesPrice = price;
         } // end method set supplies price
    
         // return supplies price
         public double getSuppliesPrice()
         { 
              return suppliesPrice;
         } // end method get supplies price
    
         // calculate supplies inventory value
         public double getValue()
         {
              return suppliesUnits * suppliesPrice;
         } // end method supplies inventory value 
    
        // four-argument constructor
         supplies( int number, String name, int units, double price )
         { 
              suppliesNumber = number;
              suppliesName = name;
              suppliesUnits = units;
              suppliesPrice = price;
         } // end four-argument constructor
    
        // display inventory
         public void showInventory()
         {
              System.out.println(); // outputs blank line
    
              System.out.println( "Product Number:  "+suppliesNumber );
              System.out.println( "Product Name:  "+suppliesName );
              System.out.println( "Units in Stock:  "+suppliesUnits );
              System.out.printf( "Unit Price:  $%.2f", suppliesPrice );
    
              // value() method and display the value
              System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
                   getValue() );                           
      
        } // end display inventory
    
    } // end class supplies
    
    class manufacturer extends supplies
    {
         // holds the supplies manufacturer
         private String suppliesManufacturer;
    
         // five-argument constructor
         public manufacturer( int number, String name, int units,
              double price, String manufacturer )
         {
              super( number, name, units, price );
              // validate and store supplies manufacturer
              setSuppliesManufacturer( manufacturer ); 
         } // end five-argument constructor
    
         // set supplies manufacturer
         public void setSuppliesManufacturer( String manufacturer )
         {
              this.suppliesManufacturer = manufacturer;
         } // end method set supplies manufacturer
    
         // return supplies manufacturer
         public String getSuppliesManufacturer()
         {
             return suppliesManufacturer;
         } // end method get supplies manufacturer
    
         // calculate restocking fee
         public double getRestockingFee()
         {
              return super.getValue() * 0.05;
         } //end method calculate restocking fee
              
         //return String representation of suppliesManufacturer
         public String toString()
         {
              String formatString = "Manufacturer:  %s";
              formatString += "\nRestocking Fee:  $%.2f\n";
              formatString = String.format( formatString, suppliesManufacturer,
                   super.getValue() * 0.05 );          
              return( formatString );
         } // end toString()
    
         // display inventory
         public void showInventory()
         {
              super.showInventory();
              System.out.println( toString() );
              
              // Display value plus restocking fee
              System.out.printf( "\nTotal Inventory value of "+suppliesName+ " is = $%.2f\n",
                   super.getValue() * 0.05 + super.getValue() );     
    
         } // end method display inventory
    
    } // end class manufacturer

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default not a one day project

    Let me put it this way, you should read in the AWT / Swing forum for this post.

    This is why I walked out of a major university after only seventeen hours,....

    it defies comment.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. stuck on an assignment
    By starchildren3317 in forum New To Java
    Replies: 11
    Last Post: 11-19-2008, 11:03 PM
  2. Turtle assignment
    By jmc724 in forum New To Java
    Replies: 11
    Last Post: 07-16-2008, 09:11 PM
  3. Java assignment
    By xtianah77 in forum New To Java
    Replies: 1
    Last Post: 02-17-2008, 11:54 PM
  4. for Assignment plz help
    By assamhammad in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 08:35 PM
  5. Help with my assignment java
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •