Removing decimals from division result - decimal

I am currently developing a game, and I have a small problem.
When a player buys an item from a shop, I set it to be sold at 75% the buying price.
But when the value is checked (before selling the item) it says, for example, "Can be sold for 115.0 gold"
How do I remove the ".0" from the "115"?
I'm still new to coding, any help is appreciated.
(It's also shown with brackets, I would like to remove those as well. In example: "You can sell this for (120.0) gold pieces.")
Edit: This is java.
int ShopValue = (int)Math.floor(getItemShopValue(removeId, 1, removeSlot));
String ShopAdd = "";
if (ShopValue >= 1000000000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000000000) + " billion)";
} else if (ShopValue >= 1000000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000000) + " million)";
} else if (ShopValue >= 1000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000) + "k)";
} else if (ShopValue >= 100) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1) + ")";
} else if (ShopValue >= 10) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1) + ")";
}
c.sM(c.getItems().getItemName(removeId)+": shop will buy for <col=255>"+ShopAdd+"</col> coins");
}
}

simple way is use a integer type cast
(int)Math.floor(ShopValue*.75 / 1)

Math.floor is returning double parameter so u have to just convert it to int before you give it to ShopAdd string.

Related

How can I format this String with double x,y,total to two decimal places. output = (x + " + " + y + " = " + total);

How can I format this String with double x,y,total to two decimal places. String output = (x + " + " + y + " = " + total);
String ouput = String.format("%.2f + %.2f = %.2f",x,y,total);
System.out.println(output);
will give you the output with 2 decimal places or you can use DecimalFormat as well.

Cron expression with start and end time

I am trying to write an cron expression with a specific start time and end time everyday. i.e.
every minute from 10:15 to 17:35 everyday
One possible solution for this is writing 3 different cron expressions like this:
0 15-59 10 * * *
0 * 11-17 * * *
0 0-35 17 * * *
Is there any possible way to write this in one single cron expression ?
There is no other way to achieve it using single crone expression but to specify multiple crone expressions for specific startDate and endDate.
There is a slight modification in second crone expression though (highlighted one)
0 15-59 10 * * * (Every minute between 10:15 AM and 10:59 AM)
0 * 11-16 * * * (Every minute, between 11:00 AM and 04:59 PM)
0 0-35 17 * * * (Every minute between 05:00 PM and 05:35 PM)
Quartz Scheduler c#
run job between to hours
use corn mask:
ITrigger trigger_1 = TriggerBuilder.Create()
.ForJob("YOUR_JOB")
.WithIdentity("trigger_1")
.StartAt(startTime)
.WithCronSchedule("0 0/1 8-13 ? * SUN,MON,TUE,WED,SAT *")
.Build();
use Quartz Schedule:
trigger_1 = TriggerBuilder
.Create()
.ForJob("YOUR_JOB")
.WithIdentity("trigger_1")
.StartAt(startTime)
.WithDailyTimeIntervalSchedule(c => c
.OnEveryDay()
.WithIntervalInMinutes(1).WithRepeatCount(1)
.StartingDailyAt(new TimeOfDay(08, 30))
.EndingDailyAt(new TimeOfDay(12, 30))
)
.Build();
HashMap<String, String> weekday = new HashMap<>();
// String strDays ="[Monday, Friday]";
String strCalDay = "";
String startDate[] = fromDate.split("-");
String endDate[] = toDate.split("-");
weekday.put("MONDAY", "1");
weekday.put("TUESDAY", "2");
weekday.put("WEDNESDAY", "3");
weekday.put("THURSDAY", "4");
weekday.put("FRIDAY", "5");
weekday.put("SATURDAY", "6");
weekday.put("SUNDAY", "7");
strDays = strDays.replace("[", "").replace("]", "");
String strDay[] = strDays.trim().toUpperCase().split(",");
if (strDay != null && strDay.length > 0) {
for (int i = 0; i < strDay.length; i++) {
strCalDay = strCalDay + "," + weekday.get(strDay[i].trim().replace("\"", ""));
}
// System.out.println(" No of days :: "+ strCalDay);
strCalDay = strCalDay.replaceFirst(",", "");
//System.out.println(" No of days :: "+ strCalDay);
}
Calendar startCal = Calendar.getInstance(TimeZone.getDefault());
Calendar endCal = Calendar.getInstance(TimeZone.getDefault());
startCal.set(Integer.parseInt(startDate[0].toString()),
Integer.parseInt(startDate[1].toString()),
Integer.parseInt((startDate[2].toString())));
endCal.set(Integer.parseInt(endDate[0].toString()),
Integer.parseInt(endDate[1].toString()),
Integer.parseInt((endDate[2].toString())));
int yearsInBetween = endCal.get(Calendar.YEAR) - startCal.get(Calendar.YEAR);
int monthsDiff = endCal.get(Calendar.MONTH) - startCal.get(Calendar.MONTH);
long ageInMonths = yearsInBetween * 12 + monthsDiff;
System.out.println(" ageInMonths: " + ageInMonths);
if (startCal.get(Calendar.MONTH) != endCal.get(Calendar.MONTH)) {
if (ageInMonths == 3) {
Calendar middleMonth1 = (Calendar) startCal.clone();
middleMonth1.add(Calendar.MONTH, 1);
Calendar middleMonth2 = (Calendar) startCal.clone();
middleMonth2.add(Calendar.MONTH, 2);
int getFirstMMonth = middleMonth1.get(Calendar.MONTH);
int getSecMMonth = middleMonth2.get(Calendar.MONTH);
if (getFirstMMonth == 0) {
getFirstMMonth = 12;
System.out.println(" getFirstMMonth : " + getFirstMMonth);
}
if (getSecMMonth == 0) {
getSecMMonth = 12;
// System.out.println(" getSecMMonth : " +getSecMMonth );
}
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + "31,1-31,1-31,1-" + endDate[2] + " " +
startDate[1] + "," + getFirstMMonth + "," + getSecMMonth + "," + endDate[1] + " *";
// System.out.println(" expression for month3 : " + exp);
}
if (ageInMonths == 2) {
Calendar middleMonth1 = (Calendar) startCal.clone();
middleMonth1.add(Calendar.MONTH, 1);
//System.out.println(" get middleDate month : " + middleMonth1.get(Calendar.MONTH));
int getMiddleMonth = middleMonth1.get(Calendar.MONTH);
if (getMiddleMonth == 0) {
getMiddleMonth = 12;
// System.out.println(" getMiddleMonth : " +getMiddleMonth );
}
// System.out.println(" Outside getMiddleMonth : " +getMiddleMonth );
endCal.set(Calendar.MONTH, 11);
//System.out.println(" get middleDate month 001: " + endCal.get(Calendar.MONTH));
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + "31,1-31,1-" +
endDate[2] + " " + startDate[1] + "," +
getMiddleMonth + "," + endDate[1] + " *";
// System.out.println(" get end month2 : " + exp);
} else if (ageInMonths == 1) {
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-31,1-" +
endDate[2] + " " + startDate[1] + "," + endDate[1] + " *";
//System.out.println(" expression for one month : " + exp);
}
} else {
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + endDate[2] + " " + endDate[1] + " *";
}
System.out.println(" expression for before parameter : " + exp);
//Run with only Start Date
if (strRepeat != null && strRepeat.equalsIgnoreCase("No")) {
exp = strTimeMin + " " + strTime + " " + startDate[2] + " " + startDate[1] + " *";
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Daily")) {
exp = exp;
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Weekdays")) {
// System.out.println(" expression for weekdays before : " + exp);
exp = exp.replace("*", strCalDay);
// System.out.println(" expression for weekdays after : " + exp);
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Weekends")) {
// System.out.println(" expression for weekend before : " + exp);
exp = exp.replace("*", "6,7");
// System.out.println(" expression for weekend after : " + exp);
}
System.out.println(" cron expression ::: " + exp);

Adding multiple shapes in d3

I would like to add different shapes depending on one of the properties in my json file. I found this approach by Mike:
https://groups.google.com/forum/#!topic/d3-js/4EJDu1xOh8Y
The idea is great, I'm just not sure how to adapt it. I either want to add a circle or an svg:use element (with attr("xlink:href")). They both have (of course) different attributes. So how do I do that? What do I append? In the example, the attr("d") was also used, do I need that also?
That's what I have so far but I'm not sure what to add where.
I really appreciate your help!
var type = d3.scale.ordinal()
.domain(["Q", "C"])
.range("circle","svg:use");
for(l=0;l<4;l++){
currentsvg.selectAll("path")
.data(queryArray[l])
.enter()
.append("svg:path")
.type(function(d,i) {
if (queryArray[l][i].name.substr(0,1) == "Q"){
return type("Q");
}
else if (queryArray[l][i].name.substr(0,1) == "C"){
return type("C");
}
});
}
Below is a different solution without filtering that uses the path to draw the shapes. It doesn't use the "rect" or "circle" of svg but rather just uses the path to draw the shapes. Check out here for more on paths. Note that the circle is two connecting arcs. It also classes each shape based on the data so you can have different colors, etc using CSS. Here is a fiddle.
currentsvg.selectAll("path")
.data(data)
.enter()
.append("path")
.attr("d",function(d,i){
var path,
s = i*50,
r = 10,
w = r*2;
if (data[i] == "Q"){
path = "M" + s + " " + s + " L" + s + " " + (s+w) +
" L" + (s+w) + " " + (s+w) + " L" + (s+w) + " " + s + "Z"
}
else if (data[i] == "C"){
path = "M" + s + " " + s + " m" + -r + ", 0 " +
" a " + r + "," + r + " 0 1,0 " + r*2 + ",0" +
" a " + r + "," + r + " 0 1,0 "+ -r*2 + ",0"
}
return path;
})
.attr("class", function(d){return d == "Q" ? "rec" : "circ";})
The best way to do that is to filter the data how you want into separate data sets for each shape before you create shapes. Then you can create the shapes with that new data set.
var data = ["Q","Q","Q","C","C","Q","Q","C","Q","C"];
var circleSet = data.filter(function(d){return d === "Q";}),
squareSet = data.filter(function(d){return d === "C";});
As Lars said, that is also not how the d attribute works. Here is a working JSFiddle of the whole thing.

Beginner: concat a string from different primitives

Apologies, as I'm sure this is a stupid question, but...
Please could anyone explain to me why this:
public class java {
public static void main(String[] args) {
byte zero = 0;
short one = 1;
int three = 3;
long one2 = 1;
float onepointnought = 1.0f;
double onedotnone = 1.0;
char letterh = 'H';
char letterw = 'w';
char letterr = 'r';
char letterd = 'd';
boolean bool = true;
String output = letterh + three + one + one2 + zero + " " + letterw + zero + letterr + one + letterd + " " + (onepointnought+onedotnone) + " " + bool;
System.out.println(output);
} }
Is outputting:
77 w0r1d 2.0 true
I'm expecting it to say "H3ll0 w0r1d 2.0 true"
It's from the interactive online java tutorials over at http://www.learnjavaonline.org/
Thanks!
Neil.
In this sentence
String output = letterh + three + one + one2 + zero + " " + letterw + zero + letterr + one + letterd + " " + (onepointnought+onedotnone) + " " + bool;
the letterh contains 'H' whose ASCII value is 72 & the addition of three + one + one2 + zero is 5 because these are non-string variables, so it is displaying (72 + 5)77 in the result,
you must convert three , one , one2 , zero to sting variable

How to get X and Y from 1 point?

I am doing this in java, but the answer isn't java specific.
Here is my code:
String map = " x " +
" x o xxxx xxxx xxxx " +
" x xxxx " +
" xxxx xxxx " +
" xx xxxxxx " +
" xx " +
" xx " +
" xx x " +
" xx x " +
" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ";
for(int i = 0; i < map.length(); i++) {
if(map.charAt(i) == 'x') {
platform[i] = CCSprite.sprite("platform_2.gif");
platform[i].setPosition(x, y); //How to get x and y?
addChild(platform[i]);
platformCount++;
}
}
As you can see, for every "x" in the map string, I want to create a new platform. Now, each line of the string is 57 characters long, and I need to get the X and Y value of where that X is, but all I can retrieve is the charAt the "i" variable, in the for statement. What is a logical way to do this?
int x = i % width;
int y = i / width;
…where % is modulo and / is integer division.

Resources