• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

I'm confused on why my program isn't displaying some things when I have no error messages.

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a part of my inventory program that is supposed to add an additional attribute to the dvds. I chose to add the genre for each movie but when I run my program in Eclipse is doesn't display the genre. I also wrote something that is supposed to calculate a 5% restocking fee for each dvd by multiplying the price and the amount in stock (quantity), and that also isn't showing up on the display. I am a newbie at this. Any hints on what I am doing wrong will be appreciated.





 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do you actually create a DVD2 and give it a genre to print out? All I see you making are DVDs, which do not have genres.
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. Okay. So I just need to create a print statement in DVD2 for each dvd's genre?
 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote:Hmm. Okay. So I just need to create a print statement in DVD2 for each dvd's genre?



All the printing comes from DVD but DVD2 is the only one that contains genre! You don't create any instances of DVD2, but you don't try to print them either, so no error
Best solution might just be to add genre to DVD and get rid of DVD2. I like how you've formatted the output.
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added genre to DVD but I cannot completely get rid of DVD2 because having that class is a requirement for my assignment. Can I just use it for something like calculating the restocking fee?
 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote:I added genre to DVD but I cannot completely get rid of DVD2 because having that class is a requirement for my assignment. Can I just use it for something like calculating the restocking fee?



If you can do anything with DVD2 that you want, you could make it a subclass of DVD that adds genre or say movie length. Then you could use DVD as the base for both movie and data DVDs. If it's required to have it,
need to figure out a reasonable way to justify it too Or figure out more clearly what the instructor (your boss) is thinking.

 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
leaving your code mostly as-is, why not do this:

 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My instructor just informed me that I am not supposed to make any changes to my DVD or Inventory classes. I need to create a method for adding a 5% restocking fee, add an additional feature (I chose to add the genre for each dvd), and then modify the output to display those things. So all of this needs to be done from my DVD2 class.
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I attempted to add the restocking fee and the genre but I'm confused on how to display those new outputs along with the rest.

 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote:My instructor just informed me that I am not supposed to make any changes to my DVD or Inventory classes. I need to create a method for adding a 5% restocking fee, add an additional feature (I chose to add the genre for each dvd), and then modify the output to display those things. So all of this needs to be done from my DVD2 class.



Ok you're almost done then. I didn;t know any of the code had been provided. I would just do what Fred said and also add the fee thing. Then print DVD2 instead of DVD if it's allowed and as far as I can tell you're done.

P.S. just saw your update about how to print the new stuff. Assign and print DVD2 instead of DVD and problem solved. Realize DVD2 also has all the properties of DVD since it extends it.

 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I do what Fred had suggested wouldn't I be editing my 'inventory' class?
 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote:If I do what Fred had suggested wouldn't I be editing my 'inventory' class?



Unless I'm missing something there all you have to do is something like DVD p1 = new DVD2(1,"Forrest Gump","comedy",3,15.49); in main(). Whatever parameters the DVD2 constructor takes. Then the "products" just below are DVD2 instances. When you print it wil include the new stuff genre and etc.
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I start by adding my dvds

in my DVD2 class, correct?
 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote:So I start by adding my dvds

in my DVD2 class, correct?



most of what you need to do is in main(). But I just noticed you'll have to override toString() in DVD2 to get the extra parameters in there. It will look like a copy of the one in DVD but with the extra parameters.

You will have to try things and see what happens. Always keep the previous versions to revert back to.
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm fairly new to this whole programming thing. When you said "most of what you need to do is in main()" were you referring to my inventory class? and how do I go about overriding toString() in DVD2 to get the extra parameters in there. I went ahead and added my dvds with the genres included to my DVD2 class as you mentioned. Does it look okay or no?

 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote: Does it look okay or no?



The question should be what happens when I run it. If it's not what you had in mind then ponder what almost gave you what you wanted and how to add to it to give you what you want. I'll say to copy and paste the old toString() into DVD2 and add the new parameters you want to that method. For future reference it seems a little unusual to use toString() for this but it's probably just personal preference.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Does it look okay or no?
I'm going to say no.

By "main()" Guillermo was referring to the main method of your Inventory program - the one where you were already creating the DVD library.

Think of it this way.
If it is to do with the details of one DVD, then write code in the DVD/DVD2 class (calculating value, printing a title etc etc)
If it is to do with a set of dvds in general, it should be outside of the DVD class - in the inventory class (which is where you originally had it)

Maybe you took the "only make changes to DVD2" instruction too far?
You have to be able to change that class to create DVD2 objects rather than DVD objects. Right?


 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I ran it there were no changes. It displayed just the same as it did before I added the genre. Am I to copy the toString() that's at the end of my DVD class and use that in DVD2? I tried copying the toString() and applying it to DVD2 and it says "void methods cannot return a value".
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Stefan

I need to make changes to all 5 dvds by adding the genre to each of them, as well as to calculate the 5% restocking fee for each dvd.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So yes.

Your DVD2 class supports Genre where the DVD class didn't.
Your DVD2 class adds a restocking fee, where the original doesn't.

So the DVD2 class should override a couple of the methods from DVD.

Your inventory class then needs to work with DVD2 objects.
So at the top of the main method of your inventory class, instead of creating a DVD objects, create DVD2 objects.
All the rest of the inventory program should theoretically remain exactly the same, and 'just work'.

 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how about this? I am not getting anything different when the output is displayed.

 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Potential big problem here... .

I just noticed you said you aren't allowed to change the Inventory class, so what we are suggesting e.g. DVD d = new DVD2(... isn't allowed since main() is in Inventory.

I would demand clarification on what the output is supposed to be. Supposed to be to pass the assignment.

The problem is a fuzzy spec. Seen it a million times. I think they like this in Agile. Especially if two people are working on it together. Sometimes it looks like agile is
youngsters running headlong into problems the oldsters have long before learned to avoid...


 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I run it, this is what it displays:



There is supposed to be a genre and restocking fee included for each item.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am presuming you are running your Inventory class.
Does the Inventory class use DVD or DVD2 objects in its 'inventory' ?

I think you want to replace


with


If you do that and run it, I think it will print out the Genre's appropriately for you.

Your DVD2 class now has two methods:
getInventoryValue() (inherited from DVD)
getValue()

I think these methods are intended for the same general purpose, and only one of these signatures should exist
That will get you closer again to your 'answer'

For the last issue I can see:
If you apply a tax to a value, should it cost more or less than it did originally ?
 
John Locke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried running that but got this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined

at inventory.main(inventory.java:13)

 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is easier to fix compilation errors during compilation. See this...

https://coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication

Henry
 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Locke wrote:I tried running that but got this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined
The constructor DVD2(int, String, int, double) is undefined

at inventory.main(inventory.java:13)



John, that error is caused because you are calling a constructor for DVD2 using those parameters but don't have one defined that uses those parameters. When you call a method you have to supply the right number and type of parameters in the right order in those parenthesis. Sometimes error messages are too cryptic to be helpful but not in this case. Read about constructors in Java.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thing is, the correct code has already been written and posted in this thread at least twice.
To construct a DVD2 object, you need to pass the genre.



 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic