Computers & Internet Logo

Related Topics:

Posted on May 19, 2017

USING JOPTIONPANE 1.Using a JOptionPane, write a program that converts degrees Celsius to Fahrenheit using the formula degreesC = 5(degreesF) ? 32/9. Prompt the user to enter a temperature in degrees Fahrenheit (just a whole number of degrees, without a fractional part) and print out the equivalent Celsius temperature including the fractional part to at least one decimal point. A possible dialog might be: Enter a temperature in degrees Fahrenheit: 72 72 degrees Fahrenheit = 22.2 degrees Celcius"

  • Anonymous May 11, 2010

    We don't do your homework for you.

×

2 Related Answers

Anonymous

  • 24 Answers
  • Posted on Mar 30, 2010

SOURCE: how to convert infix to postfix using stacks in

u can try the follwing coding
import java.io.*;
import java.util.*;
//begin coding for the stack interface
interface Stack<E>
{
public boolean isEmpty();//tests is current stack is empty. Returns true if so, and false if not.
public E top() throws StackException;//retrieves value at the top of the stack. Stack cannot be empty.
public void push(E value) throws StackException;//pushes a value on the top of the stack.
public void pop() throws StackException;//removes a value from the top of the stack. Stack cannot be empty.
}//terminates coding of Stack interface

//begin coding for the objArrayStack class
class objArrayStack<E> implements Stack<E>
{
//constructor
public objArrayStack()
{
topValue=-1;
}//terminates constructor
public void push(E value)throws StackException
{
if(topValue<ArraySize-1)//currrent stack is not full
{
++topValue;
Info[topValue]=value;
}//terminates if
else //current stack is full
throw new StackException("Error: Overflow");
}//terminates push method
public void pop() throws StackException
{
if(!isEmpty())//current stack is not empty
--topValue;
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates pop method
public boolean isEmpty()
{
return topValue==-1;
}//terminates isEmpty method
public E top() throws StackException
{
if(!isEmpty())//stack is not empty
return (E)Info[topValue];
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates top method
//declare instance variables
final int ArraySize=10;
private Object Info[]=new Object[ArraySize];
private int topValue;

//begins coding for the StackException class
class StackException extends RuntimeException
{
//constructor
public StackException(String str)
{
super(str);
}//terminates text of constructor
}//terminates text of StackException class

//method to convert from infix to postfix notation
public static String InToPost(String infixString)
{
//operator stack initialized
objArrayStack<Character> operatorStack = new objArrayStack<Character>();
//postfix string initialized as empty
String postfixString = " ";
//scan infix string and take appropriate action
for(int index = 0; index < infixString.length(); ++index)
{
char chValue = infixString.charAt(index);
if(chValue == '(')
operatorStack.push('(');
else if(chValue == ')')
{
Character oper = operatorStack.top();
while(!(oper.equals('(')) && !(operatorStack.isEmpty()))
{
postfixString += oper.charValue();
operatorStack.pop();
oper = operatorStack.top();
}//end while loop
operatorStack.pop();
}//end else if
else if(chValue == '+' || chValue == '-')
{
if(operatorStack.isEmpty()) //operatorStack is empty
operatorStack.push(chValue);
else //current operatorStack is not empty
{
Character oper = operatorStack.top();
while(!(operatorStack.isEmpty() || oper.equals(new Character('(')) || oper.equals(new Character(')'))))
{
operatorStack.pop();
postfixString += oper.charValue();
}//ends while loop
operatorStack.push(chValue);
}//end else
}//end else if
else if(chValue == '*' || chValue == '/')
{
if(operatorStack.isEmpty())
operatorStack.push(chValue);
else
{
Character oper = operatorStack.top();
while(!oper.equals(new Character('+')) && !oper.equals(new Character('-')) && !operatorStack.isEmpty())
{
operatorStack.pop();
postfixString += oper.charValue();
}//end while loop
operatorStack.push(chValue);
}//end else
}//end else if
else
postfixString += chValue;
}//end for loop
while(!operatorStack.isEmpty())
{
Character oper = operatorStack.top();
if(!oper.equals(new Character('(')))
{
operatorStack.pop();
postfixString += oper.charValue();
}//end if
}//end while
return postfixString ;
}//terminates text of InToPost method

public static void main(String[]args)
{
objArrayStack mystack = new objArrayStack();
System.out.println("Enter a string");
Scanner scan = new Scanner(System.in);
scan.nextLine();
String str = scan.nextLine();
InToPost(str);
}//terminates text of main method
}//terminates text of objArrayStack class

Ad

Anonymous

  • 284 Answers
  • Posted on Feb 24, 2011

SOURCE: wirte a pogram in java using for loop,that will

package com.gpt;

import javax.swing.JOptionPane;

/*
This program computes Fibonacci numbers using a recursive
method.
*/
public class Fibonacci
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Enter n: ");
int n = Integer.parseInt(input);

for (int i = 1; i {
int f = fib(i);
System.out.println("fib(" + i + ") = " + f);
}
System.exit(0);

}

/**
Computes a Fibonacci number.
@param n an integer
@return the nth Fibonacci number
*/
public static int fib(int n)
{
if (n return 1;
else
return fib(n - 1) + fib(n - 2);
}
}

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

Change from Celsius to feherenheit

There is a formula for converting Celsius to Fahrenheit temperatures.
[Celsius] times 9/5 plus 32
or
(°C) * 9/5 +32 = Fahrenheit

For example,
20 in Celsius needs to be converted,

20 * 9/5 + 32 = 68
Hence, 20 Celsius is 68 Fahrenheit.

Kudos!
0helpful
1answer

How to change F to C degrees

for fast conversion use this table:


http://www.rapidtables.com/convert/temperature/fahrenheit-to-celsius.htm

The temperature T in degrees Celsius (°C) is equal to the temperature T in degrees Fahrenheit (°F) minus 32, times 5/9:
T(°C) = (T(°F) - 32) × 5/9
or
T(°C) = (T(°F) - 32) / (9/5)
or
T(°C) = (T(°F) - 32) / 1.8
Example Convert 68 degrees Fahrenheit to degrees Celsius:
T(°C) = (68°F - 32) × 5/9 = 20 °C


Other webpages about conversion:

Fahrenheit to celsius conversion


http://www.wbuf.noaa.gov/tempfc.htm


Conversion of Temperature
0helpful
3answers

How to change from Fahrenheit to celcius

formulas and examples here

http://albireo.ch/temperatureconverter/formula.htm
0helpful
1answer

How to change from Celsius to Fahrenheit

To convert degrees C to degrees F, Multiply the Centigrade temperature by 9, then divide by 5, then add 32

Or, degrees F= (9/5 degrees C) + 32
Here's link to website which explains difference between Fahrenheit & Centigrade scales, & how to convert between them:

http://www.mathsisfun.com/temperature-conversion.html
0helpful
1answer

What is 20 celsius in farenheit

Hi jujaramirez,

Have a nice day.

Here is the formula to compute farenheit to celsius and celsius to fahrenheit:

C is Celsius
F is Farenheit C = 5/9 (F-32
F = 9/5 (C+32
Let's try converting 68 degrees Farenheit to celsius 5/9(68-32)
Step 1: 68 less 32 is 36
Step 2: 5 divided by 9 is 0.5555555555555
Step 3: multiply the repeating decimal by 36
Step 4: your solution is 20
Now, convert 20 degrees Celsius to Farenheit to check your work.
9/5C +32
Step 1: 9 divided by 5 is 1.8
Step 2: 1.8 multiplied by 20 is 36
Step 3: 36 plus 32 = 68

Hope it answers your problem.

Thank you for using fixya.

Adieh
1helpful
1answer

Wirte a pogram in java using for loop,that will print out the first 1 numbers of a fibonacii series that is:1 1 2 3 5 13 21 34 55

package com.gpt;

import javax.swing.JOptionPane;

/*
This program computes Fibonacci numbers using a recursive
method.
*/
public class Fibonacci
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Enter n: ");
int n = Integer.parseInt(input);

for (int i = 1; i {
int f = fib(i);
System.out.println("fib(" + i + ") = " + f);
}
System.exit(0);

}

/**
Computes a Fibonacci number.
@param n an integer
@return the nth Fibonacci number
*/
public static int fib(int n)
{
if (n return 1;
else
return fib(n - 1) + fib(n - 2);
}
}
2helpful
1answer

What is the formula for 32degree celcius to fahrenheit?

the formula to convert degree Celsius to Fahrenheit is
Tf = (9/5)*Tc+32; Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit

to convert 32degree Celsius to Fahrenheit is
Tf = (9/5)*32+32 = 89.6°F
1helpful
1answer

What's the formula to convert Fahrenheit to Celsius?

To convert from Fahrenheit to Celsius, use this equation:

C=(F-32) x 5/9


To convert from Celsius to Fahrenheit, use this equation:

F=(C x 9/5) + 32
Not finding what you are looking for?

189 views

Ask a Question

Usually answered in minutes!

Top Sun Computers & Internet Experts

Rob Hill
Rob Hill

Level 3 Expert

1480 Answers

k24674

Level 3 Expert

8093 Answers

Sean Wright
Sean Wright

Level 3 Expert

2045 Answers

Are you a Sun Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...