Flutter - How to use data from equal built classes? - flutter

I want to build an app for my pupil which generates tasks out of sentence blocks.
For example I created two classes, apple and pear, with nearly the same structure. They return a question built out of the sentence blocks which are defined in the classes. In both classes is a GenerateQuestion()-function for that.
Now I want to build some kind of overclass, which picks a random class of i.e. apple or pear and then returns the strings from the functions. The functions names are the same, but I can't figure out how to get data from a random choosen class. Hoping for help. Thanks in advance.
Update: Here is the code I wrote so far (I tried to translate it properly):
import 'dart:math';
int randomminmax1 = 0;
int randomminmax2 = 0;
int randomminmax3 = 0;
List classes = [apple, pear];
class overClass {
static pickClass(){
int randomClassItem = Random().nextInt(classes.length);
print(classes[randomClassItem]);
return classes[randomClassItem];
}
}
class apple {
static String giveQuestion() {
randomminmax1 = 2 + Random().nextInt(15 - 2);
randomminmax2 = randomminmax1 * (2+Random().nextInt(12 - 2));
randomminmax3 = 2 + Random().nextInt(30 - 2);
List value_1 = [" boxes", " bags", " bucket"];
List verbs = ["cost","have a price of", "are offered for"];
List value_2 = ["Euro"];
List questionWords = [""];
int randomIndexValue1 = Random().nextInt(value_1.length);
int randomIndexVerbs = Random().nextInt(verbs.length);
int randomIndexValue2 = Random().nextInt(value_2.length);
String value = randomminmax1.toString() + value_1[randomIndexValue1].toString() + " apples" + verbs[randomIndexVerbs].toString() + " " + randomminmax2.toString() + " " + value_2[randomIndexValue2].toString() + ".\n";
String question = "How much are " + randomminmax3.toString() + value_1[randomIndexValue1].toString() + "?\n";
return value + question;
}
static String giveAnswer(){
double result = (randomminmax2/randomminmax1)*randomminmax3;
return result.toStringAsFixed(2) + " Euro.";
}
}
class pear {
static String giveQuestion() {
randomminmax1 = 2 + Random().nextInt(15 - 2);
randomminmax2 = randomminmax1 * (2+Random().nextInt(12 - 2));
randomminmax3 = 2 + Random().nextInt(30 - 2);
List value_1 = [" boxes", " bags", " bucket"];
List verbs = ["cost","have a price of", "are offered for"];
List value_2 = ["Euro"];
List questionWords = [""];
int randomIndexValue1 = Random().nextInt(value_1.length);
int randomIndexVerbs = Random().nextInt(verbs.length);
int randomIndexValue2 = Random().nextInt(value_2.length);
String value = randomminmax1.toString() + value_1[randomIndexValue1].toString() + " pears" + verbs[randomIndexVerbs].toString() + " " + randomminmax2.toString() + " " + value_2[randomIndexValue2].toString() + ".\n";
String question = "How much are " + randomminmax3.toString() + value_1[randomIndexValue1].toString() + "?\n";
return value + question;
}
static String giveAnswer(){
double result = (randomminmax2/randomminmax1)*randomminmax3;
return result.toStringAsFixed(2) + " Euro.";
}
}
static String giveAnswer(){
double result = (randomminmax2/randomminmax1)*randomminmax3;
return result.toStringAsFixed(2) + " Euro.";
}
}

Can you try to create a superclass that all question classes will inherit and then get the subclasses and programmatically call functions. Try to see here

At least I managed to give my values directly from the classes into the list. But then I got problems with the int-variables, which were built wrong.
My "solution": I converted my classes into isolated flutter widgets, which works fine, except the problem that I'm not able to put the widgets into a list, from where they are picked randomly...but therefore I'll write a new post.
Thank you Moustapha for your help (the superclass idea sounds good, but way too hard to code for me) ;)!

Related

Parallel execution with Jbehave with pico (jbehave-pico)

I'm new Jbehave. Im trying to find a way to achieve world in cucumber with Jbehave.
I generated project with jbehave with pico archetype. Im trying to run two stories in parallel. I updated threads in pom.xml to 2.
Consider a sample stepdef class as below
public class PojoSteps {
public Pojo pojo;
public PojoSteps(Pojo pojo){
this.pojo = pojo;
System.out.println(" ##" + new Timestamp(System.currentTimeMillis()) + " * this is " + this + ". In PojoSteps constructor. Pojo created is:" + this.pojo + ". Thread = " + Thread.currentThread().getId());
}
#Given("I have a pojo with $i")
public void iHaveAPojoWith1(int i){
pojo.setI(i);
System.out.println(" ##" + new Timestamp(System.currentTimeMillis()) + " * this is " + this + ".In iHaveAPojoWith1. pojo = " + this.pojo +". Value of To be set = " + i +". Value set Pojo.getI() = " + this.pojo.getI() + ". Thread = " + Thread.currentThread().getId());
}
#When("I wait for some time")
public void randomWait() throws InterruptedException {
Thread.sleep(new Random().nextInt(200));
}
#Then("my pojo should still have $expectedi")
public void myPojoShouldStillHave1(int expectedi){
System.out.println(" ##" + new Timestamp(System.currentTimeMillis()) + " * this is " + this +". In myPojoShouldStillHave1. pojo = " + this.pojo + ". expected = " + expectedi + ". actual = " + this.pojo.getI() + ". Thread = " + Thread.currentThread().getId());
Assert.assertEquals(this.pojo.getI(), expectedi);
}
}
I have Pojo model as below
public class Pojo {
private int i;
public void setI(int i){
this.i = i;
}
public int getI(){
return this.i;
}
}
My two stories are as below
PojoOne.story
Scenario: scenario description
Given I have a pojo with 1
When I wait for some time
Then my pojo should still have 1
PojoTwo.story
Scenario: random description
Given I have a pojo with 2
When I wait for some time
Then my pojo should still have 2
I have MyStories class which extends JUnitStories as below
public class MyStories extends JUnitStories {
....
private PicoContainer createPicoContainer() {
MutablePicoContainer container = new DefaultPicoContainer(new Caching().wrap(new ConstructorInjection()));
container.addComponent(PojoSteps.class);
container.addComponent(Pojo.class);
return container;
}
}
When I don't run stories in parallel, they succeed. When I run stories in parallel, they are failing.
##2020-01-02 20:35:36.53 * this is learning.steps.PojoSteps#49f3f232. In PojoSteps constructor. Pojo created is:learning.Support.Pojo#4aa9e824. Thread = 12
##2020-01-02 20:35:36.531 * this is learning.steps.PojoSteps#49f3f232.In iHaveAPojoWith1. pojo = learning.Support.Pojo#4aa9e824. Value of To be set = 1. Value set Pojo.getI() = 1. Thread = 12
##2020-01-02 20:35:36.532 * this is learning.steps.PojoSteps#6136e035. In PojoSteps constructor. Pojo created is:learning.Support.Pojo#1f4412c8. Thread = 13
##2020-01-02 20:35:36.533 * this is learning.steps.PojoSteps#6136e035.In iHaveAPojoWith1. pojo = learning.Support.Pojo#1f4412c8. Value of To be set = 2. Value set Pojo.getI() = 2. Thread = 13
##2020-01-02 20:35:36.558 * this is learning.steps.PojoSteps#6136e035. In myPojoShouldStillHave1. pojo = learning.Support.Pojo#1f4412c8. expected = 1. actual = 2. Thread = 12
##2020-01-02 20:35:36.668 * this is learning.steps.PojoSteps#6136e035. In myPojoShouldStillHave1. pojo = learning.Support.Pojo#1f4412c8. expected = 2. actual = 2. Thread = 13
...
Then my pojo should still have 1 (FAILED)
(java.lang.AssertionError: expected:<2> but was:<1>)
I'm not able to find documentation on how to run tests in parallel with Jbehave and pico. Also I need to have a model outside my stepdef class as I will be having multiple stefdef classes which will share the same model instance.
After reading a bit more and trying out Jbehave with spring,
1. I think there is no way to get different instances of stepdef created per thread.
2. In Jbehave, there is no equivalent of cucumber's world object which is threadsafe.
As #VaL mentioned in the comments of the questions, we have to make thinks threadsafe explicitly.
This is my understanding as of now. If there is any better way - kindly let me know.

Google Play Games leaderboard custom

I want to implement this
"my ranking : Top 13% (25034 rank)"
What I've tried↓
Social.LoadScores("CgkI1...", scores => {...})
: "scores.Length" was returned only up to 25.
ILeaderboard lb = Social.CreateLeaderboard();
lb.id = "CgkI1...";
uint max_player = lb.maxRange;
: failed..
I don't know in leaderboard player count and my rank.
please help me what can I do..
I succeeded on my own:
ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
lb.id = "CgkI1...";
lb.userScope = UserScope.Global;
lb.range = new Range(1,10);
lb.timeScope = TimeScope.AllTime;
lb.LoadScores(scores =>
{
uint all_player = lb.maxRange;
int my_rank = lb.localUserScore.rank;
decimal percent = (decimal)my_rank / (decimal)all_player;
text.text = scores.ToString() + "\nAllPlayer: " + all_player + "\nMyRank: " + my_rank + "\nMyScore: " +lb.localUserScore.value.ToString() + "\nPercent: " + percent + "%";
});

Studio won't print array elements when I test. (Java)

I'm working with eclipse and when I want the program to print either all the array elements or just a single array element via indexing. It doesn't return an error or even an address when I run the program.
import java.util.Scanner;
public class FavoriteListMaker {
public static void main(String[] args)
{
Scanner inputDevice = new Scanner(System.in);
System.out.println("This program is to help you order a favorites list. Please enter the amount of items on the list.");
int ListSize = inputDevice.nextInt();
String [] TopXA = new String [ListSize + 1];
int [] TopXB = new int[ListSize + 1];
for (int x = 0; x < TopXA.length; ++ x)
{
System.out.println("Please enter an item to be organized on the list");
String item = inputDevice.nextLine();
TopXA[x] = item;
System.out.println("You have " + (ListSize - x) + " items left to fill on the list.");
}
System.out.println("Now we will compare each item on the list with every item on the list one at a time.");
System.out.println("We will ask you a series a question on whether you like item A better then item B and tally the score.");
System.out.println("At the end the item with the most points wins.");
for (int y = 0; y < TopXA.length; ++ y)
for (int z = 0; z < TopXA.length; ++ z)
{
String compareA = TopXA[y];
String compareB = TopXA[z];
System.out.println("Do you prefer " + compareA + " or " + compareB + " .");
System.out.println("If you prefer " + compareA + "Please press 1. If you prefer " + compareB + " please press 2.");
int choice = inputDevice.nextInt();
switch(choice)
{
case 1:
TopXB[y] =+ 1;
break;
case 2:
TopXB[z] =+ 2;
break;
default:
System.out.print("I'm sorry but that is not a valid input.");
}
}
When I run the code it will print out. "Do you prefer or ." instead of the array element.
Disclaimer - I don't have eclipse, I dont program in Java
Please check two things
1) The for loop for y doesn't have curly brackets
2) Please check array 'TopXA' to see if 'item' is being populated in array once you input it.
3) Are CompareA and CompareB being assigned values?
EDIT - found problem
Add scanner.nextLine(); after the nextINt line.
Your problem is that the nextInt() method is not consuming the newline character (see other question). This leads to the fact that your first element in the list is empty. In the first iteration (y=0, z=0) of the nested for-loops this empty element gets printed two times.
Try adding inputDevice.nextLine() after each nextInt() call and you will see that it is working ;)
And PLEASE: Don't name variables uppercase!
import java.util.Scanner;
public class FavoriteListMaker {
public static void main(String[] args)
{
Scanner inputDevice = new Scanner(System.in);
System.out.println("This program is to help you order a favorites list. Please enter the amount of items on the list.");
int listSize = inputDevice.nextInt();
inputDevice.nextLine();
String [] topXA = new String [listSize];
int [] topXB = new int[listSize];
for (int x = 0; x < topXA.length; ++x)
{
System.out.println("Please enter an item to be organized on the list");
String item = inputDevice.nextLine();
topXA[x] = item;
System.out.println("You have " + (listSize - x) + " items left to fill on the list.");
}
System.out.println("Now we will compare each item on the list with every item on the list one at a time.");
System.out.println("We will ask you a series a question on whether you like item A better then item B and tally the score.");
System.out.println("At the end the item with the most points wins.");
for (int y = 0; y < topXA.length; ++y)
{
for (int z = 0; z < topXA.length; ++z)
{
String compareA = topXA[y];
String compareB = topXA[z];
System.out.println("Do you prefer " + compareA + " or " + compareB + " .");
System.out.println("If you prefer " + compareA + "Please press 1. If you prefer " + compareB + " please press 2.");
int choice = inputDevice.nextInt();
inputDevice.nextLine();
switch(choice)
{
case 1:
topXB[y] =+ 1;
break;
case 2:
topXB[z] =+ 2;
break;
default:
System.out.print("I'm sorry but that is not a valid input.");
}
}
}
}
}

