Hey guy I am studying and I am trying to solve this hard exercise.
on the above picture I am trying to implement this into a code: however I find it extremely hard. I have tried the following at the moment, don't know if its correct or not, can someone please help me?
just some info that the assignment says:
-The attribute product should be an objekt of the class Product
Shipping adress and billing address should be an object of the class Adress
User should also be an object of the class User
CalculateOrder (should calculate order and sum the price for everything
Calculate vat should add 25 %
printAllorders() should print all orders
what is mean by "object of the class"
what is mean by "object of the class"
Object off the class means you build an instance of it like
Proudct p = new Product();
With this you build an instance or object of the Class Product
Your class lineItem has an Attribute Product.
This means that the attribute is not of an primitive type like int, boolean .... it is of type product
public class LineItem(){
int id;
double price;
int quantity;
Product prod;
}
Related
I have a register class that has a pointer to a student class. I'd like to be able to sort on the name of the Student - is that possible?
var Register = Parse.Object.extend("Register");
var regquery = new Parse.Query(Register);
regquery.equalTo("Group", group);
regquery.equalTo("AttDate", date);
regquery.include("Student");
regquery.ascending(??????); // Is it possible to sort on the name of the Student?
regquery.find({...
No, this is not possible. You need to rethink your data model, or include the name field in your Register object. This last option is an easy workaround.
I have
class A{
users = new B().users;
}
class B{
users : Array<any> = [];
}
at the first run the users fields are the same in both classes , but when users in class B changed the users in A isn't changed .
example : at first A.users and B.users are [user1]
when I add new user to B.users ([user1, user2]) A.users still the same .
Any idea ?
Thanks in advance ...
Any idea
Depends on how you add them. If you are doing something like b.users = b.users.concat([another]); then b.users will be a new array distict from the one that is referenced by A.
NOTE: Having two classes point the same array seems like a bad idea where mutation will quickly get out of hand and you will not know what moved your cheese. But there isn't more architecture advice I can give without a larger context that you can present in a separate question if you want.
I created a pointer column (emailAddress) in parse and pointed it to the _User class. But how do I point this to a specific column(email) in the _User class? Is this done in the code or is this done in Parse? I'm building an app in Javascript.
Pointers are for references to Classes, you cannot create a Pointer for a Column on a Class.
If you want a copy of a column (e.g. a String emailAddress column), you can create an after-save Cloud Function for the User class that checks if the emailAddress is dirty, and if so updates your other class. I would recommend against this though unless there's a very good reason for doing this.
If you have another class that needs one or more column values from your User class the usual way to handle this is to just create a user column of type Pointer<_User>, then when querying your class just tell it to include the user column, e.g.:
query.include('user');
Then in your find() or whatever you use to run the query you can now do the following:
var user = results[i].get('user');
var email = user.get('emailAddress');
I have an entity called product. There is a field called item price.
Now i have created 100 products. I want to SUM (mathematical operation) all the products "item price" field and display it in an other entity called opportunity field called "total items price".
Besides this if i create 101 product and it's "item price", "total items price" field in opportunity automatically up date itself.
So for i have SUMMED to fields of a form. e.g there is a field A and field B, multiplying field A with 3.14 and displaying result in field B.
Here is the Code.
function SumField() {
var price = Xrm.Page.getAttribute("new_price");
var total_price = Xrm.Page.getAttribute("new_total_price");
if(price.getValue() != null) {
var newValue = price.getValue() * 3.14;
total_price.setValue(newValue);
// Make sure the changes are saved back to the server - in CRM 4.0, this was crmForm.new_fieldname.ForceSubmit = true;
Xrm.Page.getAttribute("new_total_price").setSubmitMode("always");
}
}
JavaScript will not work in this scenario, atleast it will not be the most optimum solution.
Rather than handling it with JavaScript write a Plugin that fires on change in Product entity and updates the desired record of opportunity entity. (I am considering that there will be few products related to one opportunity i.e. 1:N relationship)
In case you want that change in one product will update values in all records Opportunity create a another entity say "Configuration" which will hold this value and show it on Opportunity form using JavaScript (reason being: If one product record creation updates all records of Opportunities it will impact performance of CRM)
You have some possibilities, the best choice depends of your technology expertise:
Workflow - launch workflow when the field new_total_price changed and update the opportunity related. For this you don't need any known of programming languages
Plugin - in update of your product entity you can update the related opportunity. You need know C# or VB .NET
Javascript - One solution is onload of opportunity you check if product related has (you case use FetchXML or OData for example) the new_total_price filled, with that information you can update your opportunity.
There is more alternatives but you have here some options.
I'm trying to figure out a way to create a new class instance when values are passed from an Android app to a JavaScript program. I know JS doesn't use classes, but there are ways to use functions in a similar way.
When a user presses a button in the Android app, I want to send a randomly generated ID (which I have created) to a database that stores the ID (and user info), and then have a JS program pull the ID and create a new instance for that ID. There will be multiple users accessing this at the same time, so I need to create a new instance each time a user presses the button. It will also send the ID, latitude, longitude, and time to a separate database where the location will be updated and stored every second.
For example, if 'user1' presses the button, the id (user1) will be sent to DB_1 and the ID, latitude, longitude, and timestamp will be sent to DB_2. The JS will be alerted of the new user and create an instance for user1, and then will use the ID as a variable to search DB_2 for coordinates every second. This way, if there are multiple users, each class will only search DB_2 for coordinates that pertain to that user. I need to do this because I must be able to track multiple users at the same time (and in real time) with a Google Map on the web. Let me know if you have any suggestions!
Thanks
If all you want to do is make a JavaScript object with it's own private variables then try something like
function User(id) {
this.id = id;
};
You can then use prototype functions.
User.prototype.getId = function() {
return this.Id;
};
Now you have an object with a private variable id and a getter for that variable.
You can create instances of the object like this
var user1 = new User(id1);
var user2 = new User(id2);
var user1Id = user1.getId();
var user2Id = user2.getId();
I like to use the prototype pattern because it keeps things safe and organized but you do end up using "this" a lot. There are other patterns that achieve basically the same thing, which you may prefer to use but I can't think if the name of any of them right now.
In the construct using
function User(id) {
this.id = id;
};
User.prototype.getId = function() {
return this.Id;
};
Is sort of similar to doing this in Java except without type safety.
public class User{
private int id;
public User(int id){
this.id = id;
}
public int getUserId(){
return this.id;
}
}
Of course there is a pretty big difference between the inner workings of compiled Java and interpreted JavaScript but the above method gives you a similar OO effect.
If you use this method and end up with some errors, in all probability you have left out a "this" somewhere. Every variable in the prototype function that is part of the object must have the "this." prefix.
Hope that's something along the lines of what you were looking for.