Search Results

Search found 3120 results on 125 pages for 'php5 oop'.

Page 54/125 | < Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >

  • Why does this program stop running?

    - by designloper
    Hi everyone....I am developing a card making system...nothing fancy. Right got this far but program now stops running with no error when running after the first card sample i.e. " Enter 'OK' if this card is OK, otherwise enter an alternative border character: + ". Any suggestions Java Masters? //Ask user for input //makes use of print line method System.out.println("Enter name: "); //took the variables //called the object of the scanner 'cardOrder' //and use the Scanner objects method '.nextLine' //to read the next line of the input firstName = cardOrder.nextLine(); mInitial = cardOrder.nextLine(); lastName = cardOrder.nextLine(); //Print out the "Here is a sample card" + the first name, middle initial and last name System.out.println("Here is a sample card: \n\n" + firstName + mInitial + lastName + "**************" + "**************" + firstName + mInitial + lastName + "\n* *" + "\n*" + " " + firstName + mInitial + lastName + " *" + "\n* *\n" + firstName + mInitial + lastName +"**************" + "**************" + firstName + mInitial + lastName + "\n"); //Ask user is the card is OK to proceed to order query or if they want an alternative border character: + System.out.println("Enter 'OK' if this card is OK, otherwise enter an alternative border character: + "); //Check if user entered "OK" and store it in var optionA optionA = cardOrder.nextLine(); //test if (a == optionA){ System.out.println("\nHow many cards would you like? "); cardsOrdered = cardOrder.nextInt(); equals = (int) (cardPriceA * cardsOrdered); System.out.println("The price of " + cardsOrdered + " cards"+ " is £" + equals + ".\n"); System.out.println("No Discount given."); } else if(b == optionA) { //Print out the "Here is a sample card" + the first name, middle initial and last name System.out.println("Here is a sample card: \n\n" + firstName + mInitial + lastName + "++++++++++++++" + "++++++++++++++" + firstName + mInitial + lastName + "\n+ +" + "\n+" + " " + firstName + mInitial + lastName + " +" + "\n+ +\n" + firstName + mInitial + lastName +"++++++++++++++" + "++++++++++++++" + firstName + mInitial + lastName + "\n"); //Ask user is the card is OK to proceed to order query or if they want an alternative border character: + System.out.println("Enter 'OK' if this card is OK, otherwise enter an alternative border character: OK "); //Check if user entered "OK" and store it in var optionA optionA = cardOrder.nextLine(); if (a == optionA){ System.out.println("\nHow many cards would you like? "); cardsOrdered = cardOrder.nextInt(); equals = (int) (cardPriceA * cardsOrdered); System.out.println("The price of " + cardsOrdered + " cards"+ " is £" + equals + ".\n"); System.out.println("No Discount given."); } } else if (c == optionA) {//Print out the "Here is a sample card" + the first name, middle initial and last name System.out.println("Here is a sample card: \n\n" + firstName + mInitial + lastName + "**************" + "**************" + firstName + mInitial + lastName + "\n* *" + "\n*" + " " + firstName + mInitial + lastName + " *" + "\n* *\n" + firstName + mInitial + lastName +"**************" + "**************" + firstName + mInitial + lastName + "\n"); //Ask user is the card is OK to proceed to order query or if they want an alternative border character: + System.out.println("Enter 'OK' if this card is OK, otherwise enter an alternative border character: + "); //Check if user entered "OK" and store it in var optionA optionA = cardOrder.nextLine(); if (a == optionA){ System.out.println("\nHow many cards would you like? "); cardsOrdered = cardOrder.nextInt(); equals = (int) (cardPriceA * cardsOrdered); System.out.println("The price of " + cardsOrdered + " cards"+ " is £" + equals + ".\n"); System.out.println("No Discount given."); } }

    Read the article

  • Possible to add hook as android fetches XML-strings?

    - by user247245
    I'm on my first week with android and would appreciate any insight if it's possible to hook or override the default behaviour when an android application reads their values from the resource-files to the shown layouts. What I want is to over time be able to add new/updated strings OTA and store locally and then on launch of application load new values instead of the ones in the default /res. Ideally i guess, would be an override of setContentView. Files holding updates will be in same xml-format as those in /res. (Please, no advices in other ways to do this. Just need to know if it's at all possible, without hacking the SDK) regards, /t

    Read the article

  • One-to-One relation classes

    - by SeyZ
    I want to have a class named ProjectDirectory and a class named MetaDirectory. Each project has a MetaDirectory which contains some meta data. Is it the good way to write the classes like this: class ProjectDirectory(object): def __init__(self, directory=None): self.directory = directory self.meta_directory = MetaDirectory(self) def __repr__(self): return self.directory class MetaDirectory(object): def __init__(self, project_directory=None): self.project_directory = project_directory self.directory = "%s/.meta/" % project_directory ProjectDirectory has a reference to MetaDirectory and MetaDirectory has a reference to ProjectDirectory. Is there an other solution or this solution is good ?

    Read the article

  • Elegant ways to print out a bunch of instance attributes in python 2.6?

    - by wds
    First some background. I'm parsing a simple file format, and wish to re-use the results in python code later, so I made a very simple class hierarchy and wrote the parser to construct objects from the original records in the text files I'm working from. At the same time I'd like to load the data into a legacy database, the loader files for which take a simple tab-separated format. The most straightforward way would be to just do something like: print "%s\t%s\t....".format(record.id, record.attr1, len(record.attr1), ...) Because there are so many columns to print out though, I thought I'd use the Template class to make it a bit easier to see what's what, i.e.: templ = Template("$id\t$attr1\t$attr1_len\t...") And I figured I could just use the record in place of the map used by a substitute call, with some additional keywords for derived values: print templ.substitute(record, attr1_len=len(record.attr1), ...) Unfortunately this fails, complaining that the record instance does not have an attribute __getitem__. So my question is twofold: do I need to implement __getitem__ and if so how? is there a more elegant way for something like this where you just need to output a bunch of attributes you already know the name for?

    Read the article

  • Property and Encapsulation

    - by Lijo
    Hi Team, Following is a question regarding using Properties in class. I am software engineer with 3 years of experience. I have been using public properties instead of exposing member variables publically. Many a people told that this approach helps in encapsulation. I don’t realize any encapsulation advantage by making it a property. While discussions, I came to know that not many people knows about the real reason for going for Property. They just do it as part of coding standard. Can someone clearly explain how Property is better than public member variable? How it improves encapsulation? Thanks Lijo

    Read the article

  • Why this doesnt't work in C++?

    - by user3377450
    I'm doing something and I have this: //main.cpp file template<typename t1, typename t2> std::ostream& operator<<(std::ostream& os, const std::pair<t1, t2>& pair) { return os << "< " << pair.first << " , " << pair.second << " >"; } int main() { std::map<int, int> map = { { 1, 2 }, { 2, 3 } }; std::cout << *map.begin() << std::endl;//This works std::copy(map.begin(), map.end(), std::ostream_iterator<std::pair<int,int> >(std::cout, " "));//this doesn't work } I guess this is not working because in the std::copy algorithm the operator isn't defined, but what can I do?

    Read the article

  • How does Undo work?

    - by dontWatchMyProfile
    How does undo work? Does it copy all the managed objects every time any of the values change? Or does it only copy the actual changes together with an information which objects were affected? Is that heavy or lightweight?

    Read the article

  • access a property via string with array in php?

    - by sprugman
    (This is in drupal, but I don't really think that matters.) I have a big list of properties that I need to map between two objects, and in one, the value that I need to map is buried inside an array. I'm hoping to avoid hard-coding the property names in the code. If I have a class like this: class Product { public $colors, $sizes; } I can access the properties like this: $props = array('colors', 'sizes'); foreach ($props as $p) { $this->$p = $other_object->$p; } As far as I can tell, if each of the properties on the left are an array, I can't do this: foreach ($props as $p) { $this->$p[0]['value'] = $other_object->$p; } Is that correct, or am I missing some clever way around this?

    Read the article

  • Javascript: Inherit method from base class and return the subclass's private variable

    - by marisbest2
    I have the following BaseClass defined: function BaseClass (arg1,arg2,arg3) { //constructor code here then - var privateVar = 7500; this.getPrivateVar = function() { return privateVar; }; } I want to have the following subclass which allows changing privateVar like so: function SubClass (arg1,arg2,arg3,privateVar) { //constructor code here then - var privateVar = privateVar; } SubClass.prototype = new BaseClass(); Now I want SubClass to inherit the getPrivateVar method. However, when I try this, it always returns 7500 which is the value in the BaseClass and not the value of privateVar. In other words, is it possible to inherit a BaseClass's public methods but have any references in them refer to the SubClass's properties? And how would I do that?

    Read the article

  • Java : Using parent class method to access child class variable

    - by Jayant
    I have the following scenario : public class A { private int x = 5; public void print() { System.out.println(x); } } public class B extends A { private int x = 10; /*public void print() { System.out.println(x); }*/ public static void main(String[] args) { B b = new B(); b.print(); } } On executing the code, the output is : 5. How to access the child class(B's) variable(x) via the parent class method? Could this be done without overriding the print() method (i.e. uncommenting it in B)? [This is important because on overriding we will have to rewrite the whole code for the print() method again]

    Read the article

  • Any method to denote object assignment?

    - by Droogans
    I've been studying magic methods in Python, and have been wondering if there's a way to outline the specific action of: a = MyClass(*params).method() versus: MyClass(*params).method() In the sense that, perhaps, I may want to return a list that has been split on the '\n' character, versus dumping the raw list into the variable a that keeps the '\n' intact. Is there a way to ask Python if its next action is about to return a value to a variable, and change action, if that's the case? I was thinking: class MyClass(object): def __init__(*params): self.end = self.method(*params) def __asgn__(self): return self.method(*params).split('\n') def __str__(self): """this is the fallback if __asgn__ is not called""" return self.method(*params)

    Read the article

  • Help in restructuring a project

    - by mrblah
    I have a commerce application, asp.net mvc. I want it to be extensible in the sense others can create other payment providers, as long as they adhere to the interfaces. /blah.core /blah.web /blah.Authorize.net (Implementation of a payment provider using interfaces Ipaymentconfig and paymentdata class) Now the problem is this: /blah.core - PaymentData /blah.core.interfaces - IPaymentConfig where Payment Data looks like: using blah.core; public class PaymentData { public Order Order {get;set;} } IPayment data contains classes from blah.core like the Order class. Now I want to use the actual Authorize.net implementation, so when I tried to reference it in the blah.core project I got a circular dependency error. How could I solve this problem? Many have said to break out the interfaces into their own project, but the problem is PaymentData references entities that are found in blah.core also, so there doesn't seem to be a way around this (in my head anyhow). How can I redesign this?

    Read the article

  • why can not create instance from any class out side of constructor?

    - by Phsika
    why i generate instance outside of class. i give inheritance snifC to sinifD i need to create instance sinifC sinifc= new sinifC() in SinifD out side of constructor? public class sinifC { public void method3() { Console.WriteLine("Deneme3"); } } public class sinifD : sinifC { void method4() { Console.WriteLine("Deneme4"); } public sinifD() { sinifC sinifc = new sinifC(); sinifc.method3(); } } i want to make it below: public class sinifC { public void method3() { Console.WriteLine("Deneme3"); } } public class sinifD : sinifC { void method4() { Console.WriteLine("Deneme4"); } sinifC sinifc = new sinifC(); sinifc.method3(); } Error: Invalid token '(' in class, struct, or interface member declaration

    Read the article

  • Is it best to make fewer calls to the database and output the results in an array?

    - by Jonathan
    I'm trying to create a more succinct way to make hundreds of db calls. Instead of writing the whole query out every time I wanted to output a single field, I tried to port the code into a class that did all the query work. This is the class I have so far: class Listing { /* Connect to the database */ private $mysql; function __construct() { $this->mysql = new mysqli(DB_LOC, DB_USER, DB_PASS, DB) or die('Could not connect'); } function getListingInfo($l_id = "", $category = "", $subcategory = "", $username = "", $status = "active") { $condition = "`status` = '$status'"; if (!empty($l_id)) $condition .= "AND `L_ID` = '$l_id'"; if (!empty($category)) $condition .= "AND `category` = '$category'"; if (!empty($subcategory)) $condition .= "AND `subcategory` = '$subcategory'"; if (!empty($username)) $condition .= "AND `username` = '$username'"; $result = $this->mysql->query("SELECT * FROM listing WHERE $condition") or die('Error fetching values'); $info = $result->fetch_object() or die('Could not create object'); return $info; } } This makes it easy to access any info I want from a single row. $listing = new Listing; echo $listing->getListingInfo('','Books')->title; This outputs the title of the first listing in the category "Books". But if I want to output the price of that listing, I have to make another call to getListingInfo(). This makes another query on the db and again returns only the first row. This is much more succinct than writing the entire query each time, but I feel like I may be calling the db too often. Is there a better way to output the data from my class and still be succinct in accessing it (maybe outputting all the rows to an array and returning the array)? If yes, How?

    Read the article

  • AS3 - Can I know if a class implements an interface (or is a subclass of another class) ?

    - by lk
    With this code function someFunction(classParam:Class):Boolean { // how to know if classParam implements some interface? } i.e. Comparing classParam with IEventDispatcher interface: someFunction(EventDispatcher) // returns true someFunction(Object) // returns false I know it can't be done with is operator. But, is there a way to do it? Is there a way to know if a class implements some interface? (or is a subclass of another class?)

    Read the article

  • Mutate an object into an instance of one its subclasses

    - by Gohu
    Hi, Is it possible to mutate an object into an instance of a derived class of the initial's object class? Something like: class Base(): def __init__(self): self.a = 1 def mutate(self): self = Derived() class Derived(Base): def __init__(self): self.b = 2 But that doesn't work. >>> obj = Base() >>> obj.mutate() >>> obj.a 1 >>> obj.b AttributeError... If this isn't possible, how should I do otherwise? My problem is the following: My Base class is like a "summary", and the Derived class is the "whole thing". Of course getting the "whole thing" is a bit expensive so working on summaries as long as it is possible is the point of having these two classes. But you should be able to get it if you want, and then there's no point in having the summary anymore, so every reference to the summary should now be (or contain, at least) the whole thing. I guess I would have to create a class that can hold both, right? class Thing(): def __init__(self): self.summary = Summary() self.whole = None def get_whole_thing(self): self.whole = Whole()

    Read the article

  • why can not see my method if i implamented interface to normal class?

    - by Phsika
    i can not see MyLoad.TreeLoader(.... but why i can not see? i implemented iloader to TreeViewLoad. i should see TreeLoader why? namespace Rekursive { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //treeView1.Nodes.Add("Test"); iloader MyLoad = new TreeViewLoad(); MyLoad.loader("test", treeView1, 1); // i can not see MyLoad.TreeLoader(.... but why i can not see? // i implemented iloader to TreeViewLoad. i should see TreeLoader why? //TreeViewLoad myloader = new TreeViewLoad(); } } interface iloader { void loader(string nodeName, TreeView myTre, int id); } class TreeViewLoad : iloader { public void TreeLoader(TreeView tre) { // i will call loader... } public void loader(string nodeName, TreeView myTre, int id) { myTre.Nodes.Add(nodeName + id.ToString()); if (id

    Read the article

< Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >