Browsing 7239 questions and answers with Jon Skeet

joda time PeriodFormatter does not print years

I have a formatter as below: private static PeriodFormatter formatter = new PeriodFormatterBuilder() .printZeroNever() .appendYears().appendSuffix("...
Jon Skeet
people
quotationmark

The underlying problem here is your use of Duration to start with, IMO. A Duration is just a number of milliseconds... it's somewhat troublesome to consider the number of years in that, as a year is either 365 or 366 days (and even that... more 9/20/2016 7:29:36 AM

people

Argument1: Cannot convert from 'System.IO.Stream' to 'String'

I'm stumped on this, and could use some assistance. I've done web searches, and read documentation for the last several hours, and have had no luck. I'm getting an error that...
Jon Skeet
people
quotationmark

JObject.Parse takes a string, not a Stream. You're trying to pass it response, which is a Stream. To fix it, just use HttpClient.GetStringAsync instead, e.g. using (HttpClient client = new HttpClient()) { var response =... more 9/20/2016 7:21:50 AM

people

Integer gets automatically set to 0 C#

I am doing an exercise on making a small console program which shows how fast a car is moving and a function to make it go either faster or slower. So here is my class called...
Jon Skeet
people
quotationmark

Your Speed property is the problem. Here's the code: public int Speed //access private int speed { get { return speed; } set { speed = Speed; } } The getter is fine - it returns the value of the private variable. The setter,... more 9/19/2016 2:56:43 PM

people

Using random function in selecting an object if two same distance values

I have an ArrayList unsolvedOutlets containing object Outlet that has attributes longitude and latitude. Using the longitude and latitude of Outlet objects in ArrayList...
Jon Skeet
people
quotationmark

Note: I believe fabian's solution is superior to this, but I've kept it around to demonstrate that there are many different ways of implementing this... I would probably: Create a new type which contained the distance from the outlet as... more 9/19/2016 6:32:15 AM

people

How to convert digit month to the full name of month in C# console

I want to convert digit month that is inputed by User to the name of month. I find it easily to use if else condition, but is there any function I can use without using condition?...
Jon Skeet
people
quotationmark

There are two reasonably simple options: Construct a date using that number as the month, and then format it with a custom format, e.g. DateTime date = new DateTime(2000, month, 1); string monthName = date.ToString("MMMM"); Use... more 9/18/2016 3:46:46 PM

people

Java Cannot find symbol get.Method but Method is declared

I was given this class and told to fix errors and Finnish the class. For this assignment, you will need to develop a test driver and a comparable class. Luckily, Prof. Fuller...
Jon Skeet
people
quotationmark

This is the problem: public int compareTo(Object other) You've said you can compare this object to any other object. You can't call other.getMidi(), because getMidi() isn't a method declared on Object. I would suggest you change your... more 9/16/2016 9:27:06 PM

people

Java. How to test date created with LocalDateTime.now()

I have this class class MyObject { private LocalDateTime date; public LocalDateTime getDate() { return this.date; } public void myMethod() { this.date =...
Jon Skeet
people
quotationmark

I cannot mock now() because it is static Indeed - but fortunately, you don't have to. Instead, consider "a date/time provider" as a dependency, and inject that as normal. java.time provides just such a dependency: java.time.Clock. In... more 9/16/2016 9:19:20 AM

people

Peso Symbol in C#

if (num1 == 5) { Console.WriteLine("\nThe " + num2 + " kilo/s of {0} " + 28 + " per kilo ", "GRAPES"); Console.WriteLine("The total amount is {0}{1}",...
Jon Skeet
people
quotationmark

Sounds like you want to provide the culture en-PHI... although that isn't a valid culture name apparently. Perhaps you just want phi as the language? var culture = CultureInfo.GetCultureInfo("phi"); var text = string.Format(culture, "The... more 9/16/2016 8:20:29 AM

people

String in byte form to original string in java

I wrote a code writing 8 different values of sine in byte form (using .getbytes) into a text file. After I run it a file is created containing the following: [B@5f18cd5 ...
Jon Skeet
people
quotationmark

You can't. You've already lost all the important data. Calling toString() on a byte[] doesn't give you anything useful, because arrays in Java don't override toString()... so you're getting the implementation from Object, which just... more 9/16/2016 7:46:26 AM

people

Json.net serialize numeric properties as string

I am using JsonConvert.SerializeObject to serialize a model object. The server expects all fields as strings. My model object has numeric properties and string properties. I can...
Jon Skeet
people
quotationmark

You can provide your own JsonConverter even for numeric types. I've just tried this and it works - it's quick and dirty, and you almost certainly want to extend it to support other numeric types (long, float, double, decimal etc) but it... more 9/16/2016 7:40:08 AM

people