I need to make a subclass for the following code. I was planning on using the extends keyword but the instructor says to use =new keyword. I do not understand the = new keyword. Can someone please explain the difference and possibly provide an example based on the following code. 10 3266
I need to make a subclass for the following code. I was planning on using the extends keyword but the instructor says to use =new keyword. I do not understand the = new keyword. Can someone please explain the difference and possibly provide an example based on the following code.
Are you sure that your professor was referring to the code of the subclass when you were told to use 'new'? Generally the 'new' keyword is used when declaring an object, such as in your code above: -
Scanner input = new Scanner( System.in );
-
This code will create a Scanner on the heap. However, if you are writing a subclass, your inclination was correct (though I would suggest this article ' http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html' if you are considering 'extends' and instead suggest 'implements' as inventorysupply2 does to Comparable.) -
public class ExampleClass extends inventorysupply2 /*or Comparable, if that's what you want here */{
-
-
// methods, variables, and other things in here
-
-
}
-
-
Was your professor possibly telling you to use 'new' when instantiating your subclass in your final program?
Are you sure that your professor was referring to the code of the subclass when you were told to use 'new'? Generally the 'new' keyword is used when declaring an object, such as in your code above: -
Scanner input = new Scanner( System.in );
-
This code will create a Scanner on the heap. However, if you are writing a subclass, your inclination was correct (though I would suggest this article ' http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html' if you are considering 'extends' and instead suggest 'implements' as inventorysupply2 does to Comparable.) -
public class ExampleClass extends inventorysupply2 /*or Comparable, if that's what you want here */{
-
-
// methods, variables, and other things in here
-
-
}
-
-
Was your professor possibly telling you to use 'new' when instantiating your subclass in your final program?
all i know u he said "You do not need to use the extends keyword. The file with the static void main will call the otherfile.java into existence via the =New keyword." so i am very ocnfused now about how to add this subclass
all i know u he said "You do not need to use the extends keyword. The file with the static void main will call the otherfile.java into existence via the =New keyword." so i am very ocnfused now about how to add this subclass
1) You do not make a subclass of code but of a class
2)You cannot make a subclass without using extends
3)Perhaps you are supposed to come up with a different type of inventorysupplystock2 class and replace the current one with the new one in the main method. (All which have nothing to do with subclassing)
1) You do not make a subclass of code but of a class
2)You cannot make a subclass without using extends
3)Perhaps you are supposed to come up with a different type of inventorysupplystock2 class and replace the current one with the new one in the main method. (All which have nothing to do with subclassing)
This is what I have to do modify the inventory program by creating a subclass of product class that uses one additional unique feature of the product you choose (for the DVDs subclass you could use movie title, for example). 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. This is what I have so far can I get some help with a few errors? -
public class inventorysubclass extends inventorysupplys2{
-
-
protected String Title;
-
protected string Genre;
-
protected double value;
-
protected double restockingfee;
-
-
// four-argument contructor
-
public Title (String Title, String Genre, String Genre, double value, double restockingfee)
-
{
-
//implicit call to DVD contructor occurs here
-
Title = Title;
-
Genre = Genre
-
setValue(value); //validate value of DVD
-
setRestockingFee(rate); //validate and store restocking fee
-
} // end four-argument MoviteTitle contructor
-
-
// set title
-
public void setTitle(String first)
-
{
-
Title=Title;
-
} //end method setTitle
-
-
// return title
-
public String getTitle()
-
{
-
return Title;
-
} //end method getTitle
-
-
// set Genre
-
public void getGenre (String Genre)
-
{
-
Genre=Genre;
-
}
-
return Genre;
-
} // end method getGenre
-
-
//set value of Dvd
-
public void setValue (double value)
-
{
-
return Value;
-
} // end method getValue
-
-
// set restocking fee
-
public void setRestockingFee(double restockingfee)
-
{
-
resstockingFee = (value * 5%)
-
} // end method setRestockingFee
-
-
// return restocking fee
-
public double getRestockingFee()
-
{
-
return restockingFee;
-
} // end method getRestockingFee
-
-
// caluculate value + restocking fee
-
public double total()
-
{
-
return restockingFee * Value;
-
} // end method total
-
This is what I have to do modify the inventory program by creating a subclass of product class that uses one additional unique feature of the product you choose (for the DVDs subclass you could use movie title, for example). 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. This is what I have so far can I get some help with a few errors? -
public class inventorysubclass extends inventorysupplys2{
-
-
protected String Title;
-
protected string Genre;
-
protected double value;
-
protected double restockingfee;
-
-
// four-argument contructor
-
public Title (String Title, String Genre, String Genre, double value, double restockingfee)
-
{
-
//implicit call to DVD contructor occurs here
-
Title = Title;
-
Genre = Genre
-
setValue(value); //validate value of DVD
-
setRestockingFee(rate); //validate and store restocking fee
-
} // end four-argument MoviteTitle contructor
-
-
// set title
-
public void setTitle(String first)
-
{
-
Title=Title;
-
} //end method setTitle
-
-
// return title
-
public String getTitle()
-
{
-
return Title;
-
} //end method getTitle
-
-
// set Genre
-
public void getGenre (String Genre)
-
{
-
Genre=Genre;
-
}
-
return Genre;
-
} // end method getGenre
-
-
//set value of Dvd
-
public void setValue (double value)
-
{
-
return Value;
-
} // end method getValue
-
-
// set restocking fee
-
public void setRestockingFee(double restockingfee)
-
{
-
resstockingFee = (value * 5%)
-
} // end method setRestockingFee
-
-
// return restocking fee
-
public double getRestockingFee()
-
{
-
return restockingFee;
-
} // end method getRestockingFee
-
-
// caluculate value + restocking fee
-
public double total()
-
{
-
return restockingFee * Value;
-
} // end method total
-
Yes you can get help about the errors if you tell us what the errors are.
Yes you can get help about the errors if you tell us what the errors are.
I got the errors worked out but I still can not get the restocking fee working.
I got the errors worked out but I still can not get the restocking fee working.
Now that you realise that a void method should not return anything, explain then what you mean by can not get the restocking fee working.
Now that you realise that a void method should not return anything, explain then what you mean by can not get the restocking fee working.
I need to add a restocking fee of 5% to this inventory program. I can not seem to get the coding for it right.
I need to add a restocking fee of 5% to this inventory program. I can not seem to get the coding for it right.
Where are you not getting it right?
If you have the complete program you are testing with, post the code, tell us what you are getting as output and what you want to have as output, then you will get your solution quicker.
Where are you not getting it right?
If you have the complete program you are testing with, post the code, tell us what you are getting as output and what you want to have as output, then you will get your solution quicker.
this is what i have and i can not seem to get the re-stocking fee to work. can i please get some help fixing this. thanks Sign in to post your reply or Sign up for a free account.
Similar topics
by: Frank Millman |
last post by:
Hi all
I have a question regarding inheritance. I have come up with a
solution, but it is not very elegant - I am sure there is a more
pythonic approach. Assume the following class definitions....
|
by: Gerry Sutton |
last post by:
Hi All!
I have noticed a strange behavior when using a constant identifier to
initialize an instance list variable in a base class and then trying to
modifying the list in subclasses by using...
|
by: Larry Lard |
last post by:
Today I discovered that a syntax that I thought was forbidden in C# but
allowed in VB.NET (and I _don't like_ that it's allowed in VB.NET) is
actually allowed in C#. Which confused me. The syntax...
|
by: Lou Pecora |
last post by:
I've been scanning Python in a Nutshell, but this seems to be either
undoable or so subtle that I don't know how to do it.
I want to subclass a base class that is returned from a Standard Library...
|
by: s.lipnevich |
last post by:
Hi All,
Is anything wrong with the following code?
class Superclass(object):
def __new__(cls):
# Questioning the statement below
return super(Superclass, cls).__new__(Subclass)
class...
|
by: damacy |
last post by:
hi, there. i have a problem writing a program which can obtain ip
addresses of machines running in the same local network.
say, there are 4 machines present in the network; , , and
and if i...
|
by: Me |
last post by:
I need to be able to acces non-virtual members of sublcasses via a
base class pointer...and without the need for an explicit type cast.
I thought a pure virtual getPtr() that acts as a type cast...
|
by: Kurt Smith |
last post by:
Hi List:
Class inheritance noob here.
For context, I have the following base class and subclass:
class Base(object):
def __init__(self, val):
self.val = val
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |