Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

35 and 36 together as one java program. preferable with flotchart, but i can mak

ID: 3604176 • Letter: 3

Question

35 and 36 together as one java program. preferable with flotchart, but i can make that.

33. Write a Java program to accept three item names and prices, and output them. Also, output the average price if one of the items is named Peas (not case sensitive) otherwise output: "no them. In addition, output the average price if one of the items is named Peas (not case sensi- Write a Java program to accept a given number of item names and prices and then output average output". 34. Write a Java program to accept an unlimited number of item names and prices, and output tive) otherwise output: "no average output". The inputs will be terminated by a sentinel price of -1. (Do not include the -1 in the average.) them in the reverse order in which they were input. In addition, output the average price if onc of the items is named Peas (not case sensitive) otherwise output: "no average output Add a static method to the program described in one of the two previous exercises that 37. Add a method to the program described in the previous excrcise that accepts and returns a (The first user input will be the number of it ems to process.) that outputs "Welcome To St. Joseph's College" before the items and prices are output. The method main should invoke this method. single item name that is input by the user. The prompt presented to the user should be po to the method as an argument.

Explanation / Answer

import java.util.Scanner;

public class Items

{

public static void Wmsg()

{

System.out.println("Welcome To St.Joseph's College");

}

public static void main(String args[])

{

Wmsg();

Scanner ip=new Scanner(System.in);

System.out.println("Enter number of Items:");

int numberOfItems=ip.nextInt();

String[] names= new String[numberOfItems];

int[] price=new int[numberOfItems];

int sum=0;

int count=0;

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

{

System.out.println("Enter Item name :");

names[i]=ip.nextLine();

System.out.println("Enter Item Price:");

price[i]=ip.nextInt();

if(names[i]=="peas")

{

sum=sum+price[i];

count++;

}

}

for(int i=names.length-1;i>=0;i--)

{

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

}

if(sum!=0)

System.out.println("Average Pea price:"+sum/count);

else

System.out.println("No average Output");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote