• 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:

Need help with Car Inventory Program part 3

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I am supposed to have:

Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product. This subclass must be "SUV" 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. The subclass of your product will be SUVs. This means that your subclass must be called “SUV”, and it will extend your “Car” class. The additional feature will be “mpg” which stands for the Miles Per Gallon. This data member should be of type “double” or “float”. The rest of the program will function the way it is described in the syllabus.

I get the following errors:

Inventory3.java:5: cannot find symbol
symbol : class Inventory
location: class Inventory3
private static Inventory i;
^
Inventory3.java:10: cannot find symbol
symbol : variable Suvcar
location: class Inventory3
Suvcar = new SuvCar(1, "Escape", 3, 34714.99);
^
Inventory3.java:10: cannot find symbol
symbol : class SuvCar
location: class Inventory3
Suvcar = new SuvCar(1, "Escape", 3, 34714.99);
^
Inventory3.java:11: cannot find symbol
symbol : variable Suvcar
location: class Inventory3
Suvcar = new SuvCar(2, "Taurus", 5, 24999.99);
^
Inventory3.java:11: cannot find symbol
symbol : class SuvCar
location: class Inventory3
Suvcar = new SuvCar(2, "Taurus", 5, 24999.99);
^
Inventory3.java:12: cannot find symbol
symbol : variable Suvcar
location: class Inventory3
Suvcar = new SuvCar(3, "Vue", 4, 32799.99);
^
Inventory3.java:12: cannot find symbol
symbol : class SuvCar
location: class Inventory3
Suvcar = new SuvCar(3, "Vue", 4, 32799.99);
^
Inventory3.java:15: cannot find symbol
symbol : class Inventory
location: class Inventory3
i = new Inventory(3);
^
Inventory3.java:16: cannot find symbol
symbol : variable p1
location: class Inventory3
i.add(p1, 0);
^
Inventory3.java:17: cannot find symbol
symbol : variable p2
location: class Inventory3
i.add(p2, 1);
^
Inventory3.java:18: cannot find symbol
symbol : variable p3
location: class Inventory3
i.add(p3, 2);
^
11 errors


Here is what I have come up with:

Inventory3:


Car class:


Suv class:


MPG class:

 
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
You seem to be missing a few classes...

Inventory3.java:5: cannot find symbol
symbol : class Inventory
location: class Inventory3
private static Inventory i;
^
Inventory3.java:10: cannot find symbol
symbol : class SuvCar
location: class Inventory3
Suvcar = new SuvCar(1, "Escape", 3, 34714.99);
^



Where is the Inventory class, and the SuvCar class?

Henry
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should both of them be named Car and Suv respectively?
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:You seem to be missing a few classes...

Inventory3.java:5: cannot find symbol
symbol : class Inventory
location: class Inventory3
private static Inventory i;
^
Inventory3.java:10: cannot find symbol
symbol : class SuvCar
location: class Inventory3
Suvcar = new SuvCar(1, "Escape", 3, 34714.99);
^



Where is the Inventory class, and the SuvCar class?

Henry



The 4 files I have are Inventory3, Car, Suv, and MPG. Is there any way to simplify this? I tried to play around with the classes in the Inventory3 part of it, but I am just getting more confused
 
Marshal
Posts: 80665
478
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds as simple as you can get: Car in Car.java, Suv in Suv.java, etc. One class, one file. Remember a "public top-level class" usually must have the same name as its file, so you can't fit two public top-level classes into one file.

And something else: don't use \n in String#format, Formatter#format, PrintStream#format and PrintStream#printf. Use %n instead. From the Formatter API documentation:

'n' line separator The result is the platform-specific line separator

This might be \n (*nix) \r (older Macs) or \r\n (DOS/Windows).
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I have made a few changes, but I am still getting the errors from before.

Inventory3.java:10: cannot find symbol
symbol : variable Car
location: class Inventory3
Car = new Car(1, "Escape", 3, 34714.99);
^
Inventory3.java:11: cannot find symbol
symbol : variable Car
location: class Inventory3
Car = new Car(2, "Taurus", 5, 24999.99);
^
Inventory3.java:12: cannot find symbol
symbol : variable Car
location: class Inventory3
Car = new Car(3, "Vue", 4, 32799.99);
^
Inventory3.java:15: cannot find symbol
symbol : class Inventory
location: class Inventory3
i = new Inventory(3);
^
Inventory3.java:16: cannot find symbol
symbol : variable p1
location: class Inventory3
i.add(p1, 0);
^
Inventory3.java:17: cannot find symbol
symbol : variable p2
location: class Inventory3
i.add(p2, 1);
^
Inventory3.java:18: cannot find symbol
symbol : variable p3
location: class Inventory3
i.add(p3, 2);
^
Inventory3.java:21: cannot find symbol
symbol : method sort()
location: class Inventory3
i.sort();
^
Inventory3.java:25: cannot find symbol
symbol : method get(int)
location: class Inventory3
System.out.println(i.get(k));
^
Inventory3.java:31: cannot find symbol
symbol : method totalValue()
location: class Inventory3
System.out.printf("Total value = $%.2f", i.totalValue());
^

What am I doing wrong? I have been on this again since 6am this morning
 
Henry Wong
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
The compiler messages are pretty clear. What is it that you don't understand?

Inventory3.java:10: cannot find symbol
symbol : variable Car
location: class Inventory3
Car = new Car(1, "Escape", 3, 34714.99);
^



Line 10 of Inventory3.java, you are using a variable name "Car", but the compiler can't find it -- either you forgot to declare it, or it is not in scope.

Inventory3.java:11: cannot find symbol
symbol : variable Car
location: class Inventory3
Car = new Car(2, "Taurus", 5, 24999.99);
^



Line 11 of Inventory3.java, you are using a variable name "Car", but the compiler can't find it -- either you forgot to declare it, or it is not in scope.


And BTW, it is generally a good idea to only fix one or two problems, then recompile -- as some compile problems can be caused by or hidden by, other compile problems... which is why I only explained the first two.

Henry
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I spent the day rewriting the whole thing and I think I made things worse.

Here are the errors when trying to compile the program:

InventoryProgramPart3.java:33: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
public static double calculateInventory(Car2[] cars) {
^
InventoryProgramPart3.java:8: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 cars[] = new Car2[5];
^
InventoryProgramPart3.java:8: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 cars[] = new Car2[5];
^
InventoryProgramPart3.java:12: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Escape = new Car2(1, "Escape", 24, 44675.75);
^
InventoryProgramPart3.java:12: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Escape = new Car2(1, "Escape", 24, 44675.75);
^
InventoryProgramPart3.java:14: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Vue = new Car2(2, "Vue", 20, 29457.99);
^
InventoryProgramPart3.java:14: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Vue = new Car2(2, "Vue", 20, 29457.99);
^
InventoryProgramPart3.java:16: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 F150 = new Car2(3, "F-150", 12, 45233.25);
^
InventoryProgramPart3.java:16: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 F150 = new Car2(3, "F-150", 12, 45233.25);
^
InventoryProgramPart3.java:18: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Aerostar = new Car2(4, "Aerostar", 6, 5000.00);
^
InventoryProgramPart3.java:18: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Aerostar = new Car2(4, "Aerostar", 6, 5000.00);
^
InventoryProgramPart3.java:20: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Caravan = new Car2(5, "Caravan", 15, 24766.50);
^
InventoryProgramPart3.java:20: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 Caravan = new Car2(5, "Caravan", 15, 24766.50);
^
InventoryProgramPart3.java:38: inconvertible types
found : <nulltype>
required: double
sum += cars[i].getUnitPrice();
^
14 errors

And now for the codes:

First one is InventoryProgramPart3:


The second one is Car2



The last one is SUV2. On this one, I have to use SUV and the extender, and I have to show MPG's (miles per gallon) I think I may have screwed up here, but I have so many things going on here, I am not quite sure what to do.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that you are forgetting the main principle behind java, Make each part work. You can take the main then one part and make it work when you are done with it start the next part and make it work, of course with the first part.
Hopefully I am not insulting here. Just trying to help. I to will copy it and see if I can be more help
I would say "Good luck" but there is no such thing just hard work and good beliefs.
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not insulted. But Frustrated...yes. Most of the mistakes I have made in the past ave been absolutely dumb. This one though takes the cake, if only I could figure out what I am doing wrong. Adding another class with the MPG requirement is throwing me off big time.

Thank you in advance. I can take any help I can get at this point.
 
Campbell Ritchie
Marshal
Posts: 80665
478
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch ( ) Larry Robinson.

The advice to do things in tiny stages is very useful.
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, after some sleep last night, I made a few changes. Some of which were stupid mistakes on my part, and some of which I would have never found on my own. The first problem was the "MPG" in my SUV2 class. Another is that I found out that I was not using an array at all in the InventoryProgramPart3 class. Now I am getting 14 errors. I am wondering if I even did that array right. Am I on the right track to assume that all my problems are within the Car array?

Here is the code for InventoryProgramPart3:

 
Campbell Ritchie
Marshal
Posts: 80665
478
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what were the errors? Try to correct the first one you can see at the top of the list, then repeat the compilation. You may find correcting one error will clear several more, so you reduce the error count quickly.

The bit you are doing wrong about the array is declaring its type incorrectly. Have you been through the Java Tutorials about for loops and arrays? That would allow you to check, and also show you the enhanced for loop, which may be easier to use here.
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Now I am only down to 9 errors. It seems like I am going around is circles. The last couple of errors are something that I have no idea what is wrong.
 
Campbell Ritchie
Marshal
Posts: 80665
478
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ignore the last error. Sort out the first error, and maybe the last error will go away. Look at this list of error messages. You probably want those in the "compiler" link. I found a second link which looks promising.
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I got. I have been over and over this....reading the textbook over and over again, and still nothing! I am about ready to throw my computer out the darn window! I can't believe I have wasted the whole weekend trying to figure this out!

InventoryProgramPart3.java:46: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
public static double calculateInventory(Car2[] cars) {
^
InventoryProgramPart3.java:21: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 cars[] = new Car2[5];
^
InventoryProgramPart3.java:21: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
Car2 cars[] = new Car2[5];
^
InventoryProgramPart3.java:25: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
cars[0] = new Car2(1, "Escape", 24, 44675.75);
^
InventoryProgramPart3.java:27: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
cars[1] = new Car2(2, "Vue", 20, 29457.99);
^
InventoryProgramPart3.java:29: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
cars[2] = new Car2(3, "F-150", 12, 45233.25);
^
InventoryProgramPart3.java:31: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
cars[3] = new Car2(4, "Aerostar", 6, 5000.00);
^
InventoryProgramPart3.java:33: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
cars[4] = new Car2(5, "Caravan", 15, 24766.50);
^
InventoryProgramPart3.java:51: inconvertible types
found : <nulltype>
required: double
sum += cars[i].getUnitPrice();
^
9 errors

InventoryProgramPart3 class:



Car2 class:



SUV2 code:
 
Henry Wong
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

InventoryProgramPart3.java:46: cannot find symbol
symbol : class Car2
location: class InventoryProgramPart3
public static double calculateInventory(Car2[] cars) {
^



This error is saying that the compiler can't find the Car2 class. This is most likely due to the fact that Car2 failed to compile. Try to compile and fix all the problems with the Car2 class first.

Henry
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now this is more like it!!! I finally figured out what I needed. Now, When I compile, the program compiles, however the SUV class does not compile with it, and when I go to run the program, it kicks me right back out to the c: prompt.

InventoryProgramPart3 class:


Car2 class:


And SUV2 class


Let me repeat for you, there are no errors showing up when I compile or run the program, I am just getting kicked out of it for some reason
 
Henry Wong
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

Kevin Quarles wrote:
Let me repeat for you, there are no errors showing up when I compile or run the program, I am just getting kicked out of it for some reason



Let's see what your main() method does, shall we?



The main method creates a Scanner object named input, and... that is all it does. You have some code after the main method, which you think is part of the main method, but it isn't.

Henry
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your patience. Do I get rid of it? If I do that, I have to get rid of import java.util.Scanner as well, right?
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, Got rid of both. It still compiles, but as soon as I run it, all I get is the c: prompt. SUV2 does not compile at all.
 
Campbell Ritchie
Marshal
Posts: 80665
478
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That last post doesn't make sense. Either it all compiles, or nothing compiles. Do you mean it throws an Exception when you run it? Or does it run and apparently nothing happens?
 
reply
    Bookmark Topic Watch Topic
  • New Topic