
- #Blue pelican java project answers software
- #Blue pelican java project answers code
- #Blue pelican java project answers plus
(This eliminates some complications with the math). public interface LinearFunctionMethods For simplicity we will assume that the linear function's graph can never be vertical or horizontal.
#Blue pelican java project answers code
When your project is complete, she will simply look at your class signature and if she sees implements LinearFunction Methods, she will know for certain that you have implemented all the methods she originally specified in the interface otherwise, your code would not compile. To insure that you produce exactly the methods she wants, she is providing the interface below and requiring that you implement this interface in the LinearFunction class you produce. Not having time to write it herself, she assigns the job to you. Your immediate supervisor has need of a class called LinearFunction and she knows exactly the methods that it needs to include.
#Blue pelican java project answers software
Linear Function You are a software engineer with the Blue Pelican Engineering Corporation. I haven't used a Scanner in a very long time, so if this assumption is incorrect, you'll have to fix that.Transcribed image text: Project. You'll notice I didn't check if the input contains a + sign at the beginning before the loop this is because I'm assuming that even if you enter something like 1 - 5 - 9, the Scanner will still return at least that whole string when sc.next() is called, which will still go into the inner loop, and the expression will still be evaluated. Sum += Integer.parseInt(temp) // there is no - sign, so skip ahead and just add to the sum Sum += diff // adds the result to the sum if there are, evaluate the subtraction expressionĭiff -= sc2.nextInt() // diff = 1345 - 137 = 1208 This is where storing the value in temp comes into play you can use a nested loop to evaluate subtraction portions of your expression! You were on the right track with checking for + and - in the input, and here is a more appropriate spot to use it: // start with + However, this code breaks on the third pass, because "1345 - 137" is clearly not an integer value. first pass, temp = "1345 - 137", code breaks at Integer.parseInt(temp) You would typically use Integer.parseInt() to turn a String to an int, like so: // start with + In the above example, temp would first be "8" (note that it's a String here), then "33" on the next pass, then "1345 - 137" on the third pass. You can still pull this off with one loop, but it will require some intermediate steps. How can you account for mixed operators? int sum = 0 Now, let's look at your sample input: 8 + 33 + 1345 - 137.
#Blue pelican java project answers plus
Since these values don't change (they are constants), and (in a real program) would be used multiple times in different places, we typically store these in their own final variables: final String PLUS = "\\s*\\+\\s*" // by convention, constants in java are named with all caps Since you are only dealing with + and -, your delimiters are "\\s*\\+\\s*" and "\\s*\\-\\s*", respectively. and so on additionally, you're probably not worried about input checking (making sure there are no letters/symbols/etc) or negative numbers, so we'll ignore those scenarios. Since you haven't learned about arrays yet and are working with a Scanner with a delimiter pattern, we'll have to work around this constraint.įirst, for the purposes of a school assignment, we can probably safely assume that your inputs will follow a particular pattern, along the lines of: (number)(operator)(number)(operator)(number). I'm going to help you answer this in a way that's (hopefully) consistent with what you've learned so far. Now we convert the String to a scanner because we will be using Scanner methodsĬan anybody help me solve the problem (First comment in my source code)? Here is my source code: //I can't get it to work if I use subtraction and addition at the same time but they work separately Now modify the program as to allow either plus or minus signs a minus sign surrounded by any amount of white space. Set delimiters to a plus sign surrounded by any amount of white space.or. object otherwise, it can get stuck waiting for input. String s = kb.nextLine( ) //Best to store in a String and then create a new Scanner So my teacher gave me an assignment to do (will be shown below) and I tried to do it but just could not figure it out, here's the assignment:Ĭonsider the following program that allows something like 8 + 33 + 1,345 + 137 to be entered as String input from the keyboard, A Scanner object then uses the plus signs (and any adjoining white space) as delimiters and produces the sum of these numbers (1523).
