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
Otrada [13]
3 years ago
7

Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of un

its sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows:
Computers and Technology
1 answer:
Dovator [93]3 years ago
5 0

Answer:

Follows are the code to the given question:

import java.util.*;//import package for input  

public class Main//defining a class Main  

{

public static void main(String[] arp)//defining main method  

  {

   double total=0,sub_Total=0;//defining double variable

   int Units,product_Num;//defining integer variable

   Scanner obq = new Scanner(System.in);//creating Scanner class object for input value

   System.out.print("Product: ");//print message

   product_Num=obq.nextInt();//input value

   while(product_Num>=1 && product_Num<=5)//defining loop for input value

   {

       sub_Total=0;//assign value 0 in sub_Total

       switch(product_Num)//use switch for check condition

          {

          case 1://for case 1

              {

              System.out.print("Enter No of units :");//print message

              Units=obq.nextInt();//input value

              sub_Total=Units*2.98;//calculating sub_Total value

              total+=sub_Total;//add value in total variable

              System.out.printf("Sub Total :$%.2f\n",sub_Total);//print value

          break;//use break keyword

          }

          case 2://for case 2

              {

              System.out.print("Enter No of units :");//print message

              Units=obq.nextInt();//input value

              sub_Total=Units*4.50;//calculating sub_Total value

              total+=sub_Total;//add value in total variable

              System.out.printf("Sub Total :$%.2f\n",sub_Total);//print value

          break;//use break keyword

          }

          case 3://for case 3

              {

              System.out.print("Enter No of units :");//print message

              Units=obq.nextInt();//input value

              sub_Total=Units*9.98;//calculating sub_Total value

              total+=sub_Total;//add value in total variable

              System.out.printf("Sub Total :$%.2f\n",sub_Total);//print value

          break;//use break keyword

          }

          case 4://for case 4

              {

              System.out.print("Enter No of units :");//print message

              Units=obq.nextInt();//input value

              sub_Total=Units*4.49;//calculating sub_Total value

              total+=sub_Total;//add value in total variable

              System.out.printf("Sub Total :$%.2f\n",sub_Total);//print value

          break;//use break keyword

          }

        case 5://for case 5

              {

              System.out.print("Enter No of units :");//print message

              Units=obq.nextInt();//input value

              sub_Total=Units*6.87;//calculating sub_Total value

              total+=sub_Total;//add value in total variable

              System.out.printf("Sub Total :$%.2f\n",sub_Total);//print value

          break;//use break keyword

          }

       }

  System.out.print("Product: ");//print message  

  product_Num=obq.nextInt();//input value

      }

      System.out.printf("\nOvertoal Total :$%.2f\n",total);//print total value

  }

}

Output:

Product: 1

Enter No of units :1

Sub Total :$2.98

Product: 2

Enter No of units :2

Sub Total :$9.00

Product: 3

Enter No of units :3

Sub Total :$29.94

Product: 4

Enter No of units :4

Sub Total :$17.96

Product: 5

Enter No of units :5

Sub Total :$34.35

Product: -1

Overtoal Total :$94.23

Explanation:

In this program, two double variables "total,sub_Total" and two integers "Units,product_Num" is used, in the next step,  the scanner class is used for an input value, for this, a while loop is defined that uses the switch for input value and calculate  its respective value, and use the print method to print its value.

You might be interested in
When communicating with sockets, a client process initiates a request for a connection and is assigned a port by the host comput
melamori03 [73]

Answer:

D. 80

Explanation:

By default, the port number for a web server is 80.

3 0
4 years ago
Read 2 more answers
Rajesh is considering whether to use a web app to collaborate with a group of friends on a project. What is one reason he should
vivado [14]

Rajesh might want to avoid the use of a web app for the project due to connectivity issues. Hence, one reason he might want to avoid using the Webb app is slow or poor internet connection.

Collaborating on a web application relies very heavily on network connectivity which is the what establishes the link ms allows the apllications to achieve optimum performance.

Therefore, slow internet connection is a major reason whuhe might want to avoid using a web app.

Learn more : brainly.com/question/25531734

6 0
3 years ago
Create a GUI application that allows the user to select a rate category (from a set of radio buttons), and enter the number of m
aniked [119]

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

Explanation:

Below is the Java Swing implementation of the assignment.

=========================== LongDistance.java ====================================

import java.awt.GridLayout;

import javax.swing.*;

public class LongDistance extends JFrame{

 

  /**

  *

  */

  public static float rate;

  public static float minutes;

  public static float total;

 

  LongDistance(){

     

     

      RatePanel rp = new RatePanel();

     

      MinutesPanel mp = new MinutesPanel();

     

      ButtonsPanel bp = new ButtonsPanel();

     

      this.setLayout(new GridLayout(3, 1));

     

 

     

      this.add(rp);

      this.add(mp);

      this.add(bp);

             

      this.setDefaultCloseOperation(EXIT_ON_CLOSE);

      this.setSize(250, 250);

      this.setVisible(true);

  }

 

}

============================ RatePanel.java ==================================

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.ButtonGroup;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.border.Border;

public class RatePanel extends JPanel implements ActionListener {

  /**

  *

  */

  private JRadioButton jr1, jr2, jr3;

  RatePanel(){

     

      Border panelBorder = BorderFactory.createTitledBorder("Select a Rate Category");

     

     

      jr1 = new JRadioButton("Daytime ($0.7) per minute");

      jr2 = new JRadioButton("Evening ($0.12) per minute");

      jr3 = new JRadioButton("Off-Peak ($0.05) per minute");

      ButtonGroup bg = new ButtonGroup();

     

      this.setLayout(new GridLayout(3,1));

      this.setBorder(panelBorder);

      this.setPreferredSize(new Dimension(800, 150));

     

      this.add(jr1);

      this.add(jr2);

      this.add(jr3);

     

      bg.add(jr1);

      bg.add(jr2);

      bg.add(jr3);

     

      jr1.addActionListener(this);

      jr2.addActionListener(this);

      jr3.addActionListener(this);

         

  }

  "at"Override

  public void actionPerformed(ActionEvent arg0) {

      // TODO Auto-generated method stub

     

      if(arg0.getSource() == jr1){

          LongDistance.rate = 0.07f;

      }

     

      if(arg0.getSource() == jr2){

          LongDistance.rate = 0.12f;

      }

     

      if(arg0.getSource() == jr3){

          LongDistance.rate = 0.05f;

      }

     

  }

}

=============================== MinutesPanel.java =============================

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import javax.swing.*;

import javax.swing.border.Border;

import javax.swing.event.DocumentListener;

public class MinutesPanel extends JPanel implements KeyListener{

  JTextField jt;

 

  MinutesPanel(){

      Border panelBorder = BorderFactory.createTitledBorder("Time Of Call");

     

      this.setLayout(new GridLayout(1, 2));

     

      JLabel jl = new JLabel("Minutes: ");

      jt = new JTextField();

     

jt.setBounds(50,50,150,20);

      this.setPreferredSize(new Dimension(10, 10));

      this.setBorder(panelBorder);

      this.add(jl);

      this.add(jt);

     

      jt.addKeyListener(this);

 

     

     

     

  }

  "at"Override

  public void keyPressed(KeyEvent arg0) {

      // TODO Auto-generated method stub

     

  }

  "at"Override

  public void keyReleased(KeyEvent arg0) {

      // TODO Auto-generated method stub

      if(jt.getText() != "")

          LongDistance.minutes = Float.parseFloat(jt.getText());

  }

  "at"Override

  public void keyTyped(KeyEvent arg0) {

      // TODO Auto-generated method stub

     

     

  }

 

}

============================= ButtonsPanel.java ============================

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

public class ButtonsPanel extends JPanel implements ActionListener{

  JButton calculate;

  JButton exit;

  ButtonsPanel(){

      calculate = new JButton("Calculate Charges");

      exit = new JButton("Exit");

     

      this.add(calculate);

      this.add(exit);

     

      calculate.addActionListener(this);

      exit.addActionListener(this);

     

  }

  "at"Override

  public void actionPerformed(ActionEvent arg0) {

      // TODO Auto-generated method stub

     

      if(arg0.getSource() == calculate){

                     

          System.out.println("r " + LongDistance.rate);

          System.out.println("m " + LongDistance.minutes);

         

          LongDistance.total = LongDistance.rate * LongDistance.minutes;

          JOptionPane.showMessageDialog(null, "Total Charges: " +LongDistance.total);

         

      }

     

      if(arg0.getSource() == exit){

          System.exit(0);

      }

  }

}

============================ App.java==============================

public class App {

  public static void main(String[] args) {

     

      LongDistance ld = new LongDistance();

     

  }

}

Check the output below

6 0
4 years ago
How would you define the rule of thirds?
omeli [17]
C ‘this is where you should place the
5 0
4 years ago
Terrance is looking for a storage device to be used for backup storage. The device has to have a large storage capacity and be p
alexdok [17]

Answer:

externral hard drive

Explanation:

my friend told me

6 0
3 years ago
Read 2 more answers
Other questions:
  • Which mitigation technique would prevent rogue servers from providing false ip configuration parameters to clients?
    5·2 answers
  • A virus that attaches to an executable program can do anything that the program is permitted to do.
    7·1 answer
  • While editing a film, a director feels that the actors have not enacted a particular scene well. What type of shot must the dire
    12·1 answer
  • Which tables and fields would you access to determine which book titles have been purchased by a customer and when the order shi
    15·1 answer
  • To insert text from a separate file into your Word document
    10·1 answer
  • What is binary ????????
    5·2 answers
  • Key
    6·1 answer
  • What are the possible consequences of plagiarism?
    15·1 answer
  • Sự ra đời của thương mại điện tử có tác động như thế nào đến việc quảng cáo và Marketing sản phẩm
    11·2 answers
  • Which statement best describes how the programming layer of abstraction in
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!