Printing Errors If F Or C Isn't Entered For Temperature Type

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


ADVERTISEMENT

Using While Loop For Printing User Entered Name From Console

Jul 2, 2014

Ask user to enter a name alphabet by alphabet, and print d whole word as output,,,,,, use while loop?Since i am new to JAVA..i have no clue on how to begin?

View Replies View Related

First Time Using Generics - Incomparable Type Errors

Aug 29, 2014

I am trying to make a generic method that will replace the data type T with those number types usable with a Scanner object. However, whenever I try to compile, I get errors saying that a Byte/Integer/Double etc are found when only a type T is allowed. This is the beginning of my method. I can;t understand what is wrong with it.

Java Code:

public <T extends Number> T nextRanged(T lowerBound, T upperBound, boolean inclusive, String errorMessage){
// Holds program execution until user inputs a numeric value between the bounds. Prevents all other input without exception.
// Output data type determined by the type of the bounds.
T input = null;
try{
if(input instanceof Byte){
input = new Byte(internalScanner.nextByte());

[Code] ....

The purpose of the method, in the end, will be to provide the nextXXX() functionality of a Scanner object but with built in validation procedures. I could easily do this by making a nextIntRanged(), nextDoubleRanged() etc methods, but this seems wasteful to me.

I meant "incompatible type errors"!

Error example:

ValidatedScanner.java:57: error: incompatible types
input = new Byte(internalScanner.nextByte());
^
required: T
found: Byte

where T is a type-variable:

T extends Number declared in method <T>nextRanged(T,T,boolean,String)

View Replies View Related

Generic Method And Bound Type Parameter Errors

Jul 14, 2014

I am following this article [URL] .... till now I have made some code

This is my Interface

public interface Comparable<T> {
public int compareTo(T o);
}

And this is my class where I am using Bound Type Parameter on Generic Methods

public class GenericMethodBoundType {
public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)

[Code] .....

What else I need to do both in main method and at what parameterized types I need to pass at the class?

View Replies View Related

Identifier Expected And Illegal Start Of Type Errors

Aug 6, 2014

I'm working through Head First Java, and I'm struggling with the chapter 6 magnet exercise on page 161. I've checked my answer countless times, and it appears to match the book's code, but when I try to run it on my computer I'm getting an error. It says:

error: <identifier> expected
System.out.println^(" "); and

error: illegal start of type
System.out.println(^" ");, both for line 32.

I cannot seem to figure out what is different about my code!!

import java.util.*;

public class ArrayListMagnet {
public static void main (String [] args) {
ArrayList<String> a = new ArrayList<String>();
a.add (0, "zero");
a.add(1, "one");
a.add(2, "two");
a.add(3, "three");

[Code] .....

Also, I'm not sure if this has anything to do with the above errors, but I'm getting a third error message for line 34 saying:

error: class, interface, or enum expected
}^.

View Replies View Related

GUI Temperature Converter

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

Program To Convert Temperature

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

High / Low / Average Temperature

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

Temperature Conversion GUI Java

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

Will Not Average For High Temperature

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

Returning Arrays On Temperature Table?

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

Temperature Conversion Celsius To Fahrenheit

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

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 View Related

Create A Java File That Will Print Out Temperature In Fahrenheit?

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

Monthly Temperature Chart Of Two Places - Array / While Loops

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

Take Input Of Temperature In Fahrenheit And Convert It To Celsius And Kelvin

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

ArrayIndexOutOfBoundsException In A Single Dimensional Array For Temperature Conversion

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

Getting Int Type Cast To Lower Precision Char Type In Parasoft JTEST

Mar 11, 2014

Below code I am using to typecast int to char.

char escapeValue = (char)0;
char cha = (char) 10;
escapeValue = (char)(escapeValue * cha); // Here am getting the above error.

I have 38 similar issues in my workspace.

View Replies View Related

Is Type Irrelevant As Long As Value Is Within Boundaries Of Type Of Switch Expression

Apr 30, 2014

If you have final int i = 1;
short s = 1;
switch(s) {
case i: System.out.println(i);
}

it runs fine. Note that the switch expression is of type short (2 bytes) and the case constant is of type int (4 bytes).My question is: Is the type irrelevant as long as the value is within the boundaries of the type of the switch expression?I have the feeling that this is true since:

byte b = 127;
final int i = 127;
switch(b) {
case i: System.out.println(i);
}

This runs fine again, but if I change the literal assigned to i to 128, which is out of range for type byte, then the compiler complains.Is it true that in the first example the short variable and in the second example the byte variable (the switch expressions) are first implicitly converted to an int and then compared with the case constants?

View Replies View Related

How To Convert Input Array Of Type Strings To Class Type

Aug 14, 2014

class Passenger{
String name;
int age;
char gender;
int weight;
public Passenger(){

[Code] ....

This is showing error.....error it gives isthat it cannot change from string type to passenger type......... How to do it??????

View Replies View Related

Addition Of Generic Type Parameter Causes Member Type Clash

Apr 22, 2014

Got a problem with generics, which I'm still pretty new at. Here's a program that compiles fine:

import java.util.ArrayList;
import javax.swing.JComponent;
public class Experiments {
public static void main(String[] args) {
ListHolder holder = new ListHolder();

[Code] ....

It's useless, but it compiles. If I change Line 14, however, to add a generic type parameter to the ListHolder class, Line 10 no longer compiles:

import java.util.ArrayList;
import javax.swing.JComponent;
public class Experiments {
public static void main(String[] args) {
ListHolder holder = new ListHolder();

[Code] ....

I get this error:

Uncompilable source code - incompatible types: java.lang.Object cannot be converted to javax.swing.JComponent
at experiments.Experiments.main(Experiments.java:10)

Apparently, the introduction of the type parameter leaves the compiler thinking that aList is of type Object. I can cast it, like this:

JComponent c = ((ArrayList<JComponent>)holder.aList).iterator().next();

That makes the compiler happy, but why is it necessary? How does adding the (unused) type parameter to the ListHolder class end up making the compiler think the aList member of an instance of ListHolder is of type Object?

View Replies View Related

Thermostat - Showcase Time Passing And Temperature Reaching Desired Setting

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

Make A Program To Calculate Average Temperature And Annual Precipitation In Jacksonville

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

How To Convert String Type To Generic Class Type

Mar 22, 2015

I have a String repersentaion of some Object.I want that object convert back into some class type how can I do this?

View Replies View Related

Temperature Conversion Project - Send Input Value To Calculation Area And Get Value To Display In JLabel

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

How To Convert ZipEntry Type To File Type

Dec 4, 2014

I'm trying to parse and compare the content of a zip file. However I'm stuck at what SHOULD be a very simple problem, however I can't seem to find a solution. I have done the following:

ZipInputStream zin1 = new ZipInputStream(fin);
ZipEntry ze1 = null;
fin2 = new FileInputStream(fileName2);
ZipInputStream zin2 = new ZipInputStream(fin2);
ZipEntry ze2 = null;
//fin.close();
ze1 = zin1.getNextEntry();
ze2 = zin2.getNextEntry();

Which gives me the first entry of each zipfile as a ZipEntry type object. I have tried getting the path of the file (inside the zip file) and using this to create a File type object. This does not seem to work though I get:

Exception in thread "main" java.io.FileNotFoundException: My DocumentsmetadatacoreProperties.xml (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)

And this is because I get a null return from trying to create the File file1 = new File(correctLocation);

I guess I cannot access the file inside a zip file this way. So my question is how can I make a ZipEntry type object into a File type object?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved