• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with final  RSS feed

 
Brandon Baldanza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really looking for some help with this final. I can get the if statement to work properly. We did not cover if statements that much.


Week 12 - Final Instructions

1. Create a class called Final.
a. The Final class should contain a main method.
2. Copy the following variable declarations below the main method.
int number1 = 0;
int number2 = 10;
int[] intArray = {2,4,6,8,10,12,14,16,18,20};
Scanner input = new Scanner(System.in);
String myString = "";
String myString2 = "This is an example of using the substring method.";
String myString3 = "When you come to a fork in the road take it.";
String mySubString2 = "";
int beginIndex = 22;
String[] splitArray;
String mySplit = "";

3. Create an if/else statement that compares number1 to number2.
a. If number1 equals number2 print:
i. "number1 is equal to number2"
b. If number1 does not equal number2 print:
i. "number1 is not equal to number2"

4. Using a for statement, print out the contents of intArray.
a. Print the index and the value in that element of the array.
b. See the Example Run for the format of the output.

5. Print out the following substring (include the double quotes) from myString2
a. "using the substring method."
b. See the Example Run for the format of the output.

6. Using the split method, split myString3 into words and store each word in an element of the splitArray.
a. Then printout the splitArray using a for statement.
b. See the Example Run for the format of the output.

7. Ask the user to enter a string by outputting:
a. "Enter a string or enter the word stop to exit: "

8. Accept the user’s input by using the Scanner method nextLine.

9. Use a while loop to continue to:
a. Ask the user to enter a string
b. Accept user input
c. Print out what the user entered
d. until the user enters stop.

10. Print out the following message:

11. "I'm finally finished with the final!!!"

12. Run the Final program.
a. Enter:
i. I like Java!!!
b. Enter:
i. Stop

13. Take a snapshot of your output.

14. Upload your code and snapshot to Canvas.
Final-Example.png
[Thumbnail for Final-Example.png]
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So can you show us your code?
 
Brandon Baldanza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code so far..

 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The conditions of your if-statement don't match the assignment. You also don't need a second if-statement, you can use an else-clause.

Do you know how to use for-loops? If not, have you gone through the Java tutorials?
 
Brandon Baldanza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iv looked through the tutorials and im using the example code he has provided us.. Cant get #4 to work and compare the numbers
 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon Baldanza wrote: Cant get #4 to work and compare the numbers

Don't worry about the 4th yet, you haven't got 3rd part correctly.

1. First thing. Assignment didn't ask you to place code to a named package. 1st line, remove it.
2. Why you got Scanner commented out? If you're getting an error, that means you need to import Scanner class. Search how to do it.

3. Create an if/else statement that compares number1 to number2.
a. If number1 equals number2 print:
i. "number1 is equal to number2"
b. If number1 does not equal number2 print:
i. "number1 is not equal to number2"

Check in your code what have you got?
 
Brandon Baldanza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! I did not input the scanner. Went ahead and skipped number #4 for now here is my code... I think from what he said if you end up with the example code and it looks the same its ok.

 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incorrect. Stop with guesses.

Please show us, which lines of your code satisfy this instructions part?

Instructions wrote:3. Create an if/else statement that compares number1 to number2.
a. If number1 equals number2 print:
i. "number1 is equal to number2"
b. If number1 does not equal number2 print:
i. "number1 is not equal to number2"
 
Brandon Baldanza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None of the lines satisfy that...

if (number1 >= number2){
number1 = number2;
} else if (number1 <= number2)
System.out.println("number1 is not equal to number2");
 
Brandon Baldanza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone else available to help with the last part? I have like 30mins left till its due...

Capture.PNG
[Thumbnail for Capture.PNG]
 
Liutauras Vilda
Sheriff
Posts: 4923
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say try to slow down with writing code. You need to make sure, what you write is correct. At least to try that.

Your instruction says:

Instructions wrote:Create an if/else statement that compares number1 to number2.
If number1 equals number2 print:
"number1 is equal to number2"
If number1 does not equal number2 print:
"number1 is not equal to number2"

Brandon Baldanza wrote:

Read out loud, what instructions bolded part says, and what your code does?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!