Need help - how to run this particular method in the main method?

Hi all,
I have a problem with methods that involves objects such as:
public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
For example this code:
import java.util.Scanner;
interface Animal {
    void soundOff();
class Elephant implements Animal {
    public void soundOff() {
        System.out.println("Trumpet");
class Lion implements Animal {
    public void soundOff() {
        System.out.println("Roar");
class TestAnimal {
    public static void main(String[] args) {
        TestAnimal ta = new TestAnimal();
        ta.get(); // error
        // doing Animal a = new Animal() is horrible... :(                   
    public static Animal get(String choice) {
        Scanner myScanner = new Scanner(System.in);
        choice = myScanner.nextLine();
        if (choice.equalsIgnoreCase("meat eater")) {
            return new Lion();
        } else {
            return new Elephant();
}Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
Thank you.

Hi paulcw,
Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
refactored:
import java.util.Scanner;
interface Animal {
    void soundOff();
class Elephant implements Animal {
    public void soundOff() {
        System.out.println("Trumpet");
class Lion implements Animal {
    public void soundOff() {
        System.out.println("Roar");
class TestAnimal {
    public static void main(String[] args) {
        Animal a = get();
    public static Animal get() {
        Scanner myScanner = new Scanner(System.in);
        System.out.println("Meat eater or not?");
        String choice = myScanner.nextLine();
        if (choice.equalsIgnoreCase("meat eater")) {
            return new Lion();
        } else {
            return new Elephant();
}The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..

Similar Messages

  • My Creative Cloud subscription has expired, and I assigned the monthly payment, but I can not open any progam creative cloud, I need help how to solve this problem

    my Creative Cloud subscription has expired, and I assigned the monthly payment, but I can not open any progam creative cloud, I need help how to solve this problem

    Carlos-
    Start by signing out and back in to see if it will see the subscription: 
    How to sign in and sign out of creative cloud (activate/deactivate)
    If the apps are installed fine and close after launch see this link:
    CC applications close immediately after launch
    If the problem is something different, please let us know the error you see or what is happening on the screen so we can advise  you on a solution
    Pattie

  • How to run this query to get the minutes between two hours?

    Hi all,
    Hope doing well,
    sir i am running one query which is:
    v_TotalHrsMin1 := LPAD((extract(minute from TO_TIMESTAMP (v_Temphrs,'HH24:mi:ss')) - extract(minute from TO_TIMESTAMP (v_Outtime1,'HH24:mi:ss'))), 2, '0');--select to_date(v_temphrs,'YYYY-MM-DD HH:mi:ss')-to_date(v_OutPunch,'YYYY-MM-DD HH:mi:ss')*1440;
    in this v_TotalHrsMin1 is number datatype and v_Temphrs is varchar2 which is storing this value: 12:00:00
    and v_Outtime1 is varchar2 which is storing 06:00:00
    now i want the minute difference between both times
    and insert into v_Totalmin1.
    but getting null value in v_totalmin1.
    thanks

    952646 wrote:
    Hi Sir,
    i used query like this: v_TotalHrsMin1 := extract(hour from time_interval) * 60 + extract(minute from time_interval) from (select to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS') time_interval from dual);That is not a query - that is a PL/SQL assignment expression. You should learn the differences between SQL and PL/SQL and how they work together ;-)
    When doing it in PL/SQL, you do not need a query at all. Why would you do a select from dual in the PL/SQL assignment.
    But you should be able to take the SQL example I gave you and write the equivalent PL/SQL code.
    We do not want to do your work for you - we want to teach you how to do it yourself.
    You should try and understand the examples we give you - not just cut-and-paste it and cry for help when you are cut-and-pasting a SQL example into PL/SQL code.
    Anyway - here's a way to do it in PL/SQL:
    declare
       v_outtime1  varchar2(8);
       v_temphrs   varchar2(8);
       v_interval  interval day to second;
       v_totalhrsmin1 number;
    begin
       v_outtime1 := '06:00:00';
       v_temphrs  := '12:00:00';
       v_interval := to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS');
       v_totalhrsmin1 := extract(hour from v_interval) * 60 + extract(minute from v_interval);
    end;
    /What's so difficult about taking my SQL example, understanding what the differenct functions do, and then write that piece of PL/SQL? ;-)

  • Hi all, I need help please to run few query one after the other...

    I understood I should do it with procedures? is it the simplest way?
    I don't know PLSQL and it was quite difficult for me to try learn it alone.
    there is a simplest way? or a good guide that able to help me?
    thanks a lot,

    Hi,
    Here's an example of a SQL*Plus script.
    Use any text editor to create a file (let's call it aug_6.sql) that contains all the statements you want to execute in order, like this:
    --      *****  Begin aug_6.sql  *****
    CREATE SEQUENCE rownum_incrementing INCREMENT BY 1 START WITH 1;
    CREATE SEQUENCE increment_order_num INCREMENT BY 1 START WITH 1000;
    Insert into orders_main(order_num,order_date,sapak_num,status) values (increment_order_num.nextval, sysdate, '12','new3');
    Insert into orders_details(row_num,order_num,item_num,quantity) values
    (rownum_incrementing.NextVal,
    ( select max(order_num) from orders_main) ,'14','40');
    Insert into delivery_main
    values (increment_del_num.nextval
    ,(select max(order_num) from orders_main)
    , sysdate
    , (select sapak_num from orders_main where order_num = ( select max(order_num) from orders_main)));
    --      *****  End aug_6.sql  *****Note that I made a lot of changes in what you posted, because there seemed to be a lot of mistakes. (See list below.)
    Once you have saved the file, you can run it in SQL*Plus by referring to the full path name of the file:
    SQL> @c:\aaa\bbb\aug_6This is very useful if you have to do the exact same thing more than once (for example, if you are going to create the same sequences and INSERT the same data in your development database, then in your test database, and finally in your production database).
    Here are a few things for you to watch:
    (a) "Query" means "SELECT statement". Use "SQL Statement" if you're talking about any kind of SQL command (including CREATE SEQUENCE and INSERT).
    (b) Every SQL statement must end with a semicolon (;) or slash (/).
    (c) Make sure single-quotes always occur in pairs.
    (d) Make sure parentheses occur in pairs, every "(" followed by a ")".
    (e) Don't use strings to refer to numbers, or vice cersa. For example, if the columns item_num and quantity in the table orders_dtails are NUMBERs, then give them NUMBER values (without quotes) like 14 and 40, not string values like '14' and '40'.
    (f) As part of a larger statement, you can simply use
    SYSDATE
    instead of the scalar sub-query
    (SELECT SYSDATE FROM dual)

  • Need help in controlling a video (play/pause) with the main play bar in Cp7.

    In a presentation, I'm doing an online ordering demo - my slide(s) have a video object, audio clip and may have various text and/or shapes that will transition from time to time. The problem being, if Pause is clicked in the main/TOC play bar, the presentation pauses but the video continues to play, until the end of that video. My video is an .f4v (I've also tried it as an .flv).
    What can i do to allow the main play bar to control the video?

    Insert as Slide video, not as Event video.  Then the playbar will also control the video.

  • Hi, I have this green mark (with pointing arrow looks like a link) on some words show on my window screen when I open a web page, I wonder if it is a virus link or such. Need help how to get rid of it. Thanks

    Hi, I have this green mark (with pointing arrow looks like a link) on some words show on my window screen when I open a web page, I wonder if it is a virus link or such. Need help how to get rid of it. Here's the example:
    WING
    GAMES
    MAJORITY
    Thanks

    If the third link you posted (the link containing the word "majority") does not look like the following then you inadvertently installed adware.
    That particular page should resemble the following:
    The word "majority" in the third paragraph should not be a link and should not have the green icon associated with it.
    To learn how this may have occurred, and how to prevent it from occurring in the future, read How to install adware
    Most so-called "news" websites are nothing more than entertainment outlets that cater to prurient interests, and contain advertisements that leave the user about three clicks away from installing junk. If you decide to frequent those websites, Safari's "Reader" feature helps minimize that exposure.
    Try it:

  • I'm trying to change my ICloud e-mail to match the one associated with the Apple ID? Can someone tell me how to do this? Seems like the phone won't accept the new one, the message states "you already have acct associated....."  (a given!!)  I need help !!

    I'm trying to change my ICloud e-mail to match the one associated with the Apple ID? Can someone tell me how to do this? Seems like the phone won't accept the new one, the message states "you already have acct associated....."  (a given!!)  I need help !!

    You made a purchase and exhausted the credit on your card before it processed. All purchases are final. Contact iTunes Store support. You need to settle up before you can purchase or download anything else.

  • Hi I am new on the Mac, I need help, how can I run my apps from my library on my Mac Pro?  All my apps I was used in my iPad, thanks guys!!!!

    Hi I am new on the Mac, I need help, how can I run my apps from my library on my Mac Pro?  All my apps I was used in my iPad, thanks guys!!!!

    The Mac OS X and iOS versions are separate products

  • Hello I Download Adobe Photoshop CC 2014 Last Night i INSTALLED it But it Crashes in 30-40 Sec After i Launch the Product Without Any Error Message I Need Help Can You Resolve This Problem i Tried Creative Cloud Sign Out Nd Sign iN But iT DidnT ReSolve My

    Hello I Download Adobe Photoshop CC 2014 Last Night
     i INSTALLED it But it Crashes in 30-40 Sec After i Launch the Product Without Any Error Message
    I Need Help Can You Resolve This Problem

    Lotfi are you receiving any error messages during the installation?  I would recommend reviewing your installation logs for errors.  Please see Troubleshoot install issues with log files | CC - http://helpx.adobe.com/creative-cloud/kb/troubleshoot-install-logs-cc.html for information on how to locate and interpret your installation log files.  You are welcome to post any specific errors you discover to this discussion.

  • Mail server not responding. Need help how to verify my account

    Mail server not responding. Need help how to verify my account

    There are instructions on this page for how to create a new account without giving credit card details (the instructions won't work with existing accounts) : http://support.apple.com/kb/HT2534
    Unless an account is created via those instructions then credit card details will need to be entered on it before the account can be used.

  • How to run WMI class.method?

    How to run Enable()/Disable() methods using Win32_NetworkAdapter class?
    Method link: http://msdn2.microsoft.com/en-us/library/aa390385(VS.85).aspx
    This only part of solution. http://forums.ni.com/ni/board/message?board.id=170&message.id=165837&query.id=73951#M165837
    Thanks.

    You should be able to do this using a .vbs script and labview.
    See this thread for some .vbs examples.
    http://forums.ni.com/ni/board/message?board.id=170&message.id=144519#M144519

  • TS3798 I get this error message"your operation could not be completed" I need help figuring out why I can not access the web page.

    I get this error message"your operation could not be completed" I need help figuring out why I can not access the web page.

    amarilysfl wrote:
    "Your disk could not be partitioned. An error occurred while partitioning the disk".
    https://www.apple.com/support/bootcamp/
    If you were using Apple's BootCamp and received this message, quit it and open Disk Uility in your Applicaitons/Utilities folder.
    Select the Macintosh HD partition on the left and select Erase and Erase Free Space > Zero option and let it complete (important) this will check the spare space for bad sectors that can cause issues formatting partitions.
    Once it's completed, try creating a partiton again in BootCamp.
    If that doesn't work, then hold command option r keys down while connected to a fast internet connection, Internet Recovery should load (spinning globe) and then in that Disk Utility, select your entire internal drive and click > First Aid > Repair Disk and Permissions.
    reboot and attempt Bootcamp again.
    If you still get a error, it might be that you have OS X data on the bottom area where BootCamp partition needs to go. This would occur if you had the drive or computer for a long time or wrote a large amount of files to the drive and nearly filling it up and then reduced some, but it left traces in the area BootCamp needs to go.
    To fix this
    BootCamp: "This disc can not be partitioned/impossible to move files."
    How to safely defrag a Mac's hard drive

  • Hi, when ever I'm using 3G, on my Iphone4 sim stops working and Network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem.

    Hi, when ever I'm using 3G, on my Iphone4 sim stops working and network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem. Thanks.

    Photos/videos in the Camera Roll are not synced. Photos/videos in the Camera Roll are not touched with the iTunes sync process. Photos/videos in the Camera Roll can be imported by your computer which is not handled by iTunes. Most importing software includes an option to delete the photos/videos from the Camera Roll after the import process is complete. If is my understanding that some Windows import software supports importing photos from the Camera Roll, but not videos. Regardless, the import software should not delete the photos/videos from the Camera Roll unless you set the app to do so.
    Photos/videos in the Camera Roll are included with your iPhone's backup. If you synced your iPhone with iTunes before the videos on the Camera Roll went missing and you haven't synced your iPhone with iTunes since they went missing, you can try restoring the iPhone with iTunes from the iPhone's backup. Don't sync the iPhone with iTunes again and decline the prompt to update the iPhone's backup after selecting Restore.

  • How can I get a stripped screw out of the bottom of my iPhone?? I need help, How can I get a stripped screw out of the bottom of my iPhone?? I need help

    How can I get a stripped screw out of the bottom of my iPhone?? I need help, How can I get a stripped screw out of the bottom of my iPhone?? I need help

    Try asking at ifixit.com. The iPhone is not considered user servicable. You're not going to get much help on an Apple sponsored forum.

  • I need help in reinstalling photoshop.I do not have the original disk. How can i reinstall PS?

    I need help in reinstalling photoshop.I do not have the original disk. How can i reinstall PS?

    Which full scale version of PS do you need?  
    Nancy O.

Maybe you are looking for

  • Failure to Consolidate

    Here's the feedback I've sent to Apple: "1. I just switched back from referenced to managed images. Of about 5,000 images, 45 failed to Consolidate. Ap reported it couldn't consolidate images not found. The images are in exactly the same folder struc

  • I still cannot open a discussion in Aperture pro aps

    I so need to know how to get into the depth of aperture 3 to delete the left over files that sit there after emptying the trash. and to set up so it wont do it again Please help Thank you

  • Can't connect to the wireless server

    My iphone picks up the wireless signal at my house and gives me full bars but it says it cannot access the server. There is no password.

  • Avail. check

    i have set Avail. check in material master data to avoid negative qty in delivery creation? in other words, the delivery should not be created any more if ATP has been occupied by the previous deliveries. otherwise PGI can not be done. but these kind

  • Jax-WS - wsimport -p option (package)

    I'm using the -p option to specify a package name. The wsimport code places ALL the generated .java files in this one package. My question is: How dangerous is it to refactor some of the classes into different packages? It looks like a lot of the Jav