Ich habe ein Problem mit einem Java-Programm, das ich für den Unterricht machen muss. Ich soll zwei Buchstaben nehmen und diese an einen Ort umwandeln. Ich soll dann eine Nachricht aufnehmen und mit einem einfachen Zeichenaustausch verschlüsseln. Ich habe anscheinend ein Problem mit der Tatsache, dass ein Aufruf in meiner Treiberdatei die Methode, die ich in meiner Actions-Datei aufrufen möchte, nicht sehen kann. Ich bin sicher, dass ich etwas Einfaches vermisse und es falsch mache, aber je mehr ich die Dokumentation lese, desto verwirrter werde ich. Könnte mir bitte jemand erklären, was ich falsch mache. Ich versuche, meine getCountry-Methode, die sich in meiner Actions-Datei befindet, aus meiner Treiberdatei aufzurufen. Der Fehler ist auf der LinieMethode von einer anderen Datei nicht gesehen
locH = loc.getCountry(locationLetters);
Driver.java
/**
Program Name: Action
Date:4/14/2016
Program Description: This program is going to handle the window where the user enters data.
It is also going to be what is going to call the methods of the Actions class
Methods: Driver(),
*/
import javax.swing.*; // For the Swing classes
import java.awt.event.*; // For the ActionListener Interface
import java.util.Scanner; //for the keyboard
public class Driver extends JFrame
{
//delcare
private String locationLetters; //this is going hold the users letter selection
private String message; //this is going to hold the users message
private String locH; //for the holder of location selection
private String messH; //to hold the message before change it to an array
Scanner keyboard = new Scanner (System.in);//to make the keyboard
/**
This method is the constuctor that is going to make the window for the program to use.
*/
public Driver()
{
System.out.println("sup nerd");
yourmom();
}//end of Driver()
public String yourmom()
{
System.out.println("Please entner the two charater key for the location you want to message");
locationLetters = keyboard.next();
System.out.println("Please enter the message you would like to have encrypted.");
message = keyboard.next();
locH = loc.getCountry(locationLetters);
return locH;
}//end of yourmom()
public static void main(String[] arg)
{
Actions loc = new Actions();
Actions mess = new Actions();
new Driver();
}//end of main
}//end of Driver class
Actions.java
/**
Program Name: Action
Date:4/14/2016
Program Description: This program is going to handle all the encryption actions as well
loction where the message is being sent.
Methods:Location(),
*/
public class Actions
{
//decare
public String messE; //this is for the message that is going to be ecrypted
public String getCountry(String locHA)
{
locHA.toUpperCase();
if(locHA == "FR")
locHA = "France";
if(locHA == "GB")
locHA = "Great Britain";
if(locHA == "CA")
locHA = "Canada";
if(locHA == "JA")
locHA = "Japan";
if(locHA == "RU")
locHA = "Russia";
if(locHA == "GE")
locHA = "Germany";
if(locHA == "AU")
locHA = "Australia";
if(locHA == "MX")
locHA = "Mexico";
return locHA;
}
}//end of action class
Ich weiß, dass diese in einer Datei getan werden könnte, aber mein Lehrer will es in zwei . Ich weiß, dass mir etwas Einfaches fehlt, aber ich verstehe die Dokumentation, die ich in Bezug auf die Verwendung von Objekten gelesen habe, nicht. Könnten Sie bitte darauf hinweisen, was ich falsch gemacht habe? Ich wäre sehr dankbar. Vielen Dank.
Das liegt daran, dass Sie 'loc' in der Methode' main() 'deklariert haben und versuchen, von der Methode' yourmom() 'darauf zuzugreifen. Veröffentlichen Sie auch keine Links zum Code. Fügen Sie Ihren Code in die Frage selbst ein. – user2004685
Der Code muss ** in der Frage selbst ** sein. Nicht bei Pastebin. Wenn Sie nach einem Fehler fragen, ** posten Sie, was der Fehler ist **. –
@ Grimmjow91: Wenn Sie jemanden in einem Kommentar benachrichtigen möchten, pred ''' 'vor ihrem Namen. Wenn du also user2004685 benachrichtigen willst, platziere '' user2004685'' in deinem Kommentar zu ihm. –