Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Creating A Car and Checking its warranty program

 
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Been a while since I needed help on my Java homework from school but I need help now.

So I have this assignment

1. Create a Car class and a subclass CertifiedPreOwnCar class that inherits from Car. Both Car and CertifiedPreOwnCar have a isCoveredUnderWarranty() method, which returns a boolean.  This method will determine whether the car is covered under warranty based on coverage years and miles, whichever comes first.  checkWarrantyStatus() method will print warranty information to inform the user whether the car is under warranty or not.

2. Create a test program called TestCar.  Create different Car objects and CertifiedPreOwnCar objects and invoke the checkWarranty() method on them.

So I worked on it and here is what I came up with. The issue I'm running into is in the testCar class. When I attempt to run it, I get multiple errors saying it can't resolve the methods in the testCar for the Honda Accord I put in. What am I doing wrong? Thanks for the help


Car Class



CertifiedPreOwnedCar class



testCar class

 
Marshal
Posts: 70620
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which methods can it not find?

Please use proper names for your constructor parameters; if you use the idiom this.xyz =... there is no need to us abbreviated names like ma.
Do you need any setWarrantyXXX() methods? Do you have some means of running up mileage/age of car to make it come out of warranty?

Edit: corrected spelling of html tag for hard space.
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Which methods can it not find?

Please use proper names for your constructor parameters; if you use the idiom this.xyz&xa0;=... there is no need to us abbreviated names like ma.
Do you need any setWarrantyXXX() methods? Do you have some means of running up mileage/age of car to make it come out of warranty?



It can't seem to find the methods in the testCar class on Lines 14 through 18

I'll change the constructor names to be proper instead of abbreviated

I was using the warrantyYears methods to check if the car was still in the time limit and mileage limit for a warranty. For example, the M6 in the testCar class is 6 years old but has no miles on it. It is still under warranty. Basically, I'm using it to set how long the warranty for the car is so that when it does the check in the CertifiedPreOwned class on Lines 26 and 27, it will check if all my conditions are met

 
Campbell Ritchie
Marshal
Posts: 70620
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the names of the classes carefully. Particularly the types of car. Where can you get a 100,000 mile/6 year extended warranty anywhere else?
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that I used it in my CertifiedPreOwned Class but my Car class doesn't check for it. Is that where I went wrong? I'm sorry for all the questions
 
Master Rancher
Posts: 4700
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your class is called CertifiedPreOwnedCar .
You are, however, declaring accord as of type CertifiedPreOwnCar .
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Your class is called CertifiedPreOwnedCar .
You are, however, declaring accord as of type CertifiedPreOwnCar .



lol I feel foolish now. Spelling errors will get you everytime
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One last question... I hope. I've got no flagrant errors in my code but when I run my code, it's not showing the results of my 3 test cars. It's just blank. Did i miss something?
blankCar.PNG
[Thumbnail for blankCar.PNG]
 
Campbell Ritchie
Marshal
Posts: 70620
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't let it worry you. everybody makes that sort of mistake.

Sean Mcintosh wrote:. . . Spelling errors will get you everytime

Maybe there is a subtler pitfall. Maybe you do have a CertifiedPreOwnCar class in your directory from old work.

I've got no flagrant errors in my code but when I run my code, it's not showing the results of my 3 test cars.

You must have an error somewhere. Please show us the current code.
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my current code

Car Class



CertifiedPreOwnedCar Class



and the testCar Class

 
Marshal
Posts: 25938
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now add some debugging statements (e.g. in the constructor for Car) which demonstrate that the code you posted is the code you're running.
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to forgive me. The only thing I know about debugging would be to add a println to see if it prints out. Is that what you're talking about?
 
Paul Clapham
Marshal
Posts: 25938
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. It's low-tech for sure but if you want a quick and dirty way to find out what your code is doing, then System.out.println is easy to use.
 
Campbell Ritchie
Marshal
Posts: 70620
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just tried your code from yesterday with copy'n'paste and no changes, and I got this result:-

java testCar.java
Your car 2014 BMW M6 with 0 miles is out of warranty.
Your car 1991 Acura NSX with 40000 miles is out of warranty.
Your car 2019 Honda Accord with 45000 miles is still covered under warranty.


 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Odd. That's exactly what it's suppose to display. Wonder why it's not doing that for me
 
Campbell Ritchie
Marshal
Posts: 70620
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe try running your code at the terminal/command line rather than your IDE. (Is that NetBeans?) Copy and paste the entire code into suitable XXX.java file(s) and try running it.
 
Sean Mcintosh
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Maybe try running your code at the terminal/command line rather than your IDE. (Is that NetBeans?) Copy and paste the entire code into suitable XXX.java file(s) and try running it.



I use IntelliJ but yeah. I ran it in Command Line and it works just fine. Weird but I'll take it. Thank you and Paul Clapham for all your help on this!
 
Paul Clapham
Marshal
Posts: 25938
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use Intellij but I would expect it to have a console somewhere, where you can see what you send to System.out and so on.

I just googled "intellij console" and it looks like there's a console tab, although it isn't entirely obvious to me as there's several other features with "console" in their name.
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic