• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Challenge Program

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been stuck on this for at least a week and would really like a jumpstart to get me going.
The assignment instructions are attached and the also the code.











 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the problem you are having? What could you use help with?
 
Christopher Goad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't seem to figure out where to get started. My class is online and there is really not a good way to communicate. So I just need some advice.
 
author
Posts: 23951
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

Christopher Goad wrote:I can't seem to figure out where to get started. My class is online and there is really not a good way to communicate. So I just need some advice.




Generally, it is a good idea to start from the beginning. Read your instructions again. Make a list of what is wanted, what is needed, and how everything should go together. Once you have that, then you can decide which piece you want to tackle first.

Also, it is probably a good idea to not code first -- you need to figure out what you need to do, and how to do it, before actually doing it. Try it on paper with a pencil first.

Henry
 
Christopher Goad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you possibly help me with my code?
 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Goad wrote:Could you possibly help me with my code?



Welcome to this place. Like Henry rightly said, forget about the code. First figure out what is the exact use-case. What is it that the objective of the assignment is? Explain that to us in plain English. Then we will move on to the next step.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Goad wrote:Could you possibly help me with my code?


You will find plenty of HELP here, but nobody is going to DO it for you.

I would also suggest that when you start coding, you do ONE thing at a time. I'm not seeing the actual assignment, but I assume is says something like "create a class X. It should have the member variables A, B, and C. It should have methods D, E and F".

If I were coding it, I would write as little code as I could to get a Class X. That may be literally the following lines:


Compile that, and fix any/all errors. Then, I'd write the code to give it member variable A (but not B or C). Compile and debug. Then write the code to add B (but not yet C). Etc.

When you get to implementing methods, do it in TEENY, TINY steps. The first iteration of method D should do nothing more than print "I'm in method D". It should not accept any parameters or return anything. Once that works and you can call it, add a return value (if one is needed). Test that. Then add in the parameters one at a time, and make sure you can print out their value each time.

The less code you write between each compile/debug/test cycle, the easier it will be.
 
Christopher Goad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry I forget to post the assignment instructions. Here they are.

15.05 Assignment Instructions
1. Create a folder called 15.05 Assignment in your module 15 assignments folder.
2. Create an interface named Product .
a. Add a method called getName() that returns a string.
b. Add a method called getCost() that returns a double.
3. Create abstract class Vehicle that implements Product.
a. It should have string variable name and double cost, that are initialized in the constructor.
b. Add appropriate getName() and getCost() methods
4. Create classes Car and Truck that extend Vehicle.
a. No other methods are needed.
5. Create class Tool that implements Product and Comparable<T> .
a. It should have string variable name and double cost that are initialized in the constructor.
b. Add appropriate getName() and getCost() methods.
c. Add a compareTo() method that compares tools based upon cost .
6. Create class InventoryDemo.
a. Test your classes by using ArrayList products of following products (Remember to declare it properly using List):
Name
Cost
Jaguar
1000000.00
Neon
17000.00
JigSaw
149.18
Jaguar
110000.00
Neon
17500.00
Neon
17875.32
RAM
35700.00
CircularSaw
200.00
CircularSaw
150.00
b. Create a static method takeInventory that, when passed the name of a product, will go through the list and print out <item name>: Quantity = <quantity>, Total cost = <totalcost>. <item name> is the name of the product, <quantity> and <totalcost> are the values you calculate by going through the list for the product with name that was passed to takeInventory.
c. To test the compareTo() method, create two Tools, saw1 , and saw2 . Give them different prices and then test the compareTo() method you made, by displaying which one is more expensive.
 
Henry Wong
author
Posts: 23951
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

Christopher Goad wrote:I'm sorry I forget to post the assignment instructions. Here they are.

15.05 Assignment Instructions
1. Create a folder called 15.05 Assignment in your module 15 assignments folder.
2. Create an interface named Product .
a. Add a method called getName() that returns a string.
b. Add a method called getCost() that returns a double.
3. Create abstract class Vehicle that implements Product.
a. It should have string variable name and double cost, that are initialized in the constructor.
b. Add appropriate getName() and getCost() methods
4. Create classes Car and Truck that extend Vehicle.
a. No other methods are needed.
5. Create class Tool that implements Product and Comparable<T> .
a. It should have string variable name and double cost that are initialized in the constructor.
b. Add appropriate getName() and getCost() methods.
c. Add a compareTo() method that compares tools based upon cost .
6. Create class InventoryDemo.
a. Test your classes by using ArrayList products of following products (Remember to declare it properly using List):
Name
Cost
Jaguar
1000000.00
Neon
17000.00
JigSaw
149.18
Jaguar
110000.00
Neon
17500.00
Neon
17875.32
RAM
35700.00
CircularSaw
200.00
CircularSaw
150.00
b. Create a static method takeInventory that, when passed the name of a product, will go through the list and print out <item name>: Quantity = <quantity>, Total cost = <totalcost>. <item name> is the name of the product, <quantity> and <totalcost> are the values you calculate by going through the list for the product with name that was passed to takeInventory.
c. To test the compareTo() method, create two Tools, saw1 , and saw2 . Give them different prices and then test the compareTo() method you made, by displaying which one is more expensive.




So, what do you mean by ??? ...


Christopher Goad wrote:I can't seem to figure out where to get started. My class is online and there is really not a good way to communicate. So I just need some advice.



You seemed to have gotten started fine... What step are you currently at? And what problem are you encountering?

Henry
 
Christopher Goad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just do not know where to start off at. I'm getting confused...
 
Henry Wong
author
Posts: 23951
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

Christopher Goad wrote:I just do not know where to start off at. I'm getting confused...




Again, what do you mean by "do not know where to start off at"? You have already started.... And probably good until about step 3, where you seem to be skipping instructions (or just leaving implementations blank).

Henry
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

3. Create abstract class Vehicle that implements Product.


is your Vehicle class abstract?
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, maybe I can help a bit,

As I see it you need to make different car-objects with different kind of variables right?

In that case you need a constructor that "reads" the different variables and sets them. So you can call them with your get-method, in your main.

for instance,


I also think your class vehicle is like a super-type, where car and truck are the subtypes.
So you can make the subtypes inherite the methods and properties they have in common, of the superclass.
I hope my explanation doesn't confuse you even more.
I think the setter-methods part and the constructor part are very important.

I hope this helped,
regards Kenneth
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kenneth Van Gysegem says that the non‑private members of the Vehicle class are inherited by the Car, Truck, etc. classes. Exactly. That means you do not need to write them twice. You don’t need getCost methods or anything. You don7#x2019;t even need a cost field. You simply use the getCost method to access the superclass’ cost field.
If you are lucky, you can create the Car class simply by supplying constructors which call the superclass’ constructors.
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic