Having trouble with Inventory Part 3 assignment

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1646 Views - Last Post: 04 May 2014 - 10:43 PM Rate Topic: -----

#1 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 11:42 AM

Hello,

For this assignment I'm supposed to modify my Inventory part 2 program so that it has a subclass of the product class that will allow for an additional attribute to be added, and also create a method to calculate the value of the inventory, as well as add a 5% restocking fee to the program. I've typed up my code, but I'm stuck with one error and I can't figure out how to fix it. Can someone please help me to fix this? I've been stuck on it for a week and need to get it fixed and turned in as soon as possible. Any help will be greatly appreciated.

Thanks :smile2:/>

package inventoryprogrampt3;

/**
 *
 * @author sgressett
 */
public class InventoryProgramPt3 {
    
  //this declares my array to be used by the subclass, not the superclass
        static int max = 5;
        static final Year[]year = new Year[max];
           
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args){
        year[0] = new Year("The Hunger Games", 4015, 1, 14.99) {};
        year[1] = new Year("Twilight", 2174, 2, 7.99);
        year[2] = new Year("The Music Man", 8225, 1, 12.99);
        year[3] = new Year("The Other Boleyn Girl", 7453, 1, 13.99);
        year[4] = new Year("The Fast and The Furious", 1421, 1, 14.99);
        calcinv(year);
        printinv(year);
        sortinv(year);
        printinv(year);
    }
    
    static void printinv(Year[]year) {
        System.out.println();
      
     for (int x=0; x<max; x++) {
         System.out.println("ID: " + year[x].pnumber);
         System.out.println("Name: " + year[x].pname);
         System.out.println("Units: " + year[x].punit);
         System.out.println("Price: $" + year[x].pprice);
     }
    }
    
    static void calcinv(Year[]year) {
        double ivalue = 0;
        
     for (int x=0; x<max; x++) {
         ivalue += year[x].punit + year[x].pprice;
     }
     System.out.println("Total Inventory Value is: $" + ivalue);
    }
    
    static void sortinv(Year[]year) {
        java.util.Arrays.sort(year);
    }
  }

class DVD implements Comparable <DVD> {
    double punit, pnumber, pprice;
    String pname;
    
    public DVD(String iname, double inumber, double iunit, double iprice) {
        pname = iname;
        pnumber = inumber;
        punit = iunit;
        pprice = iprice;
    }
    
    public int compareTo(DVD sortDVD) {
        return this.pname.compareTo(sortDVD.pname);
    }
}

class Year extends DVD {
    public double movieYear;
    double value;
    double reStockFee;
    
    public Year(String iname, double inumber, double iunit, double iprice, int year,
            double invalue, double RestockFee) {
        super(iname, inumber, iunit, iprice);
        movieYear = year;
        value = invalue;
        reStockFee = RestockFee;
    }

    Year(String the_Other_Boleyn_Girl, int i, int i0, double d) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    public void setYear (int year) {
        movieYear = year;
    }
  
    public double getYear() {
        return movieYear;
    }
  
   public void getRestockFee() {
        value = super.punit * super.pprice;
        reStockFee = value * .05;
      
    System.out.println("Restocking fee is: $" + reStockFee);
   }
}   


Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble with Inventory Part 3 assignment

#2 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 11:57 AM

What is the error?
Was This Post Helpful? 1
  • +
  • -

#3 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:04 PM

View Postastonecipher, on 04 May 2014 - 11:57 AM, said:

What is the error?




Sorry, I forgot to add that in. The error message that comes up is on Line 83 and when I hover over it with my mouse it says:

constructor DVD in class DVD cannot be applied to given types;
required: String, double, double, double
found: no arguments
reason: actual & formal argument lists differ in length

I've tried emailing my instructor about this one problem all week long but I'm still stuck on how to fix it so I can get my program to run correctly.
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:08 PM

The error is stating that it expects 4 arguments and none have been give. So look at your constructor. Are you passing the required arguments to the function?
Was This Post Helpful? 1
  • +
  • -

#5 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:10 PM

I don't understand how to do that. I'm new at all of this. Which part would I have to check to verify that?
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:12 PM

Your class constructor definition:

public Year(String iname, double inumber, double iunit, double iprice, int year,  double invalue, double RestockFee)

Your calling:

year[0] = new Year("The Hunger Games", 4015, 1, 14.99)


Should that be new DVD()?

This post has been edited by astonecipher: 04 May 2014 - 12:13 PM

Was This Post Helpful? 1
  • +
  • -

#7 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:16 PM

View Postastonecipher, on 04 May 2014 - 12:12 PM, said:

Your class constructor definition:

public Year(String iname, double inumber, double iunit, double iprice, int year,  double invalue, double RestockFee)

Your calling:

year[0] = new Year("The Hunger Games", 4015, 1, 14.99)


Should that be new DVD()?


It's supposed to add the year that the movie was made in the subclass. The original code that I had for the part 2 assignment had everything labeled as DVD[]dvd = new DVD but then when I created the year subclass for this assignment, I was told by my instructor that I had to change all of my DVD references to Year references, and when I did that I started getting this error that is popping up now and I have no idea how to even begin to fix it.
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:20 PM

Okay, it is expecting year as one of the missing parameters. Where does the year come from? Does the function calculate it or do you supply it?
Was This Post Helpful? 1
  • +
  • -

#9 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:22 PM

View Postastonecipher, on 04 May 2014 - 12:20 PM, said:

Okay, it is expecting year as one of the missing parameters. Where does the year come from? Does the function calculate it or do you supply it?



I wanted to set it up where the program would automatically supply it like it does for the rest of the information, but I'm not sure exactly how to do it because I don't know how to add more fields into the array.
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:23 PM

Are you putting when the movie was released or when the 'store' added it to the collection?
Was This Post Helpful? 1
  • +
  • -

#11 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:25 PM

When the movie was released.
Was This Post Helpful? 0
  • +
  • -

#12 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:29 PM

So that would need to be supplied. Because the program will not inherently know that information.


So, just like you added the title and price, you need to add the other information when you call the new constructor on Year()

For things the program would be able to calculate. Leave the item out of the constructor parameter list, but in that block add them to the variable list like

Name = movieName
Price = moviePrice * .25
Was This Post Helpful? 1
  • +
  • -

#13 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:31 PM

Okay so how would I do that and where would I add it in to my code at?
Was This Post Helpful? 0
  • +
  • -

#14 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,358
  • Joined: 03-December 12

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:39 PM

Your constructor:


class Year extends DVD {

    public double movieYear;

    double value;

    double reStockFee;

    public Year(String iname, double inumber, double iunit, double iprice, int year,

            double invalue, double RestockFee) {

        super(iname, inumber, iunit, iprice);

        movieYear = year;

        value = invalue;

        reStockFee = RestockFee;

    }




It might also behoove you to call other function in a private context to set some of these variables in place of having them publicly accessible.


So instead of

public function year(iyear)

You make it private and have your constructor either set it or call the function .

Have you been having any issues with not using this to refer to that instance of the object?
Was This Post Helpful? 1
  • +
  • -

#15 sewg82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 14

Re: Having trouble with Inventory Part 3 assignment

Posted 04 May 2014 - 12:44 PM

View Postastonecipher, on 04 May 2014 - 12:39 PM, said:

Your constructor:


class Year extends DVD {

    public double movieYear;

    double value;

    double reStockFee;

    public Year(String iname, double inumber, double iunit, double iprice, int year,

            double invalue, double RestockFee) {

        super(iname, inumber, iunit, iprice);

        movieYear = year;

        value = invalue;

        reStockFee = RestockFee;

    }




It might also behoove you to call other function in a private context to set some of these variables in place of having them publicly accessible.


So instead of

public function year(iyear)

You make it private and have your constructor either set it or call the function .

Have you been having any issues with not using this to refer to that instance of the object?



Up until now I've done okay, but for some reason this assignment is really throwing me for a loop and I'm not understanding much of it at all. In the part of the code that you supplied, that's where I add in the variables for the year? I'm sorry, I'm confused.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2