Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Simple Java (https://www.askmehelpdesk.com/showthread.php?t=776720)

  • Nov 26, 2013, 02:56 PM
    ranee
    Simple Java
    Can anyone help me in solving this problem please :


    A fruits shop sells several types of fruits each day. Write a program that reads from user several lines of input. Each line includes a fruit's name, price per kilogram (as an integer), number of kilograms sold (as an integer). The program should calculate and print the earned money of all fruits sold and fruit that achieved the largest profit.


    b. Give the exact output of your application. Provide 2 snapshots representing the exact output of 2 different inputs.
    Hint:
     You could assume that user will insert valid data
     User could stop the program via entering the word "stop" as a fruits' name.
  • Nov 26, 2013, 07:57 PM
    ma0641
    You can hardly expect someone to write YOUR program. This is a HELP desk, not a DO desk. Read the sticky on posting homework.
  • Nov 26, 2013, 08:29 PM
    ranee
    OK I will put my code

    but it's not giving the correct output I don't know where is the mistake



    public static void main(String[] args) {
    // TODO code application logic here
    Scanner input = new Scanner (System.in);
    String fruitname= " ";
    String maxfruit = " ";
    int price = 0,number=0;
    int sum=0;
    int max=0;


    System.out.print("Fruit name, " + "price in killogram, number of killogram sold: ");

    while (!fruitname.equals("stop")){

    fruitname = input.next();
    price = input.nextInt();
    number = input.nextInt();
    }
    if (fruitname.equals("stop"))
    {
    sum = sum+(price*number);
    }
    if (max<(price*number))
    {
    max = price*number;
    maxfruit = fruitname;
    }


    System.out.println("the earned money of all fruits is " + sum);
    System.out.println("fruit that achieved the largest profit is "+ maxfruit);

    }
    }
  • Nov 26, 2013, 09:04 PM
    ma0641
    I am not a code writer but if you had have posted this before you would have a much better possibility that someone could help find the issue.
  • Nov 30, 2013, 04:25 AM
    Scleros
    One thing that jumps out at me is your summation is not cumulative.

  • All times are GMT -7. The time now is 10:10 PM.