Question

In: Computer Science

Please create a Java Eclipse code and show output and explanation. MUST USE EXCEPTION! Step 1....

Please create a Java Eclipse code and show output and explanation.

MUST USE EXCEPTION!

Step 1. Ask users how much money was spent on an orange.

Step 2. Then ask the user how many oranges they purchased

Step 3. Lastly calculate the price for each orange purchased.

Solutions

Expert Solution

package cost;
import java.util.*;//for use of scanner funtion

public class Orange {
   public static void main(String[] args) {
           try//may throw exception
           {
           Scanner sc=new Scanner(System.in);//creating object for scanner
           System.out.println("Enter total cost of all oranges:");
           double cost=sc.nextDouble();//taking cost
           System.out.println("Enter no.of oranges purchase:");
           double item=sc.nextDouble();//taking the no.of items
           double each=cost/item;//calculating the each orange price
           if(item<=0 || cost<=0.0)//throw arthimetic exception
               throw new ArithmeticException("please enter valid input");
      
           System.out.println("each orange price is:"+each);//displaying each orange price
           }

           catch(Exception e)//handling exception
           {
              
               System.out.println("exeception is: "+e);
           }
  
   }
}


Related Solutions

PLZ USE ECLIPSE JAVA and show output with explanation The object of this assignment is to...
PLZ USE ECLIPSE JAVA and show output with explanation The object of this assignment is to construct a mini-banking system that helps us manage banking data. Notice that you can copy and paste your code from previous assignments. This assignment asks you to allow read from/write to file, as well as search and sorting algorithm. The object of this assignment is to construct a mini-banking system that helps us manage banking data. This assignment asks you to allow read from/write...
This question is about java program. Please show the output and the detail code and comment...
This question is about java program. Please show the output and the detail code and comment of the each question and each Class and interface. And the output (the test mthod )must be all the true! Thank you! Question1 Create a class Animal with the following UML specification: +-----------------------+ | Animal | +-----------------------+ | - name: String | +-----------------------+ | + Animal(String name) | | + getName(): String | | + getLegs(): int | | + canFly(): boolean | |...
PLZ USE JAVA ECLIPSE AND EXPLAIN Create a GUI which works as an accumulator:  There...
PLZ USE JAVA ECLIPSE AND EXPLAIN Create a GUI which works as an accumulator:  There is a textfield A which allows user to enter a number  There is also another textfield B with value start with 0.  When a user is done with entering the number in textfield A and press enter, calculate the sum of the number in textfield B and the number user just entered in textfield A, and display the updated number in textfield...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1478) at Main.main(Main.java:34) Your output Welcome to the food festival! Would you like to place an order? Expected output This test case should produce no output in java import java.util.Scanner; public class Main {    public static void display(String menu[])    {        for(int i=0; i<menu.length; i++)        {            System.out.println (i + " - " + menu[i]);...
Create a java program that: - Has a class that defines an exception -Have that exception...
Create a java program that: - Has a class that defines an exception -Have that exception throw(n) in one method, and be caught and handled in another one. -Has a program that always continues even if incorrect data is entered by the user -has a minimum of 2 classes in it
Create a JAVA code program: Huffman code will be converted to its text equivalent Output an...
Create a JAVA code program: Huffman code will be converted to its text equivalent Output an error message if the input cannot be converted I can give an thumbs up! :)
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
In an eclipse or blues compatible code, please create a class named Items including the described...
In an eclipse or blues compatible code, please create a class named Items including the described methods (replace and delete0 Write the following static method: /** Replaces each occurrence of an oldItem in aList with newItem */ public static void replace(ArrayList<String>aList, String oldItem, String newItem) Write the following static method: /**Deletes the first occurrence of target in aList*/ public static void delete(ArrayList<String>aList, String target)
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create...
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create your own user defined exception, COMMENT it well, and add code so that it is thrown.
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT