Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
public class test{
public void mosleh(String coursName)
{
System.out.printf("Welocm to grade bok for\n%s!\n,coursName");
}
}
--
import java.util.Scanner;
public class GradeBookTest {
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
GradeBook myGradeBook = new GradeBook ();
System.out.println("please enter the cours name");
String nameOfCourse = input.nextLine();
System.out.println();
myGradeBook.mosleh(nameOfCourse);
}
}
Its unclear what youre asking but you need to rename your test class to avail of the mosleh method
public class GradeBook {
You need to declare the mosleh() method as static
public static void mosleh(String coursName);
In order to use it in this way:
myGradeBook.mosleh(nameOfCourse);
Or create an object from myGradeBook then call the method, like this:
new myGradeBook().mosleh(nameOfCource);
Consider that you need to change the class name to myGradeBook instead of test
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to learn object oriented code in Java, and am following a tutorial. I am currently stuck trying to parse a string into my class. It is returning the following error:
Name cannot be resolved to a variable
I have a main file, called start.java, and the class I am trying to call is in a different file, called phone.java. Both are in a folder called src. Below is the start.java code (which is throwing the error)
package src;
public class Start {
public static void main(String[] args){
phone android = new phone(Name:"android 10");
System.out.println(android.getName());
}
}
And here is the class I am trying to call, in phone.java
package src;
public class phone{
private String name;
public phone(String name) {
this.name = name;
}
public String getName(){
return this.name;
}
}
Much thanks for your help
You need to remove the Name from new phone(Name:"android 10") and need to use new phone("android 10").
You just need to pass the value for the name, your constructor will bind it to the name variable.
Refer below code
public class Start {
public static void main(String[] args){
phone android = new phone("android 10");
System.out.println(android.getName());
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, I'm creating a snakes and ladders game in javafx, that asks a question when the player lands on a ladder or snake, and decides whether to go up the ladder/down the snake or not based on whether the answer is correct or not.
I have a Question class that creates a new window and displays the question, as well as a place to answer it, and a 'correct' boolean value that I am hoping to essentially, return to the main class, when the button is clicked.
Since EventHandlers cannot directly return values, I am hoping to say 'if the value of this 'correct' variable has changed, execute a getter method to get and store the value' but I don't know how to create a listener to check if the value has changed.
Any help would be appreciated!
I would do something like this:
public class Question {
public enum State {UNANSWERED, CORRECT, INCORRECT}
private final ReadOnlyObjectWrapper<State> state
= new ReadOnlyObjectWrapper<>(State.UNANSWERED);
public ReadOnlyObjectProperty<State> stateProperty() {
return state.getReadOnlyProperty() ;
}
public final State getState() {
return stateProperty().get();
}
private Button button ;
public Question() {
// ...
button = new Button(...);
button.setOnAction( event -> {
if (checkAnswer()) {
state.set(State.CORRECT);
} else {
state.set(State.INCORRECT);
}
});
// etc..
}
public void showWindow() {
// display window with question and controls, etc...
}
}
Then you can do
Question question = new Question();
question.stateProperty().addListener((obs, oldState, newState) -> {
if (state == Question.State.CORRECT) { /* ...*/}
else if (state == Question.State.INCORRECT) { /* ... */}
});
question.showWindow();
I don't know what type of listener you want but I found this for javafx changelistener at http://docs.oracle.com/javafx/2/binding/jfxpub-binding.htm. This might help you get started
package propertydemo;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ChangeListener;
public class Main {
public static void main(String[] args) {
Bill electricBill = new Bill();
electricBill.amountDueProperty().addListener(new ChangeListener(){
#Override public void changed(ObservableValue o,Object oldVal,
Object newVal){
System.out.println("Electric bill has changed!");
}
});
electricBill.setAmountDue(100.00);
}
}
There is a great API built for Dialogs. It's going to become part of the official JavaFX API, but for now you can use the separate library:
Dialogs
Confirmation Dialog is probably the one you're looking for.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Can someone please explain how is possible, that method obtain(..) throws IllegalStateException for input ConfiguratorType.SKODA (the variable configurators contains {SKODA=null})? How can it be null, I do not understand why SkodaConfigurator.INSTANCE returns null. It should never be null or am i mistaken? The code is executed in servlet environment, Java 7.
Thank you
public class CarConfigurators {
private static Map<ConfiguratorType, CarConfigurator> configurators
= new EnumMap<ConfiguratorType, CarConfigurator>(ConfiguratorType.class);
static {
configurators.put(ConfiguratorType.SKODA, SkodaConfigurator.INSTANCE);
// ..
}
public static CarConfigurator obtain(ConfiguratorType type) {
CarConfigurator configurator = configurators.get(type);
if (configurator == null)
throw new IllegalStateException("Car configurator of type " + type + " is not registered.");
return configurator;
}
...
}
public class SkodaConfigurator extends CarConfigurator {
public static final SkodaConfigurator INSTANCE = new SkodaConfigurator();
...
}
public enum ConfiguratorType {
SKODA,
// ..
}
Static code cannot all run simultaneously, the various bits of static initialization going on have to happen in a given order. Clearly in this case, your static block which does configurations.put(...) is running before the static variable in SkodaConfiguration is initialized.
This is related to static initialization order.
I found this from another answer
public class Main {
{
System.out.printf("NON-STATIC BLOCK\n");
}
static{
System.out.printf("STATIC BLOCK\n");
}
public static Main m = new Main();
public Main(){
System.out.printf("MAIN CONSTRUCTOR\n");
}
public static void main(String... args) {
//Main m = new Main();
System.out.printf("MAIN METHOD\n");
}
}
Output :
STATIC BLOCK
NON-STATIC BLOCK
MAIN CONSTRUCTOR
MAIN METHOD
Please go through this : Java Static Initialization Order
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How can i change the virtual void Execute (vtkObject *caller, unsigned long eid, void *callData) function of the vtkCallbackCommand class (vtk) to java, thanks a lot, AMAL
Adding an callback method on a specific event is different from C++. As you can see in some vtk Java Exemple you don't have to create a class which extends from vtkCallbackCommand to rewrite the Execute Method.
To add specific behavior you have to use the Java AddObserver() method, It should be something like :
public class kbHandler
{
private vtkRenderWindowInteractor iren;
public static void main(String[] args) {
kbHandler kbh = new kbHandler();
kbh.doit();
}
void callbackHandler ()
{
// if i'm here, a key is pressed !!
// you can get back information from iren (which key : iren.GetKeyCode())
}
public void doit ()
{
// Do lot of things
iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
// add observer for the handler arg1 = event to observe, arg2 object handler of the event, arg3: method to call
iren.AddObserver("CharEvent", this, "callbackHandler");
iren.Initialize();
iren.Start();
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am currently creating a events recorder GUI program. Yet I am encountering a very difficult problem.
How should I store objects within an object within an object within an object?
For example,
I have an event.
This event has 4 category.
In the first category (Category A), there are 30 exhibition shows.
Within each show, there are 20 - 30 representatives. (Let's say 30 reps for the first show).
...
How can I store all these information in an arraylist? OR is there any other better idea?
Should I also apply Polymorphism to this one too?
Event --> Category A (first one out of the four) --> First Show out of 30 --> 1 rep out of 30 reps --> ... etc.
Thanks.
My confusion is that I would like to treat every single of these as an object. For example, category is an object. The show is an object. The reps is an object. My question is how can I store an object within an object within an object and so on? Thanks.
try this
Test.java
import java.util.List;
public class Test {
public List<Category> category;
}
import java.util.List;
Category.java
public class Category {
public List<Exhibition> exhibitionShow;
public void setExhibitionShow(List<Exhibition> exhibitionShow) {
this.exhibitionShow = exhibitionShow;
}
public List<Exhibition> getExhibitionShow() {
return exhibitionShow;
}
}
Exhibition.java
import java.util.List;
public class Exhibition {
public List<Representative> representative;
public void setRepresentative(List<Representative> representative) {
this.representative = representative;
}
public List<Representative> getRepresentative() {
return representative;
}
}
Representative .java
public class Representative {
//add method
}
I am not sure what is your confusion, you need to do something like this
class Event{
Category[] categories;
}
class Category{
ArrayList<Show> shows;
}
class Show{
ArrayList<Representative> reps;
}
//.. and so on.
I think you have the idea. My idea is create one public method.