Create Alias using barclaycard payment epdq - unknown order/1/s/

Below is the code used for creating the Alias which does not work and throw an error
"unknown order/1/s/". The same code works for payment if I remove the code for Alias.
Not sure what am I missing?
I could log into the epdq barclaycard account and see the error which is "unknown order/1/s/". I can also create Alias manually through the epdq account, but just cant get to the orderstandard.asp page without error (when alias hidden fields and code used).
I would be glad if someone could help me.
<body>
<form id="OrderForm" action="https://payments.epdq.co.uk/ncol/prod/orderstandard.asp" method="post" runat="server">
<div>
<asp:HiddenField ID="AMOUNT" runat="server" />
<asp:HiddenField ID="CN" runat="server" />
...
<asp:HiddenField ID="ALIAS" runat="server" />
<asp:HiddenField ID="ALIASUSAGE" runat="server" />
<asp:HiddenField ID="ALIASOPERATION" runat="server" />
<asp:HiddenField ID="SHASign" runat="server" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text; //for Encoding
using System.Security.Cryptography; //for SHA1
public partial class _DefaultAliasTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//-- Set Values (these would be pulled from DB or a previous page). -- //
bool isAlias = true;
//- Customer/Order Details - //
string strUserTitle = "Mr"; // Customer details
string strUserFirstname = "Edward";
string strUserSurname = "Shopper";
string strBillHouseNumber = "123"; // Address Details
string strAd1 = "Penny Lane";
string strAd2 = "Central Areas";
string strBillTown = "Middlehampton"; // Bill Town
string strBillCountry = "England"; // Bill Country
string strPcde = "NN4 7SG"; // Postcode
string strContactTel = "01604 567 890"; // Contact Telephone number
string strShopperEmail = "test#test.com"; // shopper Email
string strShopperLocale = "en_GB"; // shopper locale
string strCurrencyCode = "GBP"; // CurrecncyCode
string strAddressline1n2 = strBillHouseNumber + " " + strAd1 + ", " + strAd2; // Concatenated Address eg 123 Penny Lane Central Areas
string strCustomerName = strUserTitle + " " + strUserFirstname + " " + strUserSurname; // Concatenated Customer Name eg Mr Edward Shopper
string strPaymentAmount = "100"; // This is 1 pound (100p)
string strOrderDataRaw = "HDTV - AVTV3000"; // Order description
string strOrderID = "ORD1234556Y"; // Order Id - **needs to be unique**
//- integration user details - //
string strPW = "xxxxxx!?"; // Update with the details you entered into back office
string strPSPID = "epdqxxxxxxx"; // update with the details of the PSPID you were supplied with
//- payment design options - '//
string strTXTCOLOR = "#005588"; // Page Text Colour
string strTBLTXTCOLOR = "#005588"; // Table Text Colour
string strFONTTYPE = "Helvetica, Arial"; // fonttype
string strBUTTONTXTCOLOR = "#005588"; // Button Text Colour
string strBGCOLOR = "#d1ecf3"; // Page Background Colour
string strTBLBGCOLOR = "#ffffff"; // Table BG Colour
string strBUTTONBGCOLOR = "#cccccc"; // Button Colour
string strTITLE = "Testing - Secure Payment Page"; // Title
string strLOGO = "https://www.site.com/logo.png"; // logo location
string strPMLISTTYPE = "1"; // Payment Method List type
string strALIAS = System.Guid.NewGuid().ToString();
string strALIASUSAGE = "usage"; // ALIAS USAGE
string strALIASOPERATION = "BYMERCHANT"; // ALIAS Operation
//= create string to hash (digest) using values of options/details above. MUST be in field alphabetical order!
string plainDigest =
"AMOUNT=" + strPaymentAmount + strPW +
"BGCOLOR=" + strBGCOLOR + strPW +
"BUTTONBGCOLOR=" + strBUTTONBGCOLOR + strPW +
"BUTTONTXTCOLOR=" + strBUTTONTXTCOLOR + strPW +
"CN=" + strCustomerName + strPW +
"COM=" + strOrderDataRaw + strPW +
"CURRENCY=" + strCurrencyCode + strPW +
"EMAIL=" + strShopperEmail + strPW +
"FONTTYPE=" + strFONTTYPE + strPW +
"LANGUAGE=" + strShopperLocale + strPW +
"LOGO=" + strLOGO + strPW +
"ORDERID=" + strOrderID + strPW +
"OWNERADDRESS=" + strAddressline1n2 + strPW +
"OWNERCTY=" + strBillCountry + strPW +
"OWNERTELNO=" + strContactTel + strPW +
"OWNERTOWN=" + strBillTown + strPW +
"OWNERZIP=" + strPcde + strPW +
"PMLISTTYPE=" + strPMLISTTYPE + strPW +
"PSPID=" + strPSPID + strPW +
"TBLBGCOLOR=" + strTBLBGCOLOR + strPW +
"TBLTXTCOLOR=" + strTBLTXTCOLOR + strPW +
"TITLE=" + strTITLE + strPW +
"TXTCOLOR=" + strTXTCOLOR + strPW +
"";
if (isAlias)
{
plainDigest =
plainDigest +
"ALIAS=" + strALIAS + strPW +
"ALIASUSAGE=" + strALIASUSAGE + strPW +
"ALIASOPERATION=" + strALIASOPERATION + strPW +
"";
}
//Payment
//-- insert payment details into hidden fields -- //
AMOUNT.Value = strPaymentAmount; // PaymentAmmount : (100 pence)
CN.Value = strCustomerName; // Customer Name
COM.Value = strOrderDataRaw; // OrderDataRaw (order description)
CURRENCY.Value = strCurrencyCode; // CurrecncyCode
EMAIL.Value = strShopperEmail; // shopper Email
FONTTYPE.Value = strFONTTYPE; // fonttype
LANGUAGE.Value = strShopperLocale; // shopper locale
LOGO.Value = strLOGO; // logo location
ORDERID.Value = strOrderID; // *this ORDER ID*
OWNERADDRESS.Value = strAddressline1n2; // AddressLine2
OWNERCTY.Value = strBillCountry; // Bill Country
OWNERTELNO.Value = strContactTel; // Contact Telephone number
OWNERTOWN.Value = strBillTown; // Bill Town
OWNERZIP.Value = strPcde; // Postcode
PMLISTTYPE.Value = strPMLISTTYPE; // Payment Method List type
PSPID.Value = strPSPID; // *Your PSPID*
BGCOLOR.Value = strBGCOLOR; // Page Background Colour
BUTTONBGCOLOR.Value = strBUTTONBGCOLOR; // Button Colour
BUTTONTXTCOLOR.Value = strBUTTONTXTCOLOR; // Button Text Colour
TBLBGCOLOR.Value = strTBLBGCOLOR; // Table BG Colour
TBLTXTCOLOR.Value = strTBLTXTCOLOR; // Table Text Colour
TITLE.Value = strTITLE; // Title
TXTCOLOR.Value = strTXTCOLOR; // Page Text Colour
if (isAlias)
{
ALIAS.Value = strALIAS;
ALIASUSAGE.Value = strALIASUSAGE;
ALIASOPERATION.Value = strALIASOPERATION;
}
SHASign.Value = SHA1HashData(plainDigest); // Hashed String of plain digest put into sha sign using SHA1HashData function
}
}
I found the answer to my question via customer service to Barclaycard epdq. I hope this helps others. For me the answer is the point selected in bold below.
Please see below details on how to rectify the error ‘unknown order/1/s/’:
This error indicates that ePDQ has been unable to decrypt the SHASIGN HTML Form value sent with the customer when you redirect them from your website to the ePDQ Hosted Payment Page.
The typical reasons for this error are:
• The SHA-IN Passphrase value configured in the ePDQ back office does not match the value you used to encrypt the transaction data used to create the SHASIGN parameter (please also ensure you are sending transactions to the correct ePDQ environment – TEST or PRODUCTION)
• You have not arranged the parameters in alphabetical order when calculating the SHASIGN in your server-side code
• You have not correctly declared some of the parameters – all parameters and values are case sensitive (all parameter names must be upper case)
• You have set a HASH ALGORITHM value that is different to the SHA method used in your server side script (for example, you have configured SHA-256 in the ePDQ Back Office Technical Information settings, but are using a SHA-1 method in your encryption process).
• You have passed additional parameter/value pairs in the HTML Form that have not been included in the SHA-IN calculation
For more information please refer to the Basic & Advanced e-Commerce integration guides located in the ePDQ Back Office under Support –> Integration & User Manuals.

