Ask your own question, for FREE!
Computer Science 7 Online
xjezzer:

Summative: Java Joe's Week Assignment In this assignment you will use the following concepts from this unit, "The Basics". Looping Conditional Branching Operators Variables System Output

xjezzer:

Introduction to Java Joe's Week Assignment click to see rubricSummative: Java Joe's Week Assignment In this assignment you will use the following concepts from this unit, "The Basics". Looping Conditional Branching Operators Variables System Output Assignment Background Java Joe has a busy week ahead of him. He would like you to write a program to help keep track of what he is up to! Your job is to write a program that will loop through the 7 days of the week, each time you go through the loop you should count that as moving on to the next day. For each day use conditional branching to complete the goal outlined beside the days below. You will also have to declare and use a double variable called ' Money' to keep track of how much money Joe has, at the end of the week Joe will want to know how much money he has!

xjezzer:

Joe starts his week off with $200. He also starts his week on Monday! These are the goals you much complete for each day: Monday Joe decides he will go buy some shoes to help him walk about this week, he finds a pair for $30, not including tax, calculate the total amount of the shoes Joe will pay using the formula TotalCost = Cost * 1.15; Output to the screen what day it is, how much Joe paid for the shoes and how much money he has left.

xjezzer:

Joe goes wants to paint his ceiling; he measures the length out to be 12m and the width to be 7m. Calculate the area of his ceiling for him and output to the screen what day it is and the area of Joe' s ceiling.

xjezzer:

Joe goes to the Hardware store to buy some paint. If the paint costs $1.13 per square meter, calculate how much Joe needs pay for his paint using Tuesday's measurements and then output to the screen the cost of the paint and how much money Joe has left.

xjezzer:

