Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What am I supposed to return?

  1. #1
    Junior Member
    Join Date
    Dec 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy What am I supposed to return?

    import java.util.ArrayList;
    public class CoffeeShop
    {
    private ArrayList<String> MenuArray;
    private double [] prices;

    public CoffeeShop()
    {
    MenuArray=new ArrayList<String>(); //arraylist
    MenuArray.add("0 Hot black coffee");
    MenuArray.add("1 Iced mocha latte");
    MenuArray.add("2 Iced lavendar matcha latte");
    MenuArray.add("3 Hot biscoff latte");
    MenuArray.add("4 Hot cappuccino");
    MenuArray.add("5 Breakfast sandwhich");
    MenuArray.add("6 Pumpkin muffin");
    MenuArray.add("7 Butter crossiant");
    double[] prices=new double[8]; //array
    prices[0]=2.55;
    prices[1]=5.50;
    prices[2]=8.99;
    prices[3]=6.15;
    prices[4]=4.20;
    prices[5]=4.25;
    prices[6]=3.55;
    prices[7]=2.50;
    }

    public double getMaxCost() //max for-loop
    {
    double mcost = 0;
    for (int i=0; i<prices.length; i++)
    {
    if(prices[i]> mcost)
    {
    mcost = prices[i];
    }
    }
    return mcost;
    }

    public String getMenu()
    {
    for (String menu1 : MenuArray)
    {
    System.out.println("We offer these items on our menu: " + menu1);
    {
    return ____;
    }
    }
    }
    }

    //it keeps saying I need to return something because if I don't theres an error

  2. #2
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: What am I supposed to return?

    public String getMenu()
    This line states the return type of the function getMenu is a String.

Similar Threads

  1. Isn't the result supposed to be 6?
    By obel1x in forum Java Theory & Questions
    Replies: 3
    Last Post: April 12th, 2014, 03:43 AM
  2. Replies: 1
    Last Post: July 29th, 2013, 06:22 AM
  3. Can anybody help me fix this, what I am supposed to do is at the top
    By peplo1214 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 17th, 2012, 07:05 AM
  4. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM
  5. Not sure what I'm supposed to do...
    By colerelm in forum Java Theory & Questions
    Replies: 1
    Last Post: October 3rd, 2011, 11:13 PM

Tags for this Thread