1 answer

6 (10 points Remember the recursive Searching algorithm Binary Search. Write a recursive method to search...

Question:

6 (10 points Remember the recursive Searching algorithm Binary Search. Write a recursive method to search for a target charac

6 (10 points Remember the recursive Searching algorithm Binary Search. Write a recursive method to search for a target character in the array and return the index location if found or -1 if it is not found. 7 a5 points 17 points cach) Write the code to create a GUI based class Temperature Converter which inherits from JFrame and implements the ActionListerner interface. public static int binary Search(char target, char( theValues, int firstIndex, int lastindex) Example: Clicked "F to C" button Example: Clicked C to F* button .. . . Temperature Converter 82.0 F - 27.78 Temperature Converter 32.0C-89.60 F FtoC COF Ftoc CtOF a. Create the constructor so that the JButtons have listeners attached, and all components are added to the appropriate JPanel. b. Create the getDoubleFromTextField method that takes in a JTextField and returns the value it contained as a double it should handle exceptions appropriately within the method. public double getDouble From TextField(JTextField jtf) throws Exception {

Answers

Code:

6)

Binary.java X Temparature Converter.java x public class Binary{ public static int binarySearch(char target,char[] theValues,i

Output:

söm3_7hing@ditt:-/Documents/Chegg/Dec/95$ javac Binary.java, som3_7hing@diff:-/Documents/Chegg/Dec/95$ java Binary The target

7)

1 3 6 TemparatureConverter.java X Binary.java // Importing required packages import java.awt.*; import java.awt.event.*; impopublic double getDoubleFromTextField(JTextField tf) throws Exception{ double value; try{ value = Double.parseDouble(tf.getTex

Output:

som3 7hing@diff:-/Documents/Chegg/Dec/95$ javac TemparatureConverter.java, s0m3 7hing@diff:-/Documents/Chegg/Dec/95$ java Tems0m3 7hing@diff:-/Documents/Chegg/Dec/95$ javac TemparatureConverter.java S0m3_7hing@diff:-/Documents/Chegg/Dec/95$ java Temp

Raw Code:

6)

public class Binary{
   public static int binarySearch(char target,char[] theValues,int firstIndex,int lastIndex){
       if (lastIndex>=firstIndex){
           int mid = firstIndex+(lastIndex-firstIndex)/2; // Finding mid value.
           if (theValues[mid] == target){ // Comparing array[mid] value and target
               return mid;
           }
           else if(theValues[mid] > target){
               lastIndex = mid -1; // Updating lastIndex
               return (binarySearch(target,theValues,firstIndex,lastIndex)); // Recursive call.
           }
           else if (theValues[mid] < target){
               firstIndex = mid + 1; // Updating firstIndex
               return (binarySearch(target,theValues,firstIndex,lastIndex)); // Recursive call.
           }
       }
       return -1;
   }
   public static void main(String[] args) {
       // Declaring variables.
       char theValues []= {'a','b','c','d','e','f','g','h','i'};
       int firstIndex = 0;
       int lastIndex = theValues.length;
       char target = 'g'; // target character.
       int result = binarySearch(target,theValues,firstIndex,lastIndex); // Calling function.
       if (result<0){
           System.out.println("The target is not present in the values array."); // If the target is not present in array.
       }
       else{
           System.out.println("The target is present at index: " + result ); // If the target is present in array.
       }
   }
}

7)

// Importing required packages
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class TemparatureConverter extends JFrame implements ActionListener{
JLabel label;
JButton button1,button2;
JTextField t1;
TemparatureConverter(){
this.setTitle("Temparature Converter"); // titile for frame
JPanel panel = new JPanel(); // Creating JPanel
panel.setLayout(null);
label = new JLabel(""); // Initially the JLable value in empty.
label.setBounds(70,20,280,30);
t1 = new JTextField(); // Creating TextField
t1.setBounds(10,80,280,35); // Setting position and heigth and width of a TextField.
button1 = new JButton("F to C"); // Setting button with Text "F to C"
button1.setBounds(50,130,90,32);
button1.setBackground(Color.white); // Setting background color to button1
button1.addActionListener(this); // Adding ActionListener to button1
button2 = new JButton("C to F"); // Setting button with Text "C to F"
button2.setBounds(170,130,90,32);
button2.setBackground(Color.white); // Setting background color to button1
button2.addActionListener(this); // Adding ActionListener to button1
// Adding all components to panel
panel.add(label);
panel.add(t1);
panel.add(button1);
panel.add(button2);
// Adding panel to frame.
add(panel);
setSize(300, 200); // Setting size of the frame.
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public double getDoubleFromTextField(JTextField tf) throws Exception{
double value;
try{
value = Double.parseDouble(tf.getText()); // Converting String to Double
}
catch (Exception e){
value = 0.0; // If an exception is raised.
}
return value; // Returning value.
}
public void actionPerformed(ActionEvent e){
try{
double value = getDoubleFromTextField(t1); // Calling function.
if(e.getSource()==button1){
double c = (5f/9) * (value - 32); // converting f to c
label.setText(String.format("%.1f F = %.2f C",value,c)); // Setting label text with the given format.
}
else if(e.getSource()==button2){
double f = value *(9f/5) + 32 ; // Converting c to f
label.setText(String.format("%.1f C = %.2f F",value,f)); // Setting label text with the given format.
}
}
catch (Exception e1){

}
}
public static void main(String[] args) {
new TemparatureConverter();
}
}

if you have any doubts ask in comment section.

.

Similar Solved Questions

1 answer
Oe) Organ of Corti Question 83 (1 point) Lipogenesis occurs when a) Less calories are consumed...
Oe) Organ of Corti Question 83 (1 point) Lipogenesis occurs when a) Less calories are consumed than required for ATP need b) More calories are consumed than required for ATP need O c) Less cholesterol is consumed than required for ATP need O d) Gluconeogenesis fails e) More cholesterol is consumed t...
1 answer
A particular standardized test has a mean score of 455 with a standard deviation of 112....
A particular standardized test has a mean score of 455 with a standard deviation of 112. A student received a z-score of 1.07 on this test. Determine the student's actual score.  Round to the nearest whole number....
1 answer
Iron reacts with oxygen to form iron(III) oxide according to the chemical equation below. What is...
Iron reacts with oxygen to form iron(III) oxide according to the chemical equation below. What is the theoretical yield of product when 5.00 grams of Fe react with excess O2? [Molar masses: Fe, 55.85 g/mol; O, 16.00g/mol]        5 pts     ...
1 answer
The three penguins Pug, Tug and Click are standing in the coordinates as indicated in the...
The three penguins Pug, Tug and Click are standing in the coordinates as indicated in the diagram (below left). Assume the penguins can be treated as point sized objects, with mass as indicated on the diagram. Calculate the coordinate of the center of mass of the system of penguins. Express your ans...
1 answer
2 page papers typed in paragraph form for an Alcoholics' Anonymous Discuss anything specific about the...
2 page papers typed in paragraph form for an Alcoholics' Anonymous Discuss anything specific about the meeting that you think is important . Do you think AA is helpfulfor people with alcoholism? If so, how is it likely to help? If not, why not? Kould you see yourself referring clients to AA? Wha...
1 answer
How would I account for these adjustments? Thanks! Problem 3-05A a-g (Part Level Submission) On November...
How would I account for these adjustments? Thanks! Problem 3-05A a-g (Part Level Submission) On November 1, 2020, the account balances of Ivanhoe Equipment Repair were as follows. No. Debits No. Credits 101 Cash $ 2,430 154 Accumulated Depreciation Equipment 112 Accounts Receivable 4,230 201 Account...
1 answer
Q7-Consider the following combination of expected return and risk for various portfolios (named A-H) on the...
Q7-Consider the following combination of expected return and risk for various portfolios (named A-H) on the risk-return diagram. Assume a risk-free rate of 12% where one may borrow or lend at this rate. Expected Return (%) Risk (%) A 10 23 B 12.5 21 C D E F G H 15 16 17 18 18 20 25 29 29 32 35 45 Sh...
1 answer
Problem 1 Identifying effects of transactions using the accounting equation Randa Abbas began a professional practice...
Problem 1 Identifying effects of transactions using the accounting equation Randa Abbas began a professional practice on June 1 and plans to prepare financial statements at the end of each month. During June, Abbas (the owner) completed these transactions: a. Owner invested $60,000 cash in t...
1 answer
The Dahlia Medical Center has 32 labor rooms, 20 combination labor and delivery rooms, and 2...
The Dahlia Medical Center has 32 labor rooms, 20 combination labor and delivery rooms, and 2 delivery rooms. All of these facilities operate around the clock. Time spent in labor rooms varies from hours to days, with an average of about a day. The average uncomplicated delivery requires about one ho...
1 answer
Your boss, the CEO of Wal Mart is interested in expanding operations into India
Your boss, the CEO of Wal Mart is interested in expanding operations into India. You have been asked to prepare a presentation for the company stakeholders that will inform them of the status of the market in India. Create a 7-12 slide presentation detailing the findings of the screening process you...
1 answer
E6-2 The yields for Treasuries with differing maturities on a recent day were as shown in...
E6-2 The yields for Treasuries with differing maturities on a recent day were as shown in the table below. Maturity 3 months 6 months 2 years 3 years 5 years 10 years 30 years Yield 1.41% 1.71 2.68 3.01 3.70 4.51 5.25 a. Use the information to plot a yield curve for this b. If the expectations hypot...
1 answer
Solve 1st one asap At a given temperature the rotational states of molecules are distributed according to the Boltzmann distribution. Of the hydrogen molecules in the ground state estimate the ratio o...
Solve 1st one asap At a given temperature the rotational states of molecules are distributed according to the Boltzmann distribution. Of the hydrogen molecules in the ground state estimate the ratio of the number in the ground rotational state to the number in the first excited rotational state at 3...
1 answer
How do you estimate the instantaneous rate of change of the function #f(x)=xlnx# at #x=1# and at #x=2#?
How do you estimate the instantaneous rate of change of the function #f(x)=xlnx# at #x=1# and at #x=2#?...
1 answer
6. Use the construction in Theorem 4.1 to find nfa's that accept (a) L ((ab) "a)...
6. Use the construction in Theorem 4.1 to find nfa's that accept (a) L ((ab) "a) nL (baa")...
1 answer
πΩ Equation S symbols Question Who wants to be a millionaire? 1. You just won st...
πΩ Equation S symbols Question Who wants to be a millionaire? 1. You just won st million dollar in the lottery! They offer you two options for your winnings: a lump sum payment right now or $100.000 a year over the next 10 years Current 10-year interest rates at 5%, and the current taxon lo...
1 answer
In a cell, the Keq for a reaction is 500. Is this a spontaneous reaction in...
In a cell, the Keq for a reaction is 500. Is this a spontaneous reaction in the cell? Okay. At first I thought it had an obvious answer because I was thinking that since Keq >> 1, deltaG would be large and negative. Then I looked at my book and saw that only deltaG0 is related to Keq through t...