Question
by java langage
QI A small online grocery store sells fruits with the following prices: Apple, 1.500 KWD; Orange, 0.700 KWD; Banana, 1.000 KW
0 0
Add a comment Improve this question Transcribed image text
Answer #1

BillCalc.java

import java.util.*;
class BillCalc{
   public static void main(String[] args) {
       Scanner s=new Scanner(System.in);//scanner declarations
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter Fruit name followed by quantity sold\n");
       String fn;
       int q=0;
       double p=0,tot=0;
       do{//iterating till termination condition reached
           System.out.println("Price list\n1.apple-1.5000 KWD\n2.orange-0.7000 KWD\n3.banana-1.000 KWD\n4.peach-2.5000 KWD\n5.melon-1.750 KWD\n");
           System.out.println("Enter Fruit name('end' to end)");

           fn=s.nextLine();//reading fruit name
           if(fn.equals("end"))
               break;//if 'end' received initially
           System.out.println("Enter quantity");
           q=sc.nextInt();//reading quantity of fruits
           switch(fn){//switch case to decide the fruit price
               case "apple" : p=1.500;
                               break;
               case "orange" : p=0.700;
                               break;
               case "banana" : p=1.000;
                               break;
               case "peach" : p=2.500;
                               break;
               case "melon" : p=1.750;
                               break;
               default    :p=0;
           }

       tot+=q*p;
       }while(fn!="exit");
       //printing the total
       System.out.printf("Total bill is %.03f",tot);

   }
}

output:

please take care while providing the fruit name as it is case sensitive.

2)Draw.java

import java.util.*;
class Draw{
   public static void drawRectangle(int l,int w){
       for (int i=0;i<w; i++ ) {//
           for (int j=0;j<l ;j++ ) {
               if(i==0 || i==w-1)
                   System.out.print("*");//first row or last row  
               else if(j==0 || j==l-1)
                   System.out.print("*");//first column or last column
               else
                   System.out.print(" ");//else case      
           }
           System.out.print("\n");
          
       }
   }
   public static void main(String[] args) {
       Scanner s=new Scanner(System.in);//scanner declaration
       System.out.println("Enter the length:");
       int l=s.nextInt();//reading leangth
       System.out.println("Enter the width: ");
       int w=s.nextInt();//reading width
       drawRectangle(l,w);//method call

   }
}

output:

Add a comment
Know the answer?
Add Answer to:
by java langage QI A small online grocery store sells fruits with the following prices: Apple,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A mail order house sells five different products whose retail prices are: product 1: $2.98 product...

    A mail order house sells five different products whose retail prices are: product 1: $2.98 product 2: $4.50 product 3: $9.98 product 4: $4.49 product 5: $6.87. Write a program that reads a series of pairs of numbers as follows: a) product number b) quantity sold Your program should use a switch statement to determine the retail price for each product. Your program should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to...

  • ******** IN JAVA ********* I have a program that I need help debugging. This program should...

    ******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • Just do program 6 using c++ which are printf and scanf. Please don’t use cout and...

    Just do program 6 using c++ which are printf and scanf. Please don’t use cout and cin. Program 4: A slot machine has three windows. A random fruit is picked for each window from cherry apple, lemon, and orange. If all three windows match, the user wins 8 times the bet amount. If the first two windows only are cherries, the user wins 3 times the bet amount. If the first window is a cherry and the second window is...

  • java

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here.   Step 1Develop the following class:ClassName: CollegeDegreeAccess Modifier: publicInstance variablesName: majorAccess modifier: privateData type: StringName: numberOfCoursesAccess modifier: privateData type: intName: courseNameArrayAccess modifier: privateData type: String [ ]Name: courseCreditArrayAccess modifier: privateData type: int [ ]Static variablesName: maximumNumberOfCoursesAccess modifier: privateData type: intInitial Value: 40ConstructorName: CollegeDegreeAccess modifier: publicParameters: none...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00...

    share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00 pm submit : back to classroom run Instructions from your teacher: #include <iostream> Complete this program. using namespace std; When the program is complete it should ask the user to enter a rectangle's length and width, then display the rectangle's area. The program calls the following functions which need to be completed: double getLength() { // Add code here } double getWidth() { //...

  • Using basic c++ write a separate code for each of the following: 1. Area Rectangle •...

    Using basic c++ write a separate code for each of the following: 1. Area Rectangle • Write a program that asks the user to enter length and width of a rectangle and then display the rectangles area. • Write the following functions • getLength – prompt the user to enter length and return that value as a double • getWidth – prompt the user to enter width and return that value as a double • getArea – This method should...

  • Vle/content/731186/fullscreen/3876261/View n3x You are the owner of three small grocery stores in your city. You want...

    Vle/content/731186/fullscreen/3876261/View n3x You are the owner of three small grocery stores in your city. You want to know how much money you made last week selling pre-packaged gift boxes of fruit (a box contains just apples, oranges, pears, or plums). You purchase the fruit boxes wholesale from your distributor (apples S3.20/box, oranges $3.65/box, pears $4.00/box, plums $3.50 box). Your selling price includes a 30% markup and is rounded to the nearest dime. Note: Markup % s(selling price-cost) /cost x100 For...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT