Also ich muss ein Programm in Java schreiben, das 2 Benutzer inputed Temperaturen in Celsius nimmt und es in Fahrenheit und Kelvin umwandelt. Ich schrieb den Code und es funktioniert in Eclipse, aber mein Lehrer sagte streng, dass es in cmd arbeiten muss. Es kompiliert gut, aber wenn ich gehe, um es auszuführen, gibt es could not find or load main class temperatureTester
(Name der Klasse mit meinem Haupt). Dies ist mein erster Beitrag, also wenn Sie weitere Informationen benötigen, fragen Sie bitte und ich suche nach Ideen, warum das passiert. unten ist mein Code für die Frage.wie 2 verbundene Klassen in Java auf cmd ausgeführt werden?
import java.util.Scanner;
public class temperatureTester{
public static void main (String[]args){
//create 2 objects connecting to temperatureC
temperatureC firstValue = new temperatureC();
temperatureC secondValue = new temperatureC();
// initialize scanner
Scanner stdin = new Scanner (System.in);
//initialize variables
double firstC = 0;
double secondC = 0;
//prompt user for both values
System.out.print("Please enter initial temperatures: ");
firstC = stdin.nextDouble();
secondC = stdin.nextDouble();
//call object set methods and pass entered values as arguments
firstValue.setC(firstC);
secondValue.setC(secondC);
//display the values for the values for different temp. units
System.out.println("1) The current temperature in Celcius is: " + firstValue.getC());
System.out.println("1) The current temperature in fahreinheit is: " + firstValue.getF());
System.out.println("1) The current temperature in kelvin is: " + firstValue.getK());
System.out.println("---------------------------------------------------------------");
System.out.println("2) The current temperature in Celcius is: " + secondValue.getC());
System.out.println("2) The current temperature in fahreinheit is: " + secondValue.getF());
System.out.println("2) The current temperature in kelvin is: " + secondValue.getK());
Dies ist die zweite Klasse
public class temperatureC{
private double C;
/**
The setC method stores the value in the C field
@ param initialC the value stored in C
*/
public void setC(double initialC){
C = initialC;
}
/**
The getC returns the C value and also sets a lower limit,
if a number below is entered it sets it ti the limit.
@Return the value of the C
*/
public double getC(){
if(C < -273.15){
C = -273.15;
}
return C;
}
/**
the getF method calculates and returns a value for C in fahrenheit
@return the computed for C in fahrenheit
*/
public double getF(){
return C * 1.8 + 32;
}
/**
The getK method computes and returns a value for temperature C in kelvin
@return the computed Kelvin value
*/
public double getK(){
return C + 273.15;
}
}
wie läufst du es? Kannst du deine Befehle posten? – root545
Bitte beachten Sie, dass Java-Klassen mit 'CapitalLetters' beginnen sollten –