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
bija089 [108]
2 years ago
12

Import java.awt.GridLayout;

Computers and Technology
1 answer:
Vikki [24]2 years ago
8 0

Answer:

public class ConversionCalculator extends JFrame {

  private JLabel inch_Label, meter_Label, cm_Label, yard_Label;

  private JButton clear, calculate, exit;

  private JTextField inch_tf, cm_tf, meters_tf, yards_tf;

 

  public ConversionCalculator()

  {

     

      exitButtonHandler exitB;

      clearButtonHandler clearB;

      calcButtonHandler calcB;

     

      setTitle("Conversion Calculator");

      setSize(600,200);

      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     

      //The first layout we use will be 1 row with three columns

      setLayout(new GridLayout(1,3));

     

      //initialize all the components

      inch_Label = new JLabel("Inches");

      meter_Label = new JLabel("Meters");

      cm_Label = new JLabel("Centimeters");

      yard_Label = new JLabel("Yards");

      clear = new JButton("Clear");

      calculate = new JButton("Calculate");

      exit = new JButton("Exit");

      inch_tf = new JTextField("0.00");

      cm_tf = new JTextField("0.00");

      meters_tf = new JTextField("0.00");

      yards_tf = new JTextField("0.00");

 

      JPanel panel1 = new JPanel();

      panel1.setLayout(new GridLayout(2,2));

      JPanel panel2 = new JPanel();

      panel2.setLayout(new GridLayout(2,2));

      JPanel panel3 = new JPanel();

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

      panel1.add(cm_Label);

      panel1.add(cm_tf);

      panel1.add(meter_Label);

      panel1.add(meters_tf);

     

      panel2.add(inch_Label);

      panel2.add(inch_tf);

      panel2.add(yard_Label);

      panel2.add(yards_tf);

     

      panel3.add(clear);

      panel3.add(calculate);

      panel3.add(exit);

     

      add(panel1);

      add(panel2);

      add(panel3);

     

     

      exitB = new exitButtonHandler();

      exit.addActionListener(exitB);

     

      clearB = new clearButtonHandler();

      clear.addActionListener(clearB);

     

      calcB = new calcButtonHandler();

      calculate.addActionListener(calcB);

     

      setVisible(true);

  }

 

  //public static void main(String[] args)

     // {

       // new ConversionCalculator();

      //}

 

  private class exitButtonHandler implements ActionListener

  {

      public void actionPerformed(ActionEvent e)

      {

          //exits program

          System.exit(0);

      }

  }

 

  private class clearButtonHandler implements ActionListener

  {

      public void actionPerformed(ActionEvent e)

      {

          //clear button sets all text fields to 0

          inch_tf.setText("0.00");

          meters_tf.setText("0.00");

          yards_tf.setText("0.00");

          cm_tf.setText("0.00");

      }

  }

 

  private class calcButtonHandler implements ActionListener

  {

      public void actionPerformed(ActionEvent e)

      {

          double inches, yards, meters, cms;

          DecimalFormat df = new DecimalFormat("0.00");

         

          //parse strings in textbox into doubles

          inches = Double.parseDouble(inch_tf.getText());

          yards = Double.parseDouble(yards_tf.getText());

          meters = Double.parseDouble(meters_tf.getText());

          cms = Double.parseDouble(cm_tf.getText());

         

          //we check which value has been tampered with and base our conversion off this

          //because of this it is important that the user clears, or else it will do inch conversion

          if(inches != 0.00)

          {

              cms = inches * 2.54;

              meters = cms / 100;

              yards = inches / 36;

             

              cm_tf.setText(df.format(cms));

              meters_tf.setText(df.format(meters));

              yards_tf.setText(df.format(yards));

             

          }

          else if(yards != 0.00)

          {

              inches = yards / 36;

              cms = inches * 2.54;

              meters = cms / 100;

             

              cm_tf.setText(df.format(cms));

              meters_tf.setText(df.format(meters));

              inch_tf.setText(df.format(inches));

          }

          else if(meters != 0.00)

          {

              cms = meters * 100;

              inches = cms / 2.54;

              yards = inches / 36;

             

              cm_tf.setText(df.format(cms));

              inch_tf.setText(df.format(inches));

              yards_tf.setText(df.format(yards));

          }

          else if(cms != 0.00)

          {

              inches = cms / 2.54;

              yards = inches / 36;

              meters = cms / 100;

             

              meters_tf.setText(df.format(meters));

              inch_tf.setText(df.format(inches));

              yards_tf.setText(df.format(yards));

          }

      }

  }

}

Explanation:

  • Inside the action performed method, pass the strings in text box.
  • check if the value has been modified then do the relevant conversions inside the conditional statement.
  • When the user clears, it will not do to the inch conversion.
You might be interested in
Im lonellly whos down to date me
inna [77]

Answer:

I was actually just looking to help with someone's schoolwork. . .

Explanation:

5 0
2 years ago
Read 2 more answers
Extend to also calculate and output the number of 1 gallon cans needed to paint the wal. Hint: Use a math function to round up t
Crank

Answer:

Here is the Python program:

import math #import math to use mathematical functions

height = float(input("Enter wall height (feet): ")) #prompts user to enter wall height and store it in float type variable height

width = float(input("Enter wall width (feet): ")) #prompts user to enter wall width and store it in float type variable width

area = height *width #computes wall area

print('Wall area: {} square feet'.format(round(area))) #displays wall area using round method that returns a floating-point number rounded

sqftPerGallon = 350 #sets sqftPerGallon to 350

paintNeeded = area/ sqftPerGallon #computes needed paint

print("Paint needed: {:.2f} gallons".format(paintNeeded)) #displays computed paint needed up to 2 decimal places

cansNeeded = int(math.ceil(paintNeeded)) #computes needed cans rounding the paintNeeded up to nearest integer using math.ceil

print("Cans needed: {} can(s)".format(cansNeeded)) #displays computed cans needed

colorCostDict = {'red': 35, 'blue': 25, 'green': 23} #creates a dictionary of colors with colors as key and cost as values

color = input("Choose a color to paint the wall: ") #prompts user to enter a color

if color in colorCostDict: #if the chosen color is present in the dictionary

    colorCost = colorCostDict.get(color) #then get the color cost from dictionary and stores it into colorCost using get method that returns the value(cost) of the item with the specified key(color)

    cost = cansNeeded * colorCost #computes the cost of purchasing paint of specified color per cansNeeded

  print("Cost of purchasing {} paint: ${}".format(color,colorCostDict[color])) #displays the real cost of the chosen color paint

print("Cost of purchasing {} paint per {} gallon can(s): ${}".format(color,cansNeeded, cost)) #displays the cost of chosen color paint per cans needed.

Explanation:

The program first prompts the user to enter height and width. Lets say user enter 20 as height and 50 as width so the program becomes:

Wall area computed as:

area = height *width

area = 20 * 50

area = 1000

Hence the output of this part is:

Wall area: 1000 square feet                                                                                                                     Next program computes paint needed as:

paintNeeded = area/ sqftPerGallon

Since sqftPerGallon = 350 and area= 1000

paintNeeded = 1000 / 350

paintNeeded = 2.86

Hence the output of this part is:

Paint needed: 2.86 gallons

Next program computes cans needed as:      

cansNeeded = int(math.ceil(paintNeeded))

This rounds the computed value of paintNeeded i.e. 2.86 up to nearest integer using math.ceil so,

cansNeeded = 3                                                                  

Hence the output of this part is:

Cans needed: 3 can(s)                                                                                                                            Next program prompts user to choose a color to paint the wall

Lets say user chooses 'blue'

So the program get the cost corresponding to blue color and multiplies this cost to cans needed to compute the cost of purchasing blue paint per gallon cans. So

cost = cansNeeded * colorCost

cost = 3 * 25

cost = 75

So the output of this part is:

Cost of purchasing blue paint per 3 gallon can(s): $75                                                                                        The screenshot of the program along with its output is attached.

5 0
2 years ago
In “Plugged In,” the author’s purpose is to persuade. Which of the following quotes from the text shows that the author’s purpos
lisabon 2012 [21]

The quote from the text that shows that the author’s purpose is to persuade is D. Critics say that kids stare at computers and TVs all day and do not get enough exercise. The facts stand in counterpoint to this belief.

An argumentative writing prompt is written in order to convince the readers about a particular issue.

According to the author, the fact that children are involved in watching movies, playing games, listening to music, etc doesn't mean that they can't still be productive.

There are some critics that believe that kids stare at computers and TVs all day and do not get enough exercise. This was countered by the author who stated that kids can still engage in exercises or do other productive things.

Read related link on:

brainly.com/question/24861556

3 0
2 years ago
You just got a shipment of 10 network-attached laser printers. You want these printers to always have the same address but you w
love history [14]

Answer:

Configure Reservations

Explanation:

The reason you do this, is because you are getting a permanent IP address assignment.

Hope this helps!

6 0
3 years ago
Which html attributes are required in the image () element - check as many as apply
kotykmax [81]

Answer:

The correct answer for the given question is option(3) i.  src.

Explanation:

In HTML if we insert a image on the screen we use<img> tag

the img have following attribute

1.src

2.height.

3 alt

4 width

The required attribute in img tag is src i.e source or path of image

The following are the syntax of image tag

<img src=" path of image" alt="not visible"  height="100px" width="100px"/>

The height and width attribute describe the height and width of image in pixel.

The alt attribute is not mendatory attribute in image tag.The alt attribute display the message when image is not visible in the web page .

All the other attribute like alt,height,width are used as per the requirement but src is an required attribute .

so the option(3) is correct.

6 0
2 years ago
Other questions:
  • Categorize the following relationships into generalization, aggregation, or association. Beware, there may be n-ary associations
    14·1 answer
  • Select all that apply. Given the following code fragment, which of the things shown below happen when the statement on line 8 ex
    13·1 answer
  • Based on the passage​ and/or drawing on your prior​ knowledge, you realize that an HMO is​ what?
    9·1 answer
  • After you post a video of yourself defacing school property You can likely expect that
    11·2 answers
  • Hackers who gain control over several computers can organize them into a client-server network known as a(n) __________ . This n
    7·1 answer
  • How many megapixels is in a macbook air 2017 camera
    10·1 answer
  • if a second system failure occurs while the first recovery is in progress, what needs tobe done after the system recovers for th
    11·1 answer
  • Lab Goal : This lab was designed to demonstrate the similarities and differences in a for loop and a while loop.Lab Description
    9·1 answer
  • Explain set associative mapping<br>​
    10·1 answer
  • Write the following short piece of code in python:
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!