Formatting Decimals (Two Temperature Values)
Jan 30, 2015
I'm trying to format two temperature values using String.format.
return String.format("% 5.1f", temperature) + 'u2109' + " / " + String.format("% 5.1f", temperature2) + 'u2109';
I need all of that to be combined into a single String.format and include the / and unicode symbols for degree fahrenheit. How String.format works so that I can figure out how to achieve that? I've tried a few websites but none of them explain it to the extent that I need to use it.
View Replies
ADVERTISEMENT
Oct 21, 2014
How do i format a JTable of integer values to display commas after every third value like numbers should be displayed?
View Replies
View Related
May 25, 2014
I have tried as much as I can to place code to give me only two decimals in answers but cannot get it to work not sure if placement or syntax.This is code so far and it works but gives answers to 8 decimals.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
[code]...
View Replies
View Related
Mar 31, 2015
My program is supposed to operate on decimals because it concerns volume of packagings. I learnt that what normally is simple arithmetic (100 cm × 75 cm × 60 cm = 0.45 m³) in Java gives only approximate value (something like 0.44(9) m³ in this case). That's close enough so I probably shouldn't worry, but the thing is that although for one packaging the difference is barely visible—if at all—for thousands of packagings it'll make a difference. It'll be worse when I get to counting money.
I found two solutions:
1) Using integers and so-called decorative decimal point on display. I have a bad feeling about this, though.
2) Using BigDecimal.
Now, BigDecimal seems like a nice solution. I tried it and so far it looks okay. But just look at an excerpt from my program that I had to re-write (previously it looked perfectly fine as a single line):
volume = dimensions
.get("Length").multiply(dimensions.get("Width")
.multiply(dimensions.get("Height")))
.divide(new BigDecimal("1000000"));
I'm using a HashMap to store dimensions. I figured it'd make it easy for me to manage and display data later on.
View Replies
View Related
Jul 29, 2014
I have made a program that is supposed to convert roman numerals to decimals. It is NOT supposed to convert decimals to roman numerals. The only problem it seems there is with the program is that it only adds and does NOT subtract. This causes some roman numeral conversions to be flawed. What can I try to fix this. Keep in mind that the reason some methods exist is because the directions for the code say that I have to make it this way.
Instructions:
Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class called Roman. An object of type Roman should be able to do the following:
1) Store the number as a Roman numeral.
2) Convert and store the number into decimal.
3) Print the number as a Roman numeral or decimal number as requested by the user. (Be sure to over-ride the toString function).
4) Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal number.
5) Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.
This is what I have so far. It compiles and there are no errors, but it does not subtract I from X, or I from V and so on. For example,CMXLVII should be 947, but the program outputs 1067.
import javax.swing.*;
import java.util.*;
public class Roman{
private String roman;
private int decimal;
public int romanToDecimal(String s)
[Code] .....
View Replies
View Related
May 20, 2014
I'm currently working on a loan calculator... The only problem I'm having is occasional values that have very long decimals... How do I round the decimals?
View Replies
View Related
Oct 1, 2014
I am making a small program that converts meters to feet. I want my answer to be printed with 2 decimals, but I am struggle. This is my current code, any takes on what needs to be changed and why?
import java.util.Scanner;
import java.text.DecimalFormat;
public class Chapter2PE3 {
public static void main (String[]args){
Scanner input = new Scanner (System.in);
[Code] ....
View Replies
View Related
May 4, 2015
I am having calculation issues converting Fahrenheit to Celsius. The Celsius to Fahrenheit is working properly.
private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {
int tempFahr = (int)((Double.parseDouble(tempText.getText()))
* 1.8 + 32);// Calculate Fahrenheit to Celsuis:
fahrenheitLabel.setText(tempFahr + "Fehrenheit");
}
[code]...
View Replies
View Related
Apr 24, 2014
Write a program that will provide temperature conversions between degrees Fahrenheit and degrees Celsius. Provide a method that will take an argument representing a temperature in Fahrenheit degrees and return the equivalent temperature in degrees Celsius. Also provide a method that will take an argument representing a temperature in degrees Celsius and return the equivalent temperature in degrees Fahrenheit. Conversion formulas are as follows: F = 9./5. * C + 32, C = 5./9. * ( F - 32 ), where F = Fahrenheit temperature and C = Celsius temperature. You must prompt for input using the Input class methods that are provided as a download for this unit.
I have two questions, 1st is why won't I get an output from my program when I run it? 2nd is how do I prompt for input using the Input class methods downloaded? The downloaded files are in .class form, and won't show any output when I run them.My code is:
import java.util.*;
public class temp
{
public static void main ( String [] args )
{
Scanner in = new Scanner(System.in);
[code]...
View Replies
View Related
Nov 19, 2014
I am trying to write a code that asks the user to enter a temperature for each day of the week and then it prints out the high temperature, the low temperature, and the average temperature. This is the code I have so far:
import java.util.*;
import java.text.DecimalFormat;
public class Lab10 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
int high, low, i, sum;
double avg;
[Code] ....
There are a few issues that I am having.
1. I can't for the life of me figure out how to make it print the low temperature
2. I had it running perfectly until I changed one thing and now I get a compile error saying that the last 5 statements are unreachable. (lines 32-37)
View Replies
View Related
Apr 21, 2015
I'm having trouble getting the text entered in my JTextField to be converted to the conversion formula. The line I'm getting error in is:
String text = text.getText();
Also I created another JTextField in which I want the answer to be displayed in, but I'm not too sure how to go about that.
This is my attempt at it, but it doesn't work because it doesn't make sense;
result.setText1(Integer.toString(celsius));
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TempConversion extends JFrame
{
private final JLabel ask;
private final JLabel result;
private final JTextField text;
private final JTextField text1;
[code]....
View Replies
View Related
Apr 21, 2014
This program will not give me the average high temperature for the week and I cannot figure out why! Every time it only spits out "0" whereas the average low temperature works great..
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Temps_Grid_Keenan extends JFrame
{
private static final long serialVersionUID = 1L;
private static final int WIDTH = 400;
private static final int HEIGHT = 500;
private JTextField high1Field, low1Field, high2Field, low2Field;
private JTextField high3Field, low3Field, high4Field, low4Field;
private JTextField high5Field, low5Field, high6Field, low6Field;
private JTextField high7Field, low7Field, ave_highField, ave_lowField;
[code]....
View Replies
View Related
Apr 19, 2014
I am having trouble returning the DAY and Month that the high and low temperatures occurred on (right now I am only returning the int value) I also need to show how many days were <33 degrees and >75 degrees. I have done a lot of trial and error and searching. I set the String arrays but am failing at tying them in and calling them with the high and low temps.
package nyctemp;
public class NYCtemp {
public static void main(String[] args) {
String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
String[] months = {"January", "February", "March", "April",
[code]....
View Replies
View Related
Jun 16, 2014
I have followed the instructions carefully but the conversion values are not correct.
Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is
F - | C + 32
where ¥ is the Fahrenheit temperature and C is the Celsius temperature. Your program must use a loop to display the table.
Code
public class TempConversion
{
public static void main(String[] args) {
for(double i = 0; i <= 20.0; i++) {
[Code] ....
View Replies
View Related
Nov 14, 2014
I am trying to get it to print out an error if F or C isn't entered for the temperature type, but the code I am taking from one of my other similar programs isn't working for some reason.
Also, when I type a string in the temperature I get an exception....I can do the same with that as I would the temp type? I think I may just be putting the code in the wrong spot and thats why it isn't working..
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Please enter F for Fahrenheit or C for Celsius: ");
String fOrC = input.next();
[Code] ....
View Replies
View Related
Jan 11, 2014
I am trying to create a java file that will print out the temperature in Fahrenheit. This is my code.
import java.util.Scanner;
public class TemperatureConverter {
public static void main(String[] args) {
float temperature;
Scanner in= new Scanner(System.in);
System.out.printf("Enter temperature in degrees Celsius: ");
temperature = in.nextInt();
//Getting a red X next to this line.
fahrenheit = temperature * 9/5 +32;
//Add this line
System.out.printf(+temperature + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit.");
//System.out.println(temp1 + " degrees celsius is " + fahrenheit + " degrees Fahrenheit.");
}
}
I need to know what I am doing wrong. Using Eclipse as my platform. I have entered comments where I am getting red X's.
The error I get when I run the program.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
fahrenheit cannot be resolved to a variable
fahrenheit cannot be resolved to a variable
at TemperatureConverter.main(TemperatureConverter.jav a:24)
View Replies
View Related
May 29, 2014
I started taking a java programming class javascript eclipse The program says it wants a monthly temperature chart of two places..Declare an array of values for Blueville temperatures and another array for Orlando temperatures. Then, use what you have learned to produce a program to output the following table:
Blueville Monthly temperatures
jan feb mar apr may jun jul aug sep oct nov dec
3 3 5 10 16 20 24 23 16 10 5 3
Orlando Monthly Temperatures
jan feb mar apr may jun jul aug sep oct nov dec
14 16 12 23 24 25 27 30 25 22 17 15
The warmest month in Blueville is _______
The warmest month in Orlando is ________
The month with the greatest temperature spread is __________
View Replies
View Related
Oct 28, 2014
I’m trying to write a program in Java that will take the input of a temperature in Fahrenheit and convert it to Celsius and Kelvin. This is what I have so far but when I run the program on Eclipse it says the temp. in Celsius is infinity and the same for kelvin. Why is it not preforming the operation and spiting out the correct numbers?
import java.util.Scanner;
public class Temperature {
public static void main(String[] args) {
// This program converts temperatures from Fahrenheit to Celsius to Kelvin.
double temperature1;// operands
double temperature2;
double temperature3;
[Code] ....
View Replies
View Related
Aug 31, 2014
I have a simple code for temperature conversion using single dimensional array, but I am getting ArrayIndexOutOfBoundsException error.
import java.io.*;
class arraycelcius
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);
[code]...
View Replies
View Related
Feb 25, 2014
Here is the question:
-In your main, you should create a thermostat and thoroughly test it. Be sure to showcase time passing and the temperature reaching the desired setting. Also, showcase switching modes from heating to cooling.
My question is, once it reaches the desired temp, would the thermostat turn off, and then how do you show switching from heating and cooling.
This is what prints.
Thermostat is: true Thermostat is: false The desired temp: 70.0 The current temp: 69.0
Tue Feb 25 19:06:21 CST 2014
Tue Feb 25 20:06:21 CST 2014
Thermostat is: true Thermostat is: false The desired temp: 70.0 The current temp: 70.0
Here is my Class:
import java.util.Random;
import java.util.Date;
public class Thermostat {
private double currentTemp;
private double desiredTemp;
private double heatingThreshold;
private double coolingThreshold;
[Code] .....
View Replies
View Related
Oct 4, 2014
I wasn't supposed to use the % in front of f.I have to make a program to calculate the average temperature and annual precipitation in Jacksonville. I get this error on line 49:
java.util.IllegalFormatPrecisionException;
null (in java.util.Formatter$FormatSpecifier)
I don't get any errors during compilation.Here is my code (I'm not using the system selection yet):
import java.util.Scanner;
public class AnnualClimate1
{
public static void main(String[] args)
{
double[] temperaturesInJacksonville = {53.1, 55.8, 61.6, 66.6, 73.4, 79.1, 81.6, 80.8, 77.8, 69.4, 61.7, 55.0};
[code]....
View Replies
View Related
Sep 30, 2014
The problem I'm trying to resolve now is getting my ActionEvent to send the value input in the JTextArea out to be calculated, then to display the result in my result JLabel.
Here is an image of the GUI :
The basic procedure the teacher is asking for is the user is supposed to enter a temperature in the input. The user then clicks the input scale, and then on the output scale selection the converted value is to be displayed in the output area.
As I mentioned my problem is in the sending of the input value to my calculation area, and getting the value to display in the JLabel.
How should I approach this solution? Do I need to have a listener after the JTextArea of the input box? Will that allow me to limit the input values to numbers only?
final JTextArea inputText = new JTextArea("" + (char)176,1,4);
//ReadConsole equivalent to specific input was a number?
Here is the section of code my ActionListener is:
//celOut represents the Celcius output scale JRadioButton.
celOut.addActionListener (new ActionListener () {
@Override
public void actionPerformed(ActionEvent e) {
//if the Celcius Input Scale is selected.
if(cel.isSelected())
[Code] ....
All the calculations are required to occur in a separate java file, which what I think is tripping me up. How do I send a value from the JTextArea into the Calc.celToFahr method?
//contents of my Calc.java calculation class.
public class Calc {
public static double celToFahr(double cel){
return cel * (9./5.) + 32.;
}
public static double fahrToCel(double fahr){
return (fahr - 32.)*(5./9.);
}
}
View Replies
View Related
Oct 16, 2014
How do you format an arraylist?
Mine looks like this:
[<?xml version="1.0" encoding="UTF-8" standalone="no"?> <DefEnv id="Dev">, <Envt id="Test">, , <DB id="DM">,
But I want it to look like: I'd prefer if the '[' , '<>' and ',' were not on them also but I'm not too bothered about that bit.
[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<DefEnv id="Dev">,
<Envt id="Test">, ,
<DB id="DM">, ]
View Replies
View Related
Feb 4, 2014
I have been given a piece of work to do for College that requires me to format user input. For example: This is an example of text that will have straight left and right margins after formatting
will transform into:
This..is..an.example
of..text..that..will
have..straight..left
and...right..margins
after.....formatting
The user inputs the width, in the case above being 20. Each line has to therefore be 20 characters long. All spaces are to be replaced with full stops.
This.is.an.example.o
f.text.that.will.hav
e.straight.left.and.
right.margins.after.
formatting..........
public class Main {
public static void main ( String args[])
[code]....
View Replies
View Related
Mar 26, 2004
How to go for formatting amounts to be displayed using JSP?
View Replies
View Related
Oct 8, 2014
My program is pretty much finished and does what it is supposed to do but it is displaying the href= with the url link how can i get my program to drop the href= from the url link because it is only supposed to display 'url' right now it is just displaying href='url' ...
public class myList {
public static void main(String[] args) {
String htmlCode = (long string of url links)
int linkStart = 0;
while (true) {
linkStart = hrefSearch(htmlCode);
if(linkStart == -1) {break;}
[Code] .....
View Replies
View Related