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
Sometimes news organizations have biasis because
elena55 [62]
Every person has their own personal beliefs, we are all human, so sometimes the news can include biasis because someone put their personal opinion in what they say/write.
5 0
2 years ago
Which two technologies support the building of single-page applications? and are two technologies helpful in building single pag
Sholpan [36]

Answer:

You can use JavaScript, HTML, PHP and so forth.

Explanation:

7 0
3 years ago
Which function would you use to make sure all names are prepared for a mailing label? TODAY UPPER PROPER LOWER
Aleonysh [2.5K]

Answer:

Proper.

Explanation:

5 0
2 years ago
Declare a typedef struct named jumper_t that will have four parts: character array name that is 16 in length, double array of tr
Maurinko [17]

Answer:

The typedef struct is as follows:

typedef struct jumper_t {

  char name[16];

  double tries[N_TRIES];

  double best_jump;

  double deviation;

} jumper_t;

The declaration of jlist is:

jumper_t jlist[10];

Explanation:

This defines  the typedef structure

typedef struct jumper_t {

The following declares the variables as stated in the question

<em>   char name[16]; </em>

<em>   double tries[N_TRIES]; </em>

<em>   double best_jump; </em>

<em>   double deviation; </em>

}

This ends the typedef definition

jumper_t;

(b) The declaration of array jlist is:

jumper_t jlist[10];

6 0
3 years ago
Business customers pay $0.006 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0
trasher [3.6K]

Answer:

#include <bits/stdc++.h>

using namespace std;

int main()

{

   // variables

   char cust_t;

   int no_gallon;

   double cost=0;

   cout<<"Enter the type of customer(B for business or R for residential):";

   // read the type of customer

   cin>>cust_t;

   // if type is business

   if(cust_t=='b'||cust_t=='B')

   {

       cout<<"please enter the number of gallons:";

       // read the number of gallons

       cin>>no_gallon;

       // if number of gallons are less or equal to 8000

       if(no_gallon<=8000)

       {

           // calculate cost

           cost=no_gallon*0.006;

           cout<<"total cost is: $"<<cost<<endl;

       }

       else

       {

           // if number of gallons is greater than 8000

           // calculate cost

           cost=(8000*0.006)+((no_gallon-8000)*0.008);

           cout<<"total cost is: $"<<cost<<endl;

           

       }

       

   }

   

   // if customer type is residential

   else if(cust_t=='r'||cust_t=='R')

        {

           

       cout<<"please enter the number of gallons:";

       // read the number of gallons

       cin>>no_gallon;

       // if number of gallons are less or equal to 8000

       if(no_gallon<=8000)

       {

           // calculate cost

           cost=no_gallon*0.007;

           cout<<"total cost is: $"<<cost<<endl;

       }

       else

       {// if number of gallons is greater than 8000

       // calculate cost

           cost=(8000*0.005)+((no_gallon-8000)*0.007);

           cout<<"total cost is: $"<<cost<<endl;      

       }        

   }

return 0;

}

Explanation:

Ask user to enter the type of customer and assign it to variable "cust_t". If the customer type is business then read the number of gallons from user and assign it to variable "no_gallon". Then calculate cost of gallons, if  gallons are less or equal to 800 then multiply it with 0.006.And if gallons are greater than 8000, cost for  first 8000 will be multiply by 0.006 and  for rest gallons multiply with 0.008.Similarly if customer type is residential then for first 8000 gallons cost will be multiply by 0.005 and for rest it will  multiply by 0.007. Then print the cost.

Output:

Enter the type of customer(B for business or R for residential):b                                                                                            

please enter the number of gallons:9000                                                                                                                      

total cost is: $56  

4 0
3 years ago
Other questions:
  • Which key removes all data from an active cell with one click
    7·2 answers
  • Privileged instructions 1) generate an interrupt so they can execute before non-privileged instructions. 2) are valid only when
    5·1 answer
  • A circuit contains three resistors connected in series. the value of r1 is 150 , the value of r2 is 60 , and the value of r3 is
    8·2 answers
  • When a defendant pleads guilty to one offense just to have another offense dropped, this is what type of plea bargain
    12·2 answers
  • Which of the following could be defined as a general-purpose computing device that enables workers to create, manage, store, sea
    12·1 answer
  • List at least three benefits of automated testing?
    13·1 answer
  • When reading words using a Scanner object's next method, _________. a. any characters at the beginning of the input that are con
    5·1 answer
  • Which component of a word processor displays the name of the document?
    13·1 answer
  • Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to (and including) the number
    14·1 answer
  • Why is my speedtest is very good but chrome is slow
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!