Ask Experts Questions for FREE Help !
Ask
    ranee's Avatar
    ranee Posts: 2, Reputation: 1
    New Member
     
    #1

    Nov 26, 2013, 02:56 PM
    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.
    ma0641's Avatar
    ma0641 Posts: 15,675, Reputation: 1012
    Uber Member
     
    #2

    Nov 26, 2013, 07:57 PM
    You can hardly expect someone to write YOUR program. This is a HELP desk, not a DO desk. Read the sticky on posting homework.
    ranee's Avatar
    ranee Posts: 2, Reputation: 1
    New Member
     
    #3

    Nov 26, 2013, 08:29 PM
    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);

    }
    }
    ma0641's Avatar
    ma0641 Posts: 15,675, Reputation: 1012
    Uber Member
     
    #4

    Nov 26, 2013, 09:04 PM
    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.
    Scleros's Avatar
    Scleros Posts: 2,165, Reputation: 262
    Hardware Expert
     
    #5

    Nov 30, 2013, 04:25 AM
    One thing that jumps out at me is your summation is not cumulative.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Alex invested $6000, part at 6% simple interest and part at 4% simple interest for a [ 1 Answers ]

2880 & 4320 are amounts of interest acrued, but I'm stuck on the last part of the question:"....if each account earned the same interest?"

Non simple answers to simple Yes/no questions. [ 18 Answers ]

Not knowing exactly where to put this, I'll try relationships: Alult male son and elderly mother. I'll start by an example: It's bedtime and, the kitchen light is currently on and her pills are usually on the kitchen table. Son asks, "Mom, do you need to come back into the kitchen?" ...


View more questions Search