Can I send SSRS custom subscription e-mails?

I need to send some e-mails containing a SSRS report to a list of persons, representing the amount of work items they have left until a certain date.
What I would like to do is to send each person in the list, the customized report that reflects his progress, so my question is: can I send different reports to the persons in the list (like sending it's e-mail address as a parameter to the report), or can I only send the same report to all people in the list?
Thanks!
If you do not have enterprise (to utilize data driven subscription as #StephLocke mentioned), you can programmatically generate SSRS subscriptions using the SSRS web service.
Your code would look something like this (SubscriptionRequest is a custom class I use, its properties should be intuitive):
static void generateSubscription()
{
if (SubscriptionRequests.Count < 1) return;
NetworkCredential credentials = new NetworkCredential("user", "pass");
reports.ReportingService2005 rs = new reports.ReportingService2005();
rs.Credentials = credentials;
DateTime topDatetime = DateTime.Now;
topDatetime = topDatetime.AddMinutes(2);
foreach (SubscriptionRequest x in SubscriptionRequests)
{
reports.ExtensionSettings extensionSettings = new reports.ExtensionSettings();
List<reports.ParameterValue> extParameters = new List<reports.ParameterValue>();
List<reports.ParameterValue> parameters = new List<reports.ParameterValue>();
string description = "Email: ";
string eventType = "TimedSubscription";
extensionSettings.Extension = "Report Server Email";
string scheduleXml = "<ScheduleDefinition><StartDateTime>";
scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
scheduleXml += "</StartDateTime></ScheduleDefinition>";
parameters.Add(new reports.ParameterValue() { Name = "abc", Value = x.id });
extParameters.Add(new reports.ParameterValue() { Name = "RenderFormat", Value = x.renderFormat });
extParameters.Add(new reports.ParameterValue() { Name = "TO", Value = x.email });
extParameters.Add(new reports.ParameterValue() { Name = "ReplyTo", Value = x.replyTo });
extParameters.Add(new reports.ParameterValue() { Name = "IncludeReport", Value = "True" });
extParameters.Add(new reports.ParameterValue() { Name = "Subject", Value = "subject - " + " (" + x.id.ToString() + ")" });
extParameters.Add(new reports.ParameterValue() { Name = "Comment", Value = x.body });
extensionSettings.ParameterValues = extParameters.ToArray();
description += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
description += " (" + x.a + " - " + x.b + " - " + x.c + ")";
string _reportName = "/report";
rs.CreateSubscription(_reportName, extensionSettings, description, eventType, scheduleXml, parameters.ToArray());
topDatetime = topDatetime.AddSeconds(30);
}
}
More examples can be found here.
Yes you can use a data driven subscription to do this. Unfortunately this isn't available to every edition (2008+, enterprise only I believe) so you may not be able to use this functionality.
There are more details available: http://technet.microsoft.com/en-us/library/ms159150.aspx