1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paha777 [63]
3 years ago
14

write a java program to accept three item names and prices, and output them. Also output the average price if one of the items i

s named Peas (not case sensitive) otherwise output: no average output".
Computers and Technology
1 answer:
N76 [4]3 years ago
8 0

Answer:

// program in java.

// package

import java.util.*;

// class definition

class Main

{

// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // scanner object to read input

Scanner scr=new Scanner(System.in);

 // string array

String name[] = new String[3];

 // price array

      double price[] = new double[3];

      // variable

      double sum = 0,avg;

      boolean flag = false;

      // read three name and their price

      for(int i=0;i<3;i++)

      {

          System.out.print("Enter item "+(i+1)+" name:");

          name[i]=scr.next();

          System.out.print("Enter item "+(i+1)+" price:");

          price[i]=scr.nextDouble();

          sum=sum+price[i];

          // if any name is "peas"

          if(name[i].equalsIgnoreCase("peas"))

          flag = true;

      }

System.out.println("Name and their price:");

      for(int i=0;i<3;i++)

      {

          System.out.println(name[i]+":"+price[i]);

         

      }

      // if flag is true

      if(flag)

      {

      // calculate average

          avg=sum/3;

          // print average

          System.out.println("Average price is:"+avg);

      }

      else

      System.out.println("no average output");

   

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read three name and their price from user.If any name is equal to "peas" without case sensitive then find the average of three price and print the average.If their is no name equal to "peas" then print "no average output".

Output:

Enter item 1 name:apple                                                                                                    

Enter item 1 price:20                                                                                                      

Enter item 2 name:kiwi                                                                                                    

Enter item 2 price:15                                                                                                      

Enter item 3 name:banana                                                                                                  

Enter item 3 price:20    

Name and their price:

apple:20

kiwi:15

banana:20                                                                                            

no average output

You might be interested in
Match the characteristics to the mobile operating system that it describes.
mel-nik [20]

Answer:

1. is Apple's iOS

2. is Android

3. is Microsoft

8 0
3 years ago
Select the correct answer.
BigorU [14]

Answer:

A

Explanation:

This Information involves informing the young youth about adult and mature life

5 0
3 years ago
Read 2 more answers
Why can’t I see one individual’s questions in the app through their profile, but I can see their questions on the website?
Mumz [18]

Answer:

I think thats just a software issue. i have the same problem

Explanation:

7 0
3 years ago
Read 2 more answers
How technology bacome the mode of revealing​
maria [59]

Answer:

afefdasf

Explanation:

3 0
3 years ago
What must be true before a motherboard can take advantage of the triple memory channels on the board?
sergeinik [125]

Answer:

The motherboard must be configured to accept a particular type of memory.

Explanation:

The motherboard must be configured to accept a particular type of memory, especially when dealing with multi-channel memory. On motherboard, different modes can be configured to run simultaneously . For motherboard to take advantage of  the triple memory channels on the board. You can also check the manual that came with the motherboard to know how to configure it.

7 0
3 years ago
Other questions:
  • Using a network without the network owner's permission is known as ________.
    10·1 answer
  • A media scholar is trying to find out whether internet or television political ads are more persuasive. what kind of effects is
    7·1 answer
  • Program Rock.java contains a skeleton for the game Rock, Paper, Scissors. Open it and save it to your directory. Add statements
    10·1 answer
  • The term "Cloud" refers to what option(s) below? (Select all that apply)
    13·1 answer
  • The ability to anticipate and determine upcoming driving hazards and conditions are adversely affected
    14·1 answer
  • Lisa is modifying a spreadsheet. Which view will allow Lisa to see how her changes will look when she prints the spreadsheet?
    13·2 answers
  • A newly opened law firm in Kirkland decides to create a small website that provides a brief introduction of the firm, its missio
    8·1 answer
  • If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsA
    7·1 answer
  • What is the fullform of ETA in computer term​
    15·1 answer
  • Which of the following IS an operating system? *<br> Reddit<br> Ubuntu<br> Office 365<br> Mac Pro
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!