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

Please use Java Eclipse and show code/output Please create a program that determines when a good...
Please use Java Eclipse and show code/output Please create a program that determines when a good day to go to the beach is. Please use the users input and its returning output. If the weather is 70 degree or greater, the program should say yes it is a good day to go If the weather is less than 70 degrees to say no the weather is not a good day to go
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 | |...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
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]);...
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...
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)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT