Tuesday, April 16, 2024

Java Exercise 4-1 Instructions

 

Classroom computer class - by ChatGPT


Thoughts On and Instructions For Successfully Completing Exercise 4-1


We were assigned a java programming exercise in my Software Design class the other day. I started doing it the other night after a long day of work and studying. I had no 'plan' when I started. I took some code I had created earlier from Chapter 4 and tried to modify it to fit the assignment (Each of the chapters has a "You Do It" section where they instruct you in a step by step fashion to write code that is relevant to the material you just covered in the text. It's not necessary to do the coding, but I do it every time it comes up and save it in a library of code on my laptop). I found it overwhelming and just couldn't get it. I gave up that evening feeling extremely dejected.


I woke up in the morning and decided to tackle it with a set of fresh eyes. My first problem from the night before was that I just went in and tried to 'code' the exercise with no game plan. This is where things started to get better in the morning. I went back and found the relative text in the textbook that delt with what we were being asked to do and wrote a set of directions. Afterward, I refined the directions to make them easy to understand and to make it so someone who is familiar with the class should be able to complete the lesson using them (modified them for brevity and clarity). They are below.


What I would say I learned from this is that going in without a game plan is a potential path to failure. If I was good, or at least better, at coding I could have gotten away with it. But I'm not. Using pseudo code would have probably been best from a coder's perspective. But, I'm not a coder and I work better when I can set things out with explanations and a clear set of stepped instructions. I thought I was familiar enough with the material that I could just 'modify' my previous code and get it to work. I was not.


I did not complete the whole exercise (the last step). I ran out of time to tackle that step. And, to be honest, I was just so happy to get the first part done which put me in a 'B' letter grade range that I was okay with not finishing the last step.


One of my issues with coding (to date) is that I just don't remember the form. I constantly have to look up the correct way to write something. I'm thankful that my ITP100 class has been open book for everything. If I had to do any of the requirements from rote memory I would be in a bad position. The other feature of the class that has been good so far is that only 1 assignment (midterm?) was timed. Without a time limitation I'm free to look up answers to make sure I've got it correct. Also, if any questions we have in quizzes or tests have code questions in them, the lack of a timer on them allows me to put the code in an IDE and check what I think the outcome should be with what it is in reality. That has saved me from an incorrect answer a couple of times.



(Tasks 1-5) (pages 119-124 in Java book)

1. In codespaces it's important to follow the instructions (tasks 1-6) step by step. I normally hit the 'check my grade' button to verify a task was done correctly (it's Cengage so that doesn't always work).

2. Use proper java conventions when writing out your gets and sets (the codespaces doesn’t want to give you credit if you don’t).

3. You know how to write a class

            public class ThisIsAClass

            now create one for the Sandwich class

4. The instructions give us the 3 variables (fields) we’re going to use. After writing your class, you must declare your variables. Part A of the instructions gives you all the information you need to complete this.

 

               double price;

    String mainIngredient;

    String bread;

 

 

5. This last step will  accomplish tasks 3-5. Once you do 1, you just have to repeat it 2 more times, modifying it for each data field. We are basically creating a method for working with each field (I’m trying my best to use the correct vocabulary here; I may be wrong in the terms I’m using but my output for the code is correct.)

 

A method is either public or private. I’m using public because I don’t think I’m creating new objects and I’m not worried about hiding data. We’re going to ‘get’ it first, then ‘set’ it. I’m going to use the words get and set together with my data fields. Remember this order: ‘get’ it, then ‘set’ it. 2 methods for each field. Start like this:

 

public String getMainIngredient() to make it easy to follow, and in what I believe is convention, we’re just adding ‘get’ to mainIngredient using the camel casing format and we’re going to ‘return’ the variable. It should look like this when done:

 

public String getMainIngredient()

    {

        return mainIngredient;

    }

 

After we ‘get’ it, we need to ‘set’ it. So now we create a similar method for setting. We’re going to public void setMainIngredient(String newIngredient).  What we’re doing is taking the input that we got from the prior method and setting it into are mainIngredient variable. It should look like this when done:

 

    public void setMainIngredient(String newIngredient)

    {

        mainIngredient = newIngredient;

    }

 

Just repeat this for each data field (variable) we’re going to use.    If I understand things correctly, the reason we leave the ( ) empty in the get method is because we’re getting or returning user input. In the set method, we’re now assigning the data that we got earlier to a new intermittent variable and back to the data field for use in our application.

 

Task 6 TestSandwich

(workInProgress)


Cameras, cats, and computers? This is what you get when you ask ChatGPT for a picture of a java programming class for a blog post!




No comments:

Post a Comment

LRCC ITE221 Review

  ITE 221 PC Hardware and Operating Systems/ Dr. Leach Review Edited December 10, 2024. This Fall 2024, I enrolled in ITE 221 PC Hardware an...