• Breaking News

    Thursday, November 1, 2018

    [Java] I need help solving a logic error in my program which does calculations with fractions Ask Programming

    [Java] I need help solving a logic error in my program which does calculations with fractions Ask Programming


    [Java] I need help solving a logic error in my program which does calculations with fractions

    Posted: 01 Nov 2018 08:13 PM PDT

    New to programming, my class has a project where we need to be able to add/subtract/multiply/divide mixed numbers and simplify the answer as much as possible. An example input would be "3_1/2 - 2_1/4", which is the same as "3 and 1/2 minus 2 and 1/4"; the program should return "1_1/4". This might be more of a math question than a programming question, but my program works except for one specific test.

    This picture shows all the operations that do work, except for the one that is highlighted on line 60: https://i.imgur.com/DGi8G40.png where the expression is on the right side, and the proper answer is on the left side. "5_3/4 - 6_5/8" returns "-1_1/8" when it should be returning "-7/8".

    My code is kinda messy, since we haven't learned that much yet and I'm not aware of a more efficient way of doing this, but this is the relevant method:

    //pass 6 values: the whole number, numerator, and denominator for both operands public static String subtract(int operand1_whole, int operand1_num, int operand1_denom, int operand2_whole, int operand2_num, int operand2_denom) { //if the whole number is negative, then the negative sign must also carry to the fraction if (operand1_whole < 0) { operand1_num = -operand1_num; } if (operand2_whole < 0) { operand2_num = -operand2_num; } //find a common denominator, and multiply the numerators to keep the fraction equivalent int commonDenom = operand1_denom * operand2_denom; int commonNum1 = operand1_num * operand2_denom; int commonNum2 = operand2_num * operand1_denom; //subtract the whole numbers and the numerators int finalWhole = operand1_whole - operand2_whole; int finalNum = commonNum1 - commonNum2; //method gcd() finds the greatest common divisor between the numerator and the denominator; then, divide numerator and denominator by gcd to simplify fraction int gcd = gcd(finalNum, commonDenom); finalNum /= gcd; int finalDenom = commonDenom/gcd; //if the magnitude of the numerator is greater than the denominator, then simplify the fraction and add/subtract from the whole number accordingly if (Math.abs(finalNum) >= finalDenom) { finalWhole += finalNum / finalDenom; finalNum -= (finalNum / finalDenom)*(finalDenom); } //if the whole number and the numerator or denominator are negative, then remove the negative sign from the numerator or denominator for displaying purposes if (finalWhole < 0 && finalNum < 0) { finalNum = -finalNum; } if (finalWhole < 0 && finalDenom < 0) { finalDenom = -finalDenom; } //simplified ways of displaying the final answer depending on conditions if (finalNum == 0) { return Integer.toString(finalWhole); } else if (finalWhole == 0) { return finalNum + "/" + finalDenom; } else { return finalWhole + "_" + finalNum + "/" + finalDenom; } } 

    What's really confusing me is that I don't know why the mentioned expression does not evaluate properly. I don't know how it differs from the expressions that do work; the more that I look at the ones that do work, the more I think that they shouldn't be working, but they are. What's the logical error in my program?

    Please let me know if any clarification is needed in my code, and also any tips for making this neater/more efficient is also appreciated.

    submitted by /u/elisenne
    [link] [comments]

    What is the best way to present specs for a custom application to a developer?

    Posted: 01 Nov 2018 06:06 AM PDT

    I run a small company. We are at the point that we need to have some custom software written to manage our office and shop floor. I have no experience with software development, but I know what I need the application to do.

    I had some chats with a few developers, trying to find someone that I feel confident that can a good match to deliver what I want. I feel like it has been difficult getting them to understand what I am looking for. I am thinking better communication from my side will probably help.

    What is the preferred way of communicating specs for a project? Do I write them up point by point? Use examples from our current software marked up with changes? Sketch something out on a napkin? Is there any sort of standard or is it individual to the developer?

    submitted by /u/unmotivatedbacklight
    [link] [comments]

    Recommendations for getting help with an MVP.

    Posted: 01 Nov 2018 06:21 PM PDT

    Is something like codementor a good place to get help with a small project mvp?

    submitted by /u/forrealbrahhhh
    [link] [comments]

    In bloom filter, is it possible for 2 different hash functions to hash to same value for same input ?

    Posted: 01 Nov 2018 05:24 PM PDT

    In data structure like bloom filter, we rely on multiple hashes to pickup places to put the input object. Is it possible that two different hashes resolve to exact same value ? If so, how it is solved (apart from having separate bitfield for each hash)?

    submitted by /u/desi_ninja
    [link] [comments]

    How do I know if one of the malloc() family of functions was used to allocate memory?

    Posted: 01 Nov 2018 01:09 PM PDT

    Given following simplified code:

    const unsigned int numCoordsToDuplicate = 5; const float distanceBetweenDuplicates = 5.0f; SomeLibrary->getCoords(COORD_TYPE, ( void ** )&pCoords, &numCoords ); //pCoords is an array of length numCoords //I want to duplicate numCoods, numCoordsToDuplicate times. Coords *duplicates = duplicateCords( numCoordsToDuplicate, distanceBetweenDuplicates ); //Simplification. Pretend it works. if ( pCoords ) //pCoords is not just non-zero but definitely a valid pointer. { //Next line crashes.. pCoords = ( Coords* )realloc( pCoords, numCoords * numCoordsToDuplicate + numCoords) * sizeof(*pCoords) ); } else { //Next line is never called because pCoords is never null perror("Error!!"); } 

    From what I can tell, this should work. pCoords is non-zero (not null) and valid. This should either work, or return 0 and set errno.

    The only reason I could find that this could happen is from this Stack Overflow answer:
    https://stackoverflow.com/a/15915172

    Using calloc() or new[] seems to be working.

    So, back to the question in the title. Is there any reliable way to know whether I can or cannot use realloc()?

    Also, before someone asks:
    Yes, we are mixing C/C++ here, yes it's frowned upon outside of my workplace. No, it's not up to me. Our codebase is super old with a lot of legacy stuff. I just want to focus on question.

    submitted by /u/PageFault
    [link] [comments]

    Job interview sent me home with small assignment. Design a system that updates account balances in a Billing DB based on info in a different DB for a customer support call center. Could someone help me with this?

    Posted: 01 Nov 2018 04:32 PM PDT

    There are two existing databases: 1 Billing database and 1 call center database. If a customer has not used the company's customer support call center in the last 365 days, they will receive a $5 credit on their account balance. I am to use a microservice architecture with restAPI. All I need to do is design the system and present this to them in slideshow format. I have already made a little progress, but now I think I'm stuck on how to move forward with the classes that I've made. Eventually I want to end up with a semi high-level system diagram. Here is a link to some google slides that show where I'm at with the design: https://docs.google.com/presentation/d/1BghC4v_3XGc2Nt0gUf9YRiGgY-2rOGoHK1XHbqYRuV4/edit?usp=sharing

    My problem is that I think I may have negated the need for microservice architecture when I created those classes at the end? I'm sure not sure how to incorporate the microservice architecture along with the restAPI into the design as I've never worked with these concepts before. Any help at all would be greatly appreciated!

    I should note that this is for an entry level position, so they aren't expecting perfection.

    Update (I moved this from a comment so that it will be more visible): Thanks to all of your replies so far, I really appreciate all of the feedback!

    To respond to the people saying this is too much to ask for an entry level position - I didn't do too well in the technical interview because it was in Java and my Java skills are rusty to say the least - but I'm pretty good with Python in a machine learning / data science aspect so they're confident that I can pick up Java pretty quickly. After my interview the three interviewers basically said they don't think I'm capable of being an asset from day 1, but that they still want to hire me - so they gave me this system design project to take home. I'm sure they just want to see my thought process and how I approach it. They also said that using microservice and restAPI are a bonus, but I'm trying to treat them as a system requirement.

    To anyone that says this is cheating - I completely disagree. I haven't once asked for code or even for anyone to do this for me. The task does not even require code - it's a system design to be presented in slide show format, nothing more. I'm asking for tips and guidance here - no different than using resources like finding relevant questions asked by other people that have been answered by other people.

    submitted by /u/nnnnnnnnnnnmm
    [link] [comments]

    Can someone help me understand database API calls?

    Posted: 01 Nov 2018 08:57 AM PDT

    I am self-learning how to interact with a Cornerstone database API and I understand that it is basically a way to sending URL's to the server and receiving data in response.

    What I don't understand is how the commands like GET, POST etc. and the headers are included in the call, as well as "headers".

    Can someone help me find a good resource for learning about all this?

    submitted by /u/graciousgroob
    [link] [comments]

    [Career] How to list skills in a resume ?

    Posted: 01 Nov 2018 04:03 PM PDT

    I have mostly experience (as an autodidact) in C++ and C#, but I have also used other languages and technologies. For example, I've been doing web development, even without concrete projects, I've used Symfony, I'm currently learning Vue.js... I understand how they work, even if I might struggle on

    I'd like a way to specify that I have basic knowledge of all these, even if I'm not mastering them, and let people know that I can adapt. But I have no idea how.

    submitted by /u/Azreina
    [link] [comments]

    PHP I'm hating you

    Posted: 01 Nov 2018 12:13 PM PDT

    My PHP code

    I can't post directly my php code because of formatting problem. There's my code .

    My Problem

    When executed the script doesn't enter into the correct IF branch. I don't understand why at lines: 82, 96, 117, 131, 162 the IF condition is false.

    Request

    Can someone help me? Please it's urgent.

    submitted by /u/DrakeAusir
    [link] [comments]

    Does API version 1 and version 2 has different latency?

    Posted: 01 Nov 2018 06:34 PM PDT

    I doing a arbitrage bot on one of the exchange. They offer version 1 and version 2 API. If I send order using version 1 and version 2, will it has different latency?

    submitted by /u/learningswimming
    [link] [comments]

    Can someone help me with locating and implementing a database on a responsive website?

    Posted: 01 Nov 2018 02:27 PM PDT

    I am using Visual Studio code and creating a responsive website that is supposed to take the input of an address and output the zip code of the address. I'm currently using Angular 6 CSS and do not know how to link a SQL Query database to the website. I also do not have the database at the moment due to not knowing exactly where or what database to retrieve. Please help. I'm currently a student taking an intro to Programming course. This is not an assignment, but in anticipation of a final project.

    submitted by /u/Alan9612
    [link] [comments]

    Webhook help

    Posted: 01 Nov 2018 01:45 PM PDT

    I'm trying to create a webhook for my Discord server that sends a message when there is an update on a Trello board. I know next to no code in any coding language. Any help at all would be really great.

    submitted by /u/NightmarePhoenix2017
    [link] [comments]

    How to quickly set up and configure MyEclipse?

    Posted: 01 Nov 2018 12:47 PM PDT

    How do you guys quickly stand up and configure your IDEs? Our goal is to have development environments we can easily stand up and tear down. Currently looking at all options and curious how other people do it. Thank you!

    submitted by /u/Ohdomino
    [link] [comments]

    [Java] I need to convert the umlauts in a string, without using numbers other than 1, 2 and 3 or any characters that aren't in the ASCII in my source code. But I don't know how to get the int codes for the umlauts that way. Please help.

    Posted: 01 Nov 2018 09:00 AM PDT

    Disclaimer: I'm a noob.

    What is says in the title.

    As far as I can tell, in order to determine whether or not a char is a umlaut, I need to compare it to to all umlauts. But I don't know how to get an umlaut to compare a char to given the restrictions I mention in the title.

    I'm doing this for lower and uppercase umlauts, and when the char after the umlaut is capitalized, I need to capitalize the whole replacement. As in: Äd = Aed and ÄD AED and so forth.

    I can get it to work, but not with those restrictions. If someone could spare a minute to look over this I'd be most grateful. Thank you very much.

    This is my code, which is apparently also too long and complicated, but I don't know how to solve this differently:

    public class FlattenUmlauts { public static void main(String... args) { // variables final String stringWithUmlauts = args[0]; String modifiedString = ""; int currentCharacter; char nextCharacter; boolean nextCharacterCapitalized = false; // lowercase umlauts final int uniCodeNumberOfAe = 228; final int uniCodeNumberOfOe = 246; final int uniCodeNumberOfUe = 252; final int uniCodeNumberOfSs = 223; // uppercase umlauts final int uniCodeNumberOfAE = 196; final int uniCodeNumberOfOE = 214; final int uniCodeNumberOfUE = 220; final int uniCodeNumberOfBigSS = 7838; // computing for(int letterCounter = 0; letterCounter < stringWithUmlauts.length(); letterCounter++){ currentCharacter = (int) stringWithUmlauts.charAt(letterCounter); // check if the next character is capitalized if(letterCounter < stringWithUmlauts.length() - 1){ nextCharacter = stringWithUmlauts.charAt(letterCounter + 1); nextCharacterCapitalized = nextCharacter == Character.toUpperCase(nextCharacter); } else{ nextCharacter = 'a'; //if not then pass any lowercase character } switch (currentCharacter) { // check for lowercase umlauts case uniCodeNumberOfAe: modifiedString += "ae"; break; case uniCodeNumberOfOe: modifiedString += "oe"; break; case uniCodeNumberOfUe: modifiedString += "ue"; break; case uniCodeNumberOfSs: modifiedString += "ss"; break; // check for uppercase umlauts case uniCodeNumberOfAE: modifiedString += nextCharacterCapitalized ? "AE" : "Ae"; break; case uniCodeNumberOfUE: modifiedString += nextCharacterCapitalized ? "UE" : "Ue"; break; case uniCodeNumberOfOE: modifiedString += nextCharacterCapitalized ? "OE" : "Oe"; break; case uniCodeNumberOfBigSS: modifiedString += nextCharacterCapitalized ? "SS" : "Ss"; break; // add char to the modified string when it's not an umlaut default: modifiedString += stringWithUmlauts.charAt(letterCounter); break; } } // output System.out.println(modifiedString); } 

    }

    submitted by /u/crossbreed55
    [link] [comments]

    javax.net.ssl.SSLException: java.lang.IllegalArgumentException: Empty key

    Posted: 01 Nov 2018 10:59 AM PDT

    I keep getting this error.
    I've added the certificate to the cacerts.jks file in my glassfish4 domain.
    This was working before.
    The only http call I make is to a trusted domain that we control.
    Is there anyway to ignore the cert and just make the call?
    Or how can I fix this?
    I'm really struggling here as I'm not a Java expert and the guys here that are have never used the cacerts file.

    submitted by /u/ThatShitAintPat
    [link] [comments]

    Problem with embedded PDF

    Posted: 01 Nov 2018 10:55 AM PDT

    Hello,

    I'm having an issue with embedding a PDF in my HTML code. The code is as follows.

    <div class="resumepost"> <p>If you are having trouble viewing the PDF, Download Here: <a href="MichaelJohnsonTechResume(1).pdf" download>MichaelJohnsonTechResume(1).pdf</a> </p> <embed src="MichaelJohnsonTechResume(1).pdf" width="900px" height="1200px"/> </div> 

    The result on the page is this

    https://imgur.com/a/fw4Gvpi

    Thank you.

    submitted by /u/SomethingQuiteToxic
    [link] [comments]

    Crutchless way of going through Moore Neighborhood?

    Posted: 01 Nov 2018 06:03 AM PDT

    Recently had to go through some weird python course (ended up not being a course at all, no educational material whatsoever, just couple dozens of boring tasks). One of the tasks involved making a Game of Life, for which Moore Neighborhood is quite important. Naturally, with such boring tasks I just hardcoded 8 checks, but that lead me to a thought - is there even a crutchless way of doing this? I understand with some custom data structure or extra conditionals you can do it, but that would take up as much time and effort as hardcoing eight surrounding cells.

    submitted by /u/Barsik_The_CaT
    [link] [comments]

    Copy all form fields and paste to form fields of a different web page all at once

    Posted: 31 Oct 2018 10:23 PM PDT

    So, I have two different web pages. I can't add or modify any existing codes on the second web page. But the first page is under my control. I will have the exact same form fields as page two in my page one. What I want, copy all form fields from page one and paste on page two all at once. How to accomplish this? Can it be done with any browser extension?

    Thanks in advance.

    submitted by /u/theAlphaActual
    [link] [comments]

    No comments:

    Post a Comment