0

Dear all,
I have a program to code which would take several lines of input from user (a fruit name, it's price per kg and the number of kgs sold). Each seperated by a space. It would then output the total money made and the name of the fruit that made maximum sales. And, it would use sentinel "Stop" to halt the program.
Now, I know this is fairly easy to write. But, I have never used strings and I don't know where to begin. Hints?

2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by stultuske
0

this is what I have managed to write yet

import java.util.Scanner;

public class Q3_new{
    public static void main (String []a){
        Scanner input = new Scanner (System.in);
        String nameFruit= "";
        int priceFruit;
        int Profit=0 ;  
        int kgSold= 0;

               System.out.print("Please enter name of the fruit, price and kg sold");

             while (!nameFruit.equals("Stop"))
             {
              nameFruit=input.next();
              priceFruit=input.nextInt();
              kgSold=input.nextInt();
0

actually, I would write it a bit like this:

nameFruit = input.next();
while (!nameFruit.equalsIgnoreCase("Stop")){
  // read price and sold
  // add code to handle information

  nameFruit = input.next();
}

for more precise answers, you may want to clarify your question a bit further.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.