Question: there is acomple erorr as below in the current code: and there is also another issues: this is code as below: import javax.swing.JOptionPane; import java.util.ArrayList;

there is acomple erorr as below in the current code:

there is acomple erorr as below in the current code: and there

and there is also another issues: is also another issues: this is code as below: import javax.swing.JOptionPane; import

this is code as below:

import javax.swing.JOptionPane; import java.util.ArrayList; import java.util.Scanner; class Item { private String name; private double price; public static final double TOLERANCE = 0.0000001; public Item(String name,double price) { this.name = name; this.price = price; } public Item() { this("",0.0); } public Item(Item other) { this.name = other.name; this.price = other.price; } public String getName() { return name; } public double getPrice() { return price; } public void setName(String name) { this.name = name; } public void setPrice(double price) { this.price = price; }

public void input() { // Code to be written by student Scanner sc=new Scanner(System.in); System.out.println("Enter Name of item : "); //this.name=sc.nextLine(); System.out.println("Enter price of "+this.name+" : "); //this.price=sc.nextDouble(); } public void show() { // Code to be written by student System.out.println("Item name : "+this.name); System.out.println("Price of item : "+this.price); } public String toString() { return "Item: " + name + " Price: " + price; } public boolean equals(Object other) { if(other == null) return false; else if(getClass() != other.getClass()) return false; else { Item otherItem = (Item)other; return(name.equals(otherItem.name) && equivalent(price, otherItem.price)); } } private static boolean equivalent(double a, double b) { return ( Math.abs(a - b)

public static double Average(Item[]A) {

double sum=0.0; for(int i=0; i

public static void printItemsinReverse(Item[]A) { double sum=0.0; boolean isPeasPresent = false; for(int i=A.length-1; i>0; i--){ System.out.println("Item name : "+this.name); System.out.println("Price of item : "+this.price); if(this.name.toLowerCase().equlas("peas")){ isPeasPresent = true; } sum+=A[i].getPrice(); } if(isPeasPresent) { // in order for(int i=0; i0; i--){ System.out.println("Item name : "+this.name); System.out.println("Price of item : "+this.price); } System.out.println(sum/A.length); } }

public static void main(String[]args) { // question 5

printWelcome();

//question 1 Item A=new Item(); A.input(); A.show(); //question 2 Item []B=new Item[3]; for(int i=0; i

//question 4 and 7 ArrayList C=new ArrayList(); Scanner sc= new Scanner(System.in); String choice;int count=0; while(true) { Item D=new Item(); D.input(); C.add(D); count++; System.out.println("Want to enter more item y or n : "); choice=sc.nextLine(); if(!choice.equalsIgnoreCase("y")) break; } boolean flag1=false; for(int i=0; i

this code already answerd and l used NeatBean ID 8.2 and l complie but there is an error as the instruction below:

Using the Item class provided to you for download, write a method called input in the Item class that prompts the user for the items name and price and accepts the appropriate input from the console. Write a method called show that outputs the item information to console. Test your methods by creating a class called TestItem that contains a main method. Your main method should create a default Item object, get input from the user using the input method of the class, and then output the item to the console using the show method of the Item class.

Add a static method to the TestItem class that averages the prices from an array of type Item and returns the answer as a double. Create an array of type Item that collects the input for 3 items in a loop and uses your static method to calculate the average price. Output the items and average price to the user from the console in the appropriate format (money).

Change your Java program so that it tests to see if one of the items is named Peas (not case sensitive). Your program should only output the average that is calculated if one of the items is named Peas, otherwise it should output no average output.

Change your Java program so that it will accept a practically unlimited number of items. To accomplish this you may use an array larger than would be practical. Use 100 for array size if you choose this option. Optionally you may store your items in an ArrayList instead of an array. In either case, for the input let any negative input for the price of an Item be your sentinel value. Do not include this negative value in determining your average. You will continue to use the feature from step 3, testing if one of the items is named Peas, otherwise output no average output.

Add a static method to your Java program in the TestItem class that outputs Welcome to Tri-C in a pop-up message box before the items and prices are output. You should use the showMessageDialog method of Javas JOptionPane class for this task.

Add a static method to your TestItem class that takes an array of items and outputs them in reverse order of input. Output your items in both forward and reverse and print the average if one of the items is named Peas in your test runs.

Change your Java program so that after it produces its output, it asks users if they would like to process another group of items. The program should terminate when the user enters no (not case sensitive). Otherwise it should continue processing names and prices.

104 for (int =A . length-1; 1>0; 1--){ System. out.println (Item name:+this.name System. out.println (Price of item+this.price if ( this. name. toLowerCase ( ) . egulas peas " isPeasPresenttrue 108 109 110sum+ A[i].getPrice ) 112 113 114 115 | if(13PeasPresent) // in order for (int i-0: i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!