+ Reply to Thread
Results 1 to 7 of 7

Thread: Need Java help due assignment due 6-20

  1. #1
    Newbie kris1976 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    14

    Question Need Java help due assignment due 6-20

    on line 124 there are 2 errors "can't find symbol" I'm not done with the assignment but testing as I go along and can't figure out how to correct this error... any help would be great appreciated...
    here is the assignment: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the CD subclass, you could use CD genre, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
     Modify the output to display this additional feature you have chosen and the restocking fee.
     Post as an attachment in java format.
    Code:
    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
    Scanner input = new Scanner( System.in );
    
    // display welcome message
    System.out.println( "Welcome to Felt's Inventory!" );
    
    // cd
    
    cd[] cd = new cd[100]; // array of 100 cd
    
    cd GeorgeStraight = new cd(1, "George Straight", 5, 14.00);
    cd CarrieUnderwood = new cd(2, "Carrie Underwood", 4, 13.99);
    cd FaithHill = new cd(3, "Faith Hill", 6, 15.00);
    cd JoshTurner = new cd(4, "Josh Turner", 8, 12.99);
    cd GarthBrooks = new cd(5, "Garth Brooks", 3, 11.99);
    
    // display inventory one at a time
    
    GeorgeStraight.showInventory();
    CarrieUnderwood.showInventory();
    FaithHill.showInventory();
    JoshTurner.showInventory();
    GarthBrooks.showInventory();
    
    // sort cds by name
    for ( int i = 0; i < args.length; i++ )
    System.out.println( args[i] + "," );
    
    double array[] = { 70.00, 55.96, 90.00, 103.92, 35.97 };
    double total = 0;
    
    // add each 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 Felt's Inventory\n" );
    
    } // end main method
     
    } // end class InventoryProgramPart3
    
    class cd
    {
    
    public int cdItem;
    public String cdArtist;
    public int cdUnits;
    public double cdPrice;
    
    // set cd Item
    public void setCdItem(int item) {
    	this.cdItem = item;
    } // end method set Cd Item
    
    //return cd Item
    public int getCdItem() {
    	return cdItem;
    } // end method get Cd Item
    
    // set cd Artist
    public void setCdArtist(String artist) {
    	this.cdArtist = artist;
    } // end method set Cd Artist
    
    //return cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } // end method get cd Artist
    
    // set cd Units
    public void setCdUnits(int units) {
    	this.cdUnits = units;
    } // end method set Cd Units
     
    //return cd in stock
    public int getCdUnits() {
    return cdUnits;
    } //end method get Cd Units
    
    public void setCdPrice(double price) {
    	this.cdPrice = price;
    } //end method set Cd Price
    
    //return cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    // calculate value of cd inventory
    public double getValue()
    {
    return cdUnits * cdPrice;
    }// end method value of cd inventory
    
    // constructor
    cd( int item, String artist, int units, double price )
    {
    cdItem = item;
    cdArtist = artist;
    cdUnits = units;
    cdPrice = price;
    
    } // end constructor
    
    // display inventory
    public void showInventory()
    {
    	System.out.println(); // blank line
    
    System.out.println( "Cd Item: "+cdItem );
    System.out.println( "Cd Artist: "+cdArtist );
    System.out.println( "Units in Stock: "+cdUnits );
    System.out.printf( "Unit Price: $%.2f", cdPrice );
     
    genre cd = new genre
    	( 1, "George Straight", 5, 14.00, "Country" );
    
    System.out.println( "\nGenre: "+cd.getGenre() );// value() method and display value
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n", getValue() );
    
    } // end display inventory
    
    } // end class cd
    
    
    //

  2. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,680
    Blog Entries
    57

    Re: Need Java help due assignment due 6-20

    Where is genre defined?
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Newbie kris1976 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    14

    Re: Need Java help due assignment due 6-20

    ok now there are 2 errors on line 149 1. identifier expected 2. invalid method declaration; return type required, i highlighted the line in red
    Code:
    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
    Scanner input = new Scanner( System.in );
    
    // display welcome message
    System.out.println( "Welcome to Felt's Inventory!" );
    
    // cd
    
    cd[] cd = new cd[100]; // array of 100 cd
    
    cd GeorgeStraight = new cd(1, "George Straight", 5, 14.00);
    cd CarrieUnderwood = new cd(2, "Carrie Underwood", 4, 13.99);
    cd FaithHill = new cd(3, "Faith Hill", 6, 15.00);
    cd JoshTurner = new cd(4, "Josh Turner", 8, 12.99);
    cd GarthBrooks = new cd(5, "Garth Brooks", 3, 11.99);
    
    // display inventory one at a time
    
    GeorgeStraight.showInventory();
    CarrieUnderwood.showInventory();
    FaithHill.showInventory();
    JoshTurner.showInventory();
    GarthBrooks.showInventory();
    
    // sort cds by name
    for ( int i = 0; i < args.length; i++ )
    System.out.println( args[i] + "," );
    
    double array[] = { 70.00, 55.96, 90.00, 103.92, 35.97 };
    double total = 0;
    
    // add each 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 Felt's Inventory\n" );
    
    } // end main method
     
    } // end class InventoryProgramPart3
    
    class cd
    {
    
    public int cdItem;
    public String cdArtist;
    public int cdUnits;
    public double cdPrice;
    
    // set cd Item
    public void setCdItem(int item) {
    	this.cdItem = item;
    } // end method set Cd Item
    
    //return cd Item
    public int getCdItem() {
    	return cdItem;
    } // end method get Cd Item
    
    // set cd Artist
    public void setCdArtist(String artist) {
    	this.cdArtist = artist;
    } // end method set Cd Artist
    
    //return cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } // end method get cd Artist
    
    // set cd Units
    public void setCdUnits(int units) {
    	this.cdUnits = units;
    } // end method set Cd Units
     
    //return cd in stock
    public int getCdUnits() {
    return cdUnits;
    } //end method get Cd Units
    
    public void setCdPrice(double price) {
    	this.cdPrice = price;
    } //end method set Cd Price
    
    //return cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    // calculate value of cd inventory
    public double getValue()
    {
    return cdUnits * cdPrice;
    }// end method value of cd inventory
    
    // constructor
    cd( int item, String artist, int units, double price )
    {
    cdItem = item;
    cdArtist = artist;
    cdUnits = units;
    cdPrice = price;
    
    } // end constructor
    
    // display inventory
    public void showInventory()
    {
    	System.out.println(); // blank line
    
    System.out.println( "Cd Item: "+cdItem );
    System.out.println( "Cd Artist: "+cdArtist );
    System.out.println( "Units in Stock: "+cdUnits );
    System.out.printf( "Unit Price: $%.2f", cdPrice );
     
    genre cd = new genre
    	( 1, "George Straight", 5, 14.00, "Country" );
    
    System.out.println( "\nGenre: "+cd.getGenre() );
    
    // value() method and display value
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n", getValue() );
    
    } // end display inventory
    
    } // end class cd
    
    class genre 
    {
    // holds cd genre
    private String cdGenre;
    
    // constructor
    genre( int item, String artist, int units, double price, String genre )
    {
    	super( item, artist, units, price );
    	cdGenre = genre;
    } // end constructor
    
    // set cd genre
    pulic void setGenre( String genre ){
    	this.cdGenre = genre;
    } // end method set cd genre
    
    // return cd genre
    public String getGenre()
    {
    	return cdGenre;
    } // end method get cd genre
    
    // add 5% restocking fee
    public double getValue()
    {
    	return super.getValue() * 1.05;
    } // end method return cd genre
    
    // calculate restocking fee
    public double getRestockingFee()
    {
    	return super.getValue() * .05;
    } // end method caluclate restocking fee
    
    // return String cdGenre
    public String toString()
    {
    String formatString = "Genre: %s";
    formatString =+ "Restocking Fee: $%.2f";
    formatString = String.format( formatString, cdGenre, super.getValue() * 0.05 );
    return( formatString + super.toString() );
    } // end toString()
    
    // display inventory
    public void showInventory()
    {
    	super.showInventory();
    System.out.println( toString() );
    
    // Display value plus restocking fee
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n",
    getRestockingFee() );
    
    } // end method display inventory
    
    } // end class genre

  4. #4
    Newbie ShadenSmith will become famous soon enough ShadenSmith's Avatar
    Join Date
    May 2009
    Location
    Kentucky - USA
    Age
    18
    Posts
    19

    Re: Need Java help due assignment due 6-20

    You have "pulic" instead of "public" in the highlighted portion.

  5. #5
    Newbie kris1976 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    14

    Re: Need Java help due assignment due 6-20

    wow, that's embarrassing, i've been working on this since for almost 12hrs. think my eyes are crossing. hehe anyways I fixed that error and it gave me more now. I think they are possibly related seems to be symbol error. I highlighted lines in red which contain the errors
    1. line 144 error says "object can't be applied"
    2. line 163 can't find symbol
    3. line 169 can't find symbol
    4. line 177 can't find symbol
    5. line 184 can't find symbol
    6. line 188 can't find symbol
    any help is sooo appreciated, I just don't know what is still wrong with it... : (
    Code:
    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
    Scanner input = new Scanner( System.in );
    
    // display welcome message
    System.out.println( "Welcome to Felt's Inventory!" );
    
    // cd
    
    cd[] cd = new cd[100]; // array of 100 cd
    
    cd GeorgeStraight = new cd(1, "George Straight", 5, 14.00);
    cd CarrieUnderwood = new cd(2, "Carrie Underwood", 4, 13.99);
    cd FaithHill = new cd(3, "Faith Hill", 6, 15.00);
    cd JoshTurner = new cd(4, "Josh Turner", 8, 12.99);
    cd GarthBrooks = new cd(5, "Garth Brooks", 3, 11.99);
    
    // display inventory one at a time
    
    GeorgeStraight.showInventory();
    CarrieUnderwood.showInventory();
    FaithHill.showInventory();
    JoshTurner.showInventory();
    GarthBrooks.showInventory();
    
    // sort cds by name
    for ( int i = 0; i < args.length; i++ )
    System.out.println( args[i] + "," );
    
    double array[] = { 70.00, 55.96, 90.00, 103.92, 35.97 };
    double total = 0;
    
    // add each 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 Felt's Inventory\n" );
    
    } // end main method
     
    } // end class InventoryProgramPart3
    
    class cd
    {
    
    public int cdItem;
    public String cdArtist;
    public int cdUnits;
    public double cdPrice;
    
    // set cd Item
    public void setCdItem(int item) {
    	this.cdItem = item;
    } // end method set Cd Item
    
    //return cd Item
    public int getCdItem() {
    	return cdItem;
    } // end method get Cd Item
    
    // set cd Artist
    public void setCdArtist(String artist) {
    	this.cdArtist = artist;
    } // end method set Cd Artist
    
    //return cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } // end method get cd Artist
    
    // set cd Units
    public void setCdUnits(int units) {
    	this.cdUnits = units;
    } // end method set Cd Units
     
    //return cd in stock
    public int getCdUnits() {
    return cdUnits;
    } //end method get Cd Units
    
    public void setCdPrice(double price) {
    	this.cdPrice = price;
    } //end method set Cd Price
    
    //return cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    // calculate value of cd inventory
    public double getValue()
    {
    return cdUnits * cdPrice;
    }// end method value of cd inventory
    
    // constructor
    cd( int item, String artist, int units, double price )
    {
    cdItem = item;
    cdArtist = artist;
    cdUnits = units;
    cdPrice = price;
    
    } // end constructor
    
    // display inventory
    public void showInventory()
    {
    	System.out.println(); // blank line
    
    System.out.println( "Cd Item: "+cdItem );
    System.out.println( "Cd Artist: "+cdArtist );
    System.out.println( "Units in Stock: "+cdUnits );
    System.out.printf( "Unit Price: $%.2f", cdPrice );
     
    genre cd = new genre
    	( 1, "George Straight", 5, 14.00, "Country" );
    
    System.out.println( "\nGenre: "+cd.getGenre() );
    
    // value() method and display value
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n", getValue() );
    
    } // end display inventory
    
    } // end class cd
    
    class genre 
    {
    // holds cd genre
    private String cdGenre;
    
    // constructor
    genre( int item, String artist, int units, double price, String genre )
    {
    	super( item, artist, units, price );	cdGenre = genre;
    } // end constructor
    
    // set cd genre
    public void setGenre( String genre )
    {
    	this.cdGenre = genre;
    } // end method set cd genre
    
    // return cd genre
    public String getGenre()
    {
    	return cdGenre;
    } // end method get cd genre
    
    // add 5% restocking fee
    public double getValue()
    {
    	return super.getValue() * 1.05;} // end method return cd genre
    
    // calculate restocking fee
    public double getRestockingFee()
    {
    	return super.getValue() * .05;} // end method caluclate restocking fee
    
    // return String cdGenre
    public String toString()
    {
    String formatString = "Genre: %s";
    formatString += "Restocking Fee: $%.2f";
    formatString = String.format( formatString, cdGenre, super.getValue() * 0.05 );return( formatString + super.toString() );
    } // end toString()
    
    // display inventory
    public void showInventory()
    {
    	super.showInventory();System.out.println( toString() );
    
    // Display value plus restocking fee
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n",
    getRestockingFee() );
    } // end method display inventory
    
    } // end class genre

  6. #6
    Programmer oxano is on a distinguished road oxano's Avatar
    Join Date
    May 2009
    Location
    Belgium
    Age
    19
    Posts
    180

    Re: Need Java help due assignment due 6-20

    Your problem is actually very small and easy to solve.

    Code:
    super( item, artist, units, price );
    Here you call the constructor of a class. I know, you know, he must call the constructor of class "cd". But java can't figure that out. You must tell Java which class he must call to use the constructor of it. This is done in the first line of the class:

    Code:
    class genre extends cd
    by using this as first line for the class genre. This class will now have all methods/attributes available from cd. Including the constructor of cd which you call with the super().

    Everything runs fine now. Just some "is never used"-warnings.

    Full code:
    Code:
    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
    Scanner input = new Scanner( System.in );
    
    // display welcome message
    System.out.println( "Welcome to Felt's Inventory!" );
    
    // cd
    
    cd[] cd = new cd[100]; // array of 100 cd
    
    cd GeorgeStraight = new cd(1, "George Straight", 5, 14.00);
    cd CarrieUnderwood = new cd(2, "Carrie Underwood", 4, 13.99);
    cd FaithHill = new cd(3, "Faith Hill", 6, 15.00);
    cd JoshTurner = new cd(4, "Josh Turner", 8, 12.99);
    cd GarthBrooks = new cd(5, "Garth Brooks", 3, 11.99);
    
    // display inventory one at a time
    
    GeorgeStraight.showInventory();
    CarrieUnderwood.showInventory();
    FaithHill.showInventory();
    JoshTurner.showInventory();
    GarthBrooks.showInventory();
    
    // sort cds by name
    for ( int i = 0; i < args.length; i++ )
    System.out.println( args[i] + "," );
    
    double array[] = { 70.00, 55.96, 90.00, 103.92, 35.97 };
    double total = 0;
    
    // add each 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 Felt's Inventory\n" );
    
    } // end main method
    
    } // end class InventoryProgramPart3
    
    class cd
    {
    
    public int cdItem;
    public String cdArtist;
    public int cdUnits;
    public double cdPrice;
    
    // set cd Item
    public void setCdItem(int item) {
    	this.cdItem = item;
    } // end method set Cd Item
    
    //return cd Item
    public int getCdItem() {
    	return cdItem;
    } // end method get Cd Item
    
    // set cd Artist
    public void setCdArtist(String artist) {
    	this.cdArtist = artist;
    } // end method set Cd Artist
    
    //return cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } // end method get cd Artist
    
    // set cd Units
    public void setCdUnits(int units) {
    	this.cdUnits = units;
    } // end method set Cd Units
    
    //return cd in stock
    public int getCdUnits() {
    return cdUnits;
    } //end method get Cd Units
    
    public void setCdPrice(double price) {
    	this.cdPrice = price;
    } //end method set Cd Price
    
    //return cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    // calculate value of cd inventory
    public double getValue()
    {
    return cdUnits * cdPrice;
    }// end method value of cd inventory
    
    // constructor
    cd( int item, String artist, int units, double price )
    {
    cdItem = item;
    cdArtist = artist;
    cdUnits = units;
    cdPrice = price;
    
    } // end constructor
    
    // display inventory
    public void showInventory()
    {
    	System.out.println(); // blank line
    
    System.out.println( "Cd Item: "+cdItem );
    System.out.println( "Cd Artist: "+cdArtist );
    System.out.println( "Units in Stock: "+cdUnits );
    System.out.printf( "Unit Price: $%.2f", cdPrice );
    
    genre cd = new genre
    	( 1, "George Straight", 5, 14.00, "Country" );
    
    System.out.println( "\nGenre: "+cd.getGenre() );
    
    // value() method and display value
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n", getValue() );
    
    } // end display inventory
    
    } // end class cd
    
    class genre extends cd
    {
    // holds cd genre
    private String cdGenre;
    
    // constructor
    genre( int item, String artist, int units, double price, String genre )
    {
    	super( item, artist, units, price );	cdGenre = genre;
    } // end constructor
    
    // set cd genre
    public void setGenre( String genre )
    {
    	this.cdGenre = genre;
    } // end method set cd genre
    
    // return cd genre
    public String getGenre()
    {
    	return cdGenre;
    } // end method get cd genre
    
    // add 5% restocking fee
    public double getValue()
    {
    	return super.getValue() * 1.05;} // end method return cd genre
    
    // calculate restocking fee
    public double getRestockingFee()
    {
    	return super.getValue() * .05;} // end method caluclate restocking fee
    
    // return String cdGenre
    public String toString()
    {
    String formatString = "Genre: %s";
    formatString += "Restocking Fee: $%.2f";
    formatString = String.format( formatString, cdGenre, super.getValue() * 0.05 );return( formatString + super.toString() );
    } // end toString()
    
    // display inventory
    public void showInventory()
    {
    	super.showInventory();System.out.println( toString() );
    
    // Display value plus restocking fee
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n",
    getRestockingFee() );
    } // end method display inventory
    
    } // end class genre
    PS: it's more logical to put constructors right after the declaration of the class and its attributes. I hope you have 3 seperate classes instead of writing it all in 1. Might be easier to look at in the browser if you splitted the 3 classes up with 3 differente [CODE][/CODE'] tags.
    Don't forget to use public/private in front of the new classes. I suppose Java uses a standard value if you leave it empty anyway.
    Last edited by oxano; 06-21-2009 at 04:49 AM. Reason: Added PS

  7. #7
    Newbie kris1976 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    14

    Re: Need Java help due assignment due 6-20

    Not sure why my restocking fee is not displaying, there are no errors, it runs and displays Genre but the restocking fee does not display... ???Assignment: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the CD subclass, you could use CD genre, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
     Modify the output to display this additional feature you have chosen and the restocking fee.

    Code:
    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
    Scanner input = new Scanner( System.in );
    
    // display welcome message
    System.out.println( "Welcome to Felt's Inventory!" );
    
    // cd
    
    cd[] cd = new cd[100]; // array of 100 cd
    
    cd GeorgeStraight = new cd(1, "George Straight", 5, 14.00);
    cd CarrieUnderwood = new cd(2, "Carrie Underwood", 4, 13.99);
    cd FaithHill = new cd(3, "Faith Hill", 6, 15.00);
    cd JoshTurner = new cd(4, "Josh Turner", 8, 12.99);
    cd GarthBrooks = new cd(5, "Garth Brooks", 3, 11.99);
    
    // display inventory one at a time
    
    GeorgeStraight.showInventory();
    CarrieUnderwood.showInventory();
    FaithHill.showInventory();
    JoshTurner.showInventory();
    GarthBrooks.showInventory();
    
    // sort cds by name
    for ( int i = 0; i < args.length; i++ )
    System.out.println( args[i] + "," );
    
    double array[] = { 70.00, 55.96, 90.00, 103.92, 35.97 };
    double total = 0;
    
    // add each 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 Felt's Inventory\n" );
    
    } // end main method
     
    } // end class InventoryProgramPart3
    
    class cd
    {
    
    public int cdItem;
    public String cdArtist;
    public int cdUnits;
    public double cdPrice;
    
    // set cd Item
    public void setCdItem(int item) {
    	this.cdItem = item;
    } // end method set Cd Item
    
    //return cd Item
    public int getCdItem() {
    	return cdItem;
    } // end method get Cd Item
    
    // set cd Artist
    public void setCdArtist(String artist) {
    	this.cdArtist = artist;
    } // end method set Cd Artist
    
    //return cd Artist
    public String getCdArtist() {
    	return cdArtist;
    } // end method get cd Artist
    
    // set cd Units
    public void setCdUnits(int units) {
    	this.cdUnits = units;
    } // end method set Cd Units
     
    //return cd in stock
    public int getCdUnits() {
    return cdUnits;
    } //end method get Cd Units
    
    public void setCdPrice(double price) {
    	this.cdPrice = price;
    } //end method set Cd Price
    
    //return cd Price
    public double getCdPrice() {
    	return cdPrice;
    } //end method get Cd Price
    
    // calculate value of cd inventory
    public double getValue()
    {
    return cdUnits * cdPrice;
    }// end method value of cd inventory
    
    // constructor
    cd( int item, String artist, int units, double price )
    {
    cdItem = item;
    cdArtist = artist;
    cdUnits = units;
    cdPrice = price;
    
    } // end constructor
    
    // display inventory
    public void showInventory()
    {
    	System.out.println(); // blank line
    
    System.out.println( "Cd Item: "+cdItem );
    System.out.println( "Cd Artist: "+cdArtist );
    System.out.println( "Units in Stock: "+cdUnits );
    System.out.printf( "Unit Price: $%.2f", cdPrice );
     
    genre cd = new genre
    	( 1, "George Straight", 5, 14.00, "Country" );
    
    System.out.println( "\nGenre: "+cd.getGenre() );
    
    // value() method and display value
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n", getValue() );
    
    } // end display inventory
    
    } // end class cd
    
    class genre extends cd
    {
    // holds cd genre
    private String cdGenre;
    
    // constructor
    genre( int item, String artist, int units, double price, String genre )
    {
    	super( item, artist, units, price );
    	cdGenre = genre;
    } // end constructor
    
    // set cd genre
    public void setGenre( String genre )
    {
    	this.cdGenre = genre;
    } // end method set cd genre
    
    // return cd genre
    public String getGenre()
    {
    	return cdGenre;
    } // end method get cd genre
    
    // add 5% restocking fee
    public double getValue()
    {
    	return super.getValue() * 1.05;
    } // end method return cd genre
    
    // calculate restocking fee
    public double getRestockingFee()
    {
    	return super.getValue() * .05;
    } // end method caluclate restocking fee
    
    // return String cdGenre
    public String toString()
    {
    String formatString = "Genre: %s";
    formatString += "Restocking Fee: $%.2f";
    formatString = String.format( formatString, cdGenre, super.getValue() * 0.05 );
    return( formatString + super.toString() );
    } // end toString()
    
    // display inventory
    public void showInventory()
    {
    	super.showInventory();
    System.out.println( toString() );
    
    // Display value plus restocking fee
    System.out.printf( "\nInventory value of "+cdArtist+ " is = $%.2f\n",
    getRestockingFee() );
    
    } // end method display inventory
    
    } // end class genre

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Tutorial: Starting Java Using Netbeans
    By Jordan in forum Java Tutorials
    Replies: 4
    Last Post: 02-27-2010, 05:20 PM
  2. Kill process by command name
    By mop in forum Linux Installation & Configuration
    Replies: 4
    Last Post: 02-16-2009, 07:21 PM
  3. JRuby Co-Developer to conduct Workshop on JRuby, Testing Java with Ruby
    By Shaguf in forum Software Development Tools
    Replies: 1
    Last Post: 12-23-2008, 02:19 PM
  4. Java Facts
    By techni68 in forum Java Help
    Replies: 0
    Last Post: 01-17-2007, 01:41 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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