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
Discussion Topic:
hodyreva [135]

Answer:

Prevents lagging

Explanation:

This prevents the website from being slow and upto shape so those who access it dont have difficulties

7 0
2 years ago
Can i add ADSence on bangla content in blogsopt website?
Inga [223]

Answer:

I do not think you can! However, I am not sure since I mainly use Wix!!!

Explanation:

8 0
3 years ago
Write a C++ program to grade the answers to a true-false quiz given to students in a course. The quiz consists of 5 true-false q
Eddi Din [679]

The quiz program is an illustration of loops and conditional statements

  • Loops are used to perform repetition
  • Conditional statements are used to make decisions

<h3>The quiz program</h3>

The quiz program written in C++, where comments are used to explain each action is as follows:

#include <iostream>

using namespace std;

int main(){

   //This prints the instruction

   cout<<"Enter T/t for True; F/f for False\n";

   //This initializes the question

   string questions[5] = { "Q1", "Q2", "Q3", "Q4", "Q5"};

   //This initializes the correct options

   char options[5] = { 'T','T','F','F','T'};

   //This declares the user response

   char opt;

   //This initializes the score to 0

   int score = 0;

   //This loop is repeated 5 times

   for (int i = 0; i < 5; i++){

       //This prints the current question

       cout << i + 1 <<". "<<questions[i]<<"\nAnswer: ";

       //This gets the user response

       cin>>opt;

       //If the user response is correct

       if(toupper(opt) == options[i]){

           //The score is incremented by 2

           score+=2;

       }

   }

   //This prints the total score

   cout<<"Score: "<<score;

   return 0;

}

Read more about loops at:

brainly.com/question/19347842

7 0
2 years ago
PLEASE HELP TAKING TEST NOW!!! Of the following websites, the least trustworthy is one that (1 point)
Rom4ik [11]

Here's all the right answers.

1. What is the main purpose of a graphic organizer?

Answer: B

2. Which of the following website publishers would be considered an authoritative source about the cultures of ancient Mesopotamia?

Answer: C

3. Which of the following websites is the least biased?

Answer: D

4. Which of the following is true about graphic organizers?

Answer: A

5. Of the following websites, the least trustworthy is one that...

Answer: C

6 0
3 years ago
What is technology?
RideAnS [48]
A. the ability to perform a task in a short period of time using little to no energy
7 0
3 years ago
Read 2 more answers
Other questions:
  • In pre-shared key mode, a passphrase should be at least ________ characters long.
    15·1 answer
  • you install teamviewer on your workstation at home so that you can ac ess it when on the road. how can you be assured that unkno
    9·1 answer
  • Which of the following is an external hard drive
    11·1 answer
  • Programa en C
    9·1 answer
  • In a case where electrical current leakage from the circuit occurs, the GFCI would do the following:
    10·1 answer
  • What elements are needed in a workstation domain policy regarding use of antivirus and malicious software prevention tools?
    10·1 answer
  • An employee mentions that opening a large document file is taking longer than usual. The desktop support technician suspects tha
    6·1 answer
  • The letters a, e, i, o and u are the only vowels. Write a function named vowelUseDict() takes a string t as a parameter and comp
    7·1 answer
  • Select the layer of the OSI model that is responsible for reformatting, compressing, and/or encrypting data in a way that the ap
    14·1 answer
  • Kahnacademy sucksi am so mad i want to k ..<br> ill myself
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!