Joe has been driving around a lot this week; he needs to fill his gas tank. If it costs Joe $36.40 (remember to take this off of Joe's total money) and gas was 45cents a liter, Output to the screen what day it is, how many liters of gas Joe got and how much money Joe has left.

xjezzer:

Saturday Joe donated $23 to charity, Output to the screen what day it is, and Joe's current money

xjezzer:

Sunday Output to the screen what day it is

xjezzer:

The order is Monday, Tuesday, Wednesday, Thursday, Saturday, and Sunday

Vocaloid:

This is a volunteer site. Please do not offer money in exchange for hw help. That being said @SmokeyBrown would you mind taking a look at this

SmokeyBrown:

For this assignment, since you're incrementing through a known set of days, I think a for-loop would be most appropriate. Before we get into that, there are a few variables we'd probably want to set up. The important values you'll need to keep track of throughout the program are the Current Day and the Money Remaining. Before setting up the for-loop, make sure to define these. Based on the problem, the Money should be a double variable, with a starting value of 200.00. The Current Day could be an integer, starting at 1 (for Monday). For the Days, since you will have to display the name of the day later on, you could also set up an Array of Strings containing [Monday, Tuesday, Wednesday, ..., Sunday]. This way, we can use the index of the array to call the Strings for printing later. While it doesn't matter for the structure of the program, I'm curious to know what programming language you're using? I guess "Java Joe" is probably a cheeky nod towards the Java language. If so, that's good since I'm pretty familiar with Java, and that will come in handy once we get to actually writing the code

SmokeyBrown:

Anyway, once you have your variables initialized, we can start thinking about the structure of your loop. Since we're incrementing through the 7 days of the week, it makes sense to set up a for-loop with an initial value of 1 and increment that value by 1 for each pass-through, ending the loop once the value is greater than 7. In Java, it would look something like: for (int i = 1; i <= 7; i++) { } The first part, "int i = 1" initializes the variable which will be our "counter". The second part "i <= 7" defines the condition by which the loop keeps on looping. The third part "i++" defines how the counter will be changed with each loop; in this case, it increments by 1 each time. I'll note that if you decided to use an Array of Strings for the names of the days of the week, it might make more sense to do something like for (int i = 0; i < 7; i++) { } since that will make it easier to access the Array by index (Java arrays start at index 0, not 1) But I feel like I'm getting ahead of myself in any case. We should start by focusing on the structure of your program, and we can get into the details of coding it out later.

SmokeyBrown:

Now, this program is interesting because you're not actually doing the same thing on each day of the week. In fact, on each day it seems like Joe is doing a completely different task which may or may not end up changing the amount of money he has. In order to represent these different tasks, we'll use the "Conditional Branching" described in the problem. This will consist of: First, a check to see what day of the week it is; Second, a block of code describing what to do, based on what day it is; In general, you can accomplish this either through a series of "if-else" statements or through a single "check" statement. We can get into the details of that later. In any case, your program will check the day of the week (likely using the Counter variable we used when setting up the for-loop, which I called "i" in my above example) and then choose the appropriate behavior based on what day it is.

SmokeyBrown:

Now for the meaty part of the program: all the different behaviors for each of the 7 days. We can go through them one by one, if it pleases you. On Monday, Joe pays for a pair of shoes which cost $30, plus a tax of 15%. The question does us the favor of giving us the equation for calculating cost. Since this is a price with decimal values, you could start by set up a double variable to represent the base price of the shoes, initialized at 30.00, as well as a double variable to represent the tax rate, initialized at 1.15. I didn't explain it earlier, but a "double" is a datatype for storing numbers that contain a decimal portion, as opposed to an "integer". A "float" also stores decimal numbers but takes more space to do so. Anyway, you can use these variables to calculate total cost according to the equation TotalCost = Cost * TaxRate Meanwhile, you could have another double variable to store the TotalCost value. Finally, you're required to "Output to the screen what day it is, how much Joe paid for the shoes and how much money he has left", which can be accomplished with a print statement. Of course, you'll need to calculate how much money Joe has left, for which we can use the variable we defined at the beginning to represent Money Remaining. In Java, it is pretty simple to put together String statements, so you can use a combination of Strings and the variables you have in order to construct a print statement that makes sense. Again, we can go into more details about the coding when we come to that.

SmokeyBrown:

For Tuesday, it's a pretty similar affair; make some calculations and output the results. You might make a variable for length, a variable for width, and a variable for area. Initialize length and width with the appropriate values, calculate area, and output your message as specified in the question. Wednesday is actually related to Tuesday, since you'll be using the Area value you calculated. Good thing about that variable, you can just plug it in. You can make a variable for the cost of the paint-per-square-foot if you like, and calculate the total cost of the paint based on that. As before, output the results as specified in the question.

SmokeyBrown:

Oh for Wednesday, we also shouldn't forget to take away the cost of the paint from Joe's Remaining Money, in the same way as on Monday. Thursday is another pretty straightforward one. We are given the cost of the gas directly (which you can also store in a double variable), so we can deduct that from Joe's remaining money. We are also asked to calculate how many liters he bought, based on the price of gas per liter. Using variables to store your results, output a message containing the results, as before.

SmokeyBrown:

Huh, it seems like the question skips from Thursday to Saturday, right over Friday? Interesting. This is fine, if we don't set a check for any special behavior, then "Friday" will be skipped over anyway, I just can't help but wonder whether or not that's a typo. Anyway, Saturday is particularly straightforward. All we have to do is take away 23 dollars from Joe's Remaining Money, and display our results. On Sunday, we don't have to do anything except for display the day of the week.

SmokeyBrown:

So, that's the basic structure of the program. Now we can go into more detail about actually writing the code to perform the tasks described in our plan, if you'd like. Before we start with that, do you have any questions or concerns?

xjezzer:

Thank you very much for everything, Also for Thursday the gas price is actually $80.08 and 99 cents a litre. Also Friday was actually skipped and not a typo. Finally for Monday, the formula is TotalCost = Cost * 1.13; instead of 1.15. I appreciate you so much, and to make sure the programming language is java. Let's get started with the code!

SmokeyBrown:

Alright cool. That's good to know, and it's also the nice thing about having variables to handle all that information. We can easily switch out the value of the variables and the code still runs the same. So, with any Java program, we'll have our main method, in which everything is contained. public static void main (String[] args) { ... } And then inside of that main method, between the brackets is where all of the code for our program will go. Before I go any further, I don't want to bore you with details you already know, and it would take too long to go through the entire program line-by-line (although we could do that, if we needed to). Maybe it would be helpful if you could give me some idea of what you do and do not know how to do? For instance, is there any part of the program you are sure you can write on your own or any parts that stand out as particularly confusing to you?

xjezzer:

The things I only know how to do are the easy things like naming variables which are already given to us so it won't make a difference if I were to do anything, I'm very new to programming and have been having a hard time. It's just easier for me to understand when I have the answer and I can go through it line by line.

SmokeyBrown:

Ok, maybe we can use the repl.it site to code it out interactively. I'll set up a page there so we can both see the code and work on it as we go, and I'll post the link here as well

SmokeyBrown:

https://replit.com/join/egiqsmiocn-hgu999 Please try this, I have some of the variables set up and the initial for-loop as well so far. I can also show you how the "conditional branching" might look. Beyond that, I'd like to see what you can do, and I'll be here for support if needed

xjezzer:

yes for the code I am supposed to be using conditional branching

xjezzer:

To be honest I am very lost and like I said before I really only learn from the answers (only things I'm new to) otherwise after that I work on other problems myself based on the answer provided for the previous problem

SmokeyBrown:

I've written out the comments showing the template for a conditional branching block, both in the form of a series of if-else statements and as a switch statement (I mistakenly called it a check statement earlier, my apologies) Both of these could be valid. Which would you like to go with?

SmokeyBrown:

Better yet, you can try to edit the code for yourself in the repl. Choose which strategy you'd like to use, and you can even try filling in the body of the code based on the behaviors for each day of the week. Would you like to give it a try? I can give you editing permission, if you don't have them already

xjezzer:

yeah the strategy I'd like to use is conditional branching and ill try it out

xjezzer:

I have somewhat of an idea what you are doing, some sense is coming to me just based off the comments. I feel like seeing the finished product with the code using all the looping, conditional branching, operators and variables will really make sense to me when it is finished

SmokeyBrown:

I'll just go ahead and use the if-else statements to show more of the structure of the code. I'll even finish writing the behavior for the Monday block for you. After that, I trust you'll be more comfortable trying the other days yourself?

xjezzer:

I don't really know how to explain it but I know like the knowledge and what to do and how to do it, it's just I have difficulty applying the code and writing it down. I'm not sure if that makes sense but in my head I know what to do but when it comes to applying I'm lost

SmokeyBrown:

I understand, knowing how a program should work and actually being able to write the code are two different skills. That is why I think it is even more important that you get some practice with writing code in a safe and easy environment while you have the chance. I went ahead and coded the behavior for Monday and Tuesday, as you can see. Would you like to give Wednesday a try, and then we can continue from there? I'll be here if you have any specific questions, but I'd like to give you the chance to practice as well.

SmokeyBrown:

Sorry, I think you're putting your part in the Thursday section, when it should be in the Wednesday section. Other than that, it's looking good! Keep it up! Would you like to try Thursday next?

xjezzer:

yeah ill go ahead and try thursday

SmokeyBrown:

Just fyi I'm running into a little bug on line 29 (Thursday) where the variable "area" doesn't seem to be recognized. This is might be because "area" is only defined in the Wednesday condition. I'll try some things, including defining "area" outside of that block, to see if it helps. How interesting... As for the code you've written yourself so far, it's looking good! I'll just do a bit of debugging while you continue with that.

xjezzer:

okay thank you so much!

SmokeyBrown:

It was kind of a clumsy fix, I ended up putting the variable definitions somewhere they can be accessed more globally. Well, it seems to work anyway :)

@xjezzer wrote:
okay thank you so much!
You're very welcome! Honestly, this was kind of fun for me too. It looks like you're pretty much all done. You can feel free to finish up those last two statements, clean up any of the comments I made if you'd like, and you should be good to go. Good work, and thanks for your cooperation!

xjezzer:

I appreciate you so much, you've helped me and helped me understand all this. This is all so clear to me now. Thank you so much. I went ahead and finished the code. Can you check to see if its good?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!