|
|
|
|
New Member
|
|
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.
|
|
|
Uber Member
|
|
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.
|
|
|
New Member
|
|
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);
}
}
|
|
|
Uber Member
|
|
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.
|
|
|
Hardware Expert
|
|
Nov 30, 2013, 04:25 AM
|
|
One thing that jumps out at me is your summation is not cumulative.
|
|
Question Tools |
Search this Question |
|
|
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,...
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
|