methods

Methods in java (grade calculator)

心不动则不痛 提交于 2019-12-20 07:47:52
问题 We've been learning about methods in java (using netbeans) in class and I'm still a bit confused about using methods. One homework question basically asks to design a grade calculator using methods by prompting the user for a mark , the max mark possible, the weighting of that test and then producing a final score for that test. eg. (35/50)*75% = overall mark However, I am struggling to use methods and I was wondering if someone could point me in the right direction as to why my code below

In ruby, is there a way to know in the console what a method does?

荒凉一梦 提交于 2019-12-20 07:43:13
问题 In Ruby, if i am looking for the methods of a class. ie: String.methods.sort and i have the following: [:!, :!=, :!~, :<, :<=, :<=>, :==, :===, :=~, :>, :>=, :__id__, :__send__, :allocate, :ancestors, :autoload, :autoload?, :class, :class_eval, :class_exec, :class_variable_defined?, :class_variable_get, :class_variable_set, :class_variables, :clone, :const_defined?, :const_get, :const_missing, :const_set, :constants, :define_singleton_method, :deprecate_constant, :display, :dup, :enum_for,

Java string returns as null

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 07:39:11
问题 I am attempting to get one class to return a string from another class, though the return I get is null. I have a set method that works in setting the string in the original class, but when calling the method in my second class, I get a return of null. Here is the first class; public class IceCream { // instance variables - replace the example below with your own private String flavour; public static double price; /** * Constructor for objects of class IceCream */ public IceCream() { //

Java string returns as null

为君一笑 提交于 2019-12-20 07:39:02
问题 I am attempting to get one class to return a string from another class, though the return I get is null. I have a set method that works in setting the string in the original class, but when calling the method in my second class, I get a return of null. Here is the first class; public class IceCream { // instance variables - replace the example below with your own private String flavour; public static double price; /** * Constructor for objects of class IceCream */ public IceCream() { //

Implementing parent class methods with several children class in Java

一个人想着一个人 提交于 2019-12-20 07:33:43
问题 I have a class (let's call it A ) that is extended by several children class ( B , C , D , etc.). In each child class, there are specific methods that I'd like to be accessible from an instantiation of the parent class A . I tried to declare A as an abstract class, and to declare each child class methods inside as abstract. Then I implemented these methods in their own class but it seems that each child class must implement every method of the parent class. However, I can't do this. Would you

Error Global Variable not defined when importing class

冷暖自知 提交于 2019-12-20 07:33:23
问题 I am trying to implement a movement system where the player move's towards the click position. But I have been running into some problems with the arguments of the movement method. The movement method currently needs to take all the variables as arguments: This code works: def move(self,event,mouse_pos, screen, background): if event.type == MOUSEBUTTONDOWN: if mouse_pos[1] > self.pos[1]: screen.blit(background, self.pos, self.pos) #erases players by bliting bg self.speed = 1 self.move_south()

C++ Overriding method not working

…衆ロ難τιáo~ 提交于 2019-12-20 06:40:06
问题 I am expecting "My Game" to print out but I am getting "Base" This only happens when using methods internally inside the class. #include <iostream> namespace Monster { class App { public: App(){} ~App(){} void run(){ this->speak(); } void speak(){ std::cout << "Base" << "\n"; }; };}; // class / namespace class MyGame : public Monster::App { public: MyGame(){} ~MyGame(){} void speak(){ std::cout << "My Game" << "\n"; }; }; int main(){ MyGame *child = new MyGame; child->run(); return 0; } 回答1:

Java: How do i create objects in a static method and also call for methods from another class?

自作多情 提交于 2019-12-20 06:37:12
问题 I am doing this Java assignment for hours and stuck with this tester class for very almost 5 hours. In this assignment, I have created a Product class, a Money class, a LineItem class and an Inventory class. Now i need to create a test class to test the program by putting new lineitems into the inventory array. In the tester class, I am trying to create a static method public static void addTestItems(Inventory theInventory) which suppose to add 4 items. For each item I will need to create a

How to override method with derived return type in C#?

和自甴很熟 提交于 2019-12-20 06:28:12
问题 I want to override a virtual method with a derived class type. What's the current best way to do this? So far I've found two approaches: Use an abstract base class for each derived type; bridge with protected methods. Use a protected implementation with a public accessor. Base case (no solution implemented, Clone always returns base type A1 ): public class A1 { public int X1 { get; set; } public A1(int x1) { this.X1 = x1; } public virtual A1 Clone() { return new A1(X1); } } public class A2 :

How to exit a method in ActionListener

戏子无情 提交于 2019-12-20 06:28:10
问题 I have an ActionListener connected to a JTextField and want to type something so that it will exit the method the ActionListener is in. Code: main() { Security(x,x,x); } public void Security(JTextArea out, JTextField in) { in.setText(""); in.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (in.getText().contains("exitsys")) { out.append("Security:Security System Deactivated\n"); return; } in.setText(""); } }); out.append("Security:Security System