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
Which directive is used when defining 64-bit IEEE long reals?
Taya2010 [7]

Answer:

The answer is "Option b".

Explanation:

In the project of IEEE-754 to define 64 -bit we require a REAL8 double precision that is equal to 8 bytes and 64 bit, and it is also used for floating-point arithmetic, and other options were not correct that can be described as follows:

  • In option a, REAL4 is used to define 32-bit, that's why it is not correct.
  • In option c, This type of declaration is not valid in IEEE, that's why it is wrong.
  • In option d, The REAL is a keyword that is used to define a value but in this, there is no value to define, that's why it is wrong.

7 0
3 years ago
The _____________ controls the internal operations of the computer's hardware, manages all of the devices connected to the compu
Nitella [24]

Answer:

The System Software (Operating System)

Explanation:

Examples of Operating Systems are Windows, MAC and Linux, these software are the foundation of every PC and manages all computer's resources

6 0
3 years ago
What is the difference between a prefix and postfix in Java?
Doss [256]

Answer:

prefix comes first

Explanation:

pre means before, and post means after.

7 0
3 years ago
Chip is examining data regarding the age at which people got married. He notices that in a number of cases people were reported
erastova [34]

Answer:

Data Cleaning

Explanation:

According to my research on data management, I can say that based on the information provided within the question what Chip is doing is an example of Data Cleaning. This term refers to the process of finding errors within sets of data and correcting or removing them from the set, or even the database entirely, this includes any data that may be inaccurate to completely wrong.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

6 0
4 years ago
Introduction to numbering system
kirill115 [55]
What about it? I need more details
7 0
3 years ago
Other questions:
  • Which of the following BEST represents the relationship between physical fitness and exercise?
    6·1 answer
  • WHAT BIRD IS SHOWN ON THE ARM OF BLOODHOUND?
    13·2 answers
  • One of the earlier applications of crypto-graphic hash functions was the storage of passwords to authenticate usersin computer s
    13·1 answer
  • You have just used a command that produced some interesting output on the screen. You would like to save that information into a
    10·1 answer
  • The primary benefit to the use of overlays in animation is that animators are able to
    12·2 answers
  • You receive an e-mail that seems to come from your bank. Clicking on a link in the message takes you to a website that seems to
    8·2 answers
  • 3.4 lesson practice quiz edhesive
    11·1 answer
  • How do I give Brainliest?? I'll give brainliest...
    13·2 answers
  • (Correct Answer Recieves Brainliest)
    8·2 answers
  • When a derived class method has the same name as a base class method, it is often said that the derived class method ________ th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!