Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:05+00:00 2026-05-26T16:56:05+00:00

I have this homework. And I am beginner C# program, and now learn the

  • 0

I have this homework. And I am beginner C# program, and now learn the C# and Java

Homework: Write static method that get a Drink[] array, where the AlcoholDrink has got different alcohol values. The method returns an array containing the three highest alcohol value! If it is not so much AlcoholDrink in the array, the method is returning a null reference!

I have tried write this method, but it not work correctly…

Cause at the sz[1] = (AlcoholDrink)t[1]; it is a Drink object (non-alcohol), I don’t understand why it is there…

Or maybe my Compare method is not perfect, maybe there is the mistake… How can I aim, the non AlcoholDrink objects (Drink Objects) go to the end of the array?

Here my C# code:

    class DrinkComparer : IComparer<Drink>
    {
        public int Compare(Drink x, Drink y)
        {
            // AlcoholDrink class is children of Drink class
            if (x is AlcoholDrink && y is AlcoholDrink)
            {
                AlcoholDrink a = (AlcoholDrink)x;
                AlcoholDrink b = (AlcoholDrink)y;
                double aAlk = a.GetValueOfAlcohol; 
                double bAlk = b.GetValueOfAlcohol;
                if (aAlk > bAlk)
                    return -1;
                else if (aAlk < bAlk)
                    return 1;
                else
                    return 0;
            }
            // Drink objects haven't got GetValueOfAlcohol method...
            // How can I aim, the non AlcoholDrink objects (Drink objects) go to the end     array?
            else
                return 1;                
        }
    }
    static AlcoholDrink[] Largest3AlcoholDrink(Drink[] t)
    {
        Array.Sort(t, new DrinkComparer());
        AlcoholDrink[] sz = new AlcoholDrink[3];
        sz[0] = (AlcoholDrink)t[0];
        sz[1] = (AlcoholDrink)t[1];
        sz[2] = (AlcoholDrink)t[2];
        return sz;
    }
        AlcoholDrink sz = new AlcoholDrink( "Kékfrankos" , "0.75 l", 1500, 4.5);
        Console.WriteLine(sz);

        Drink[] t = new Drink[8];
        t[0] = new AlcoholDrink("Kék Portói", "0.75 l", 1200, 20.5);
        t[1] = new Drink("Tocsik", "0.75 l", 1100); // Non Alcohol Drink
        t[2] = new AlcoholDrink("Tokaji Asszú", "0.75 l ", 1600, 14.5);
        t[3] = new AlcoholDrink("Egri Bikavér", "0.75 l", 1500, 23.5);
        t[4] = new Drink("Egri Szamóca", "0.75 l", 1100); // Non Alchol Drink
        t[5] = new AlcoholDrink("Egri Merlot", "0.75 l", 1700, 18.5);
        t[6] = new AlcoholDrink("Egri Medina", "0.75 l", 900, 16.5);
        t[7] = new AlcoholDrink("Törley Talisman", "0.75 l", 750, 4.5);
        Console.WriteLine(DrinkKeres( t, "Egri Bikavér"));

        Largest3AlcoholDrink(t);

        Console.ReadLine();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:56:05+00:00Added an answer on May 26, 2026 at 4:56 pm

    Problem is here:

            // Drink objects haven't got GetValueOfAlcohol method...
            // How can I aim, the non AlcoholDrink objects (Drink objects) go to the end     array?
            else
                return 1;
    

    You want non alcoholic drinks to go the end, but this will return 1 even if one of the drinks is alcoholic. Do this:

    else if (x is AlcoholicDrink) return -1;
    else if (y is AlcoholicDrink) return 1;
    else return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck with this Java homework question: Write a new method, Refund, that simulates
I know that I am missing something simple here. I have got this homework
FYI This is homework. I have to build a Java Chat server. I have
Hi i am a beginner, and I have this homework for my beginning C
I have this homework that I gotta finish, but then something about it is
This is not homework. I am a beginner (novice) java programmer, trying to read
First of all this is homework. I have been trying to get rid of
(this is indirectly a part of a much larger homework assignment) I have something
I have this code in jQuery, that I want to reimplement with the prototype
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.