Learning Java, How to output file "showing evidence of the program's required functionality" - Overclock.net - An Overclocking Community

Forum Jump: 

Learning Java, How to output file "showing evidence of the program's required functionality"

Reply
 
Thread Tools
post #1 of 65 (permalink) Old 11-15-2017, 02:55 PM - Thread Starter
New to Overclock.net
 
TheReciever's Avatar
 
Join Date: Nov 2009
Posts: 11,316
Rep: 434 (Unique: 322)
Hey guys!

I am in my final course of my BSIT which is essentially a Java course.

EDIT: For ALL those that have helped me thus far, love you guys! I look forward to your continued guidance cheers.gif

I will edit what ever questions I have here in the OP so its more convenient for everyone. I dont think it would be fair to keep opening new threads when its all Java related. With that said lets begin!

START!
The latest problem I just ran into. Its a new section and am running into the error

"Error: Could not find or load main class accepting.user.input.AcceptingUserInput"

Here is the screen shot



I think I am just getting ahead of myself potential, but in the book it did state to try it out without line 16 or 17 to produce an error and why those lines are needed so with that in mind I am assuming this should prove a successful output.


Anyone got any ideas?

Thanks!

EDIT: Also, if you guys think its ok, I can make separate threads or just leave the OP alone and update new problems with new posts. I wanted to make things a little more convenient for you guys helping me out but I realize that could also rob others to learn from my mistakes.

12/16/2017 EDIT: updated with new questions!

Biased rPGA and MXM 3.0A/B Elitest.
TheReciever is offline  
Sponsored Links
Advertisement
 
post #2 of 65 (permalink) Old 11-15-2017, 04:43 PM
Software 'Engineer'
 
jakethesnake438's Avatar
 
Join Date: Oct 2008
Location: Noo Zolond
Posts: 871
Rep: 53 (Unique: 48)
Your code is sound
How are you checking the contents of the array?

You cannot simply System.out.print(splitNames); as it is an array

Is this still broken?
Xeon machine
(13 items)
CPU
Xeon E5-2667V2
Motherboard
HP Z620 2012
GPU
Sapphire RX 580 4GB
RAM
32GB 1333MHZ
Hard Drive
2x 256GB SATA SSD
Operating System
Windows 10
Operating System
MacOS Mojave
Monitor
Dell P2418D 1440p
Monitor
Dell U2414H 1080p
Keyboard
Apple Kbd
Mouse
Steelseries QCK
Mouse
Logitech G602
Audio
Senheiser HD449
▲ hide details ▲
jakethesnake438 is offline  
post #3 of 65 (permalink) Old 11-15-2017, 05:04 PM - Thread Starter
New to Overclock.net
 
TheReciever's Avatar
 
Join Date: Nov 2009
Posts: 11,316
Rep: 434 (Unique: 322)
Ah I forgot to mention why im confused

" The result of the code above is the following array:
{"Peter", "John", "Andy", "David"} "

I assumed that this meant I should get that string in the output but I should've read it as it will result in the array being formed?

Would there be a way for me to confirm it? I guess I lack understanding of that method used.

Arrays are in the next section so maybe Im just jumping ahead of myself here smile.gif

Biased rPGA and MXM 3.0A/B Elitest.
TheReciever is offline  
Sponsored Links
Advertisement
 
post #4 of 65 (permalink) Old 11-15-2017, 05:14 PM
Software 'Engineer'
 
jakethesnake438's Avatar
 
Join Date: Oct 2008
Location: Noo Zolond
Posts: 871
Rep: 53 (Unique: 48)
Yeah you are getting ahead of yourself.
Go ahead and learn how to construct and loop over arrays. Then come back to it, you will learn how to read the array.
It will make sense.

Good luck, happy coding

Is this still broken?
Xeon machine
(13 items)
CPU
Xeon E5-2667V2
Motherboard
HP Z620 2012
GPU
Sapphire RX 580 4GB
RAM
32GB 1333MHZ
Hard Drive
2x 256GB SATA SSD
Operating System
Windows 10
Operating System
MacOS Mojave
Monitor
Dell P2418D 1440p
Monitor
Dell U2414H 1080p
Keyboard
Apple Kbd
Mouse
Steelseries QCK
Mouse
Logitech G602
Audio
Senheiser HD449
▲ hide details ▲
jakethesnake438 is offline  
post #5 of 65 (permalink) Old 11-15-2017, 05:15 PM
New001
 
Join Date: Feb 2016
Posts: 2,668
Quote:
Originally Posted by jakethesnake438 View Post

Yeah you are getting ahead of yourself.
Go ahead and learn how to construct and loop over arrays. Then come back to it, you will learn how to read the array.
It will make sense.

Good luck, happy coding
Getting ahead of yourself is the best thing you can be doing! Don't let the course hold you back if you are ready for more.

You just want to see the resultant array values?
Code:
        String names = "Peter, John, Andy, David";
        String[] split = names.split(", ");
        
        System.out.println("\nOUTPUT #1:");

        for ( int i = 0; i < split.length; i++ ) {
            System.out.println(split[i]);
        }
        System.out.println("\nOUTPUT #2:");

        for ( String part : split ) {
            System.out.println(part);
        }

or maybe you are using Java8 and you want to use functional operations, so maybe you could pass your String[] to a Collection of some sort, like a List (implementation of Collection).

Using a Generic List::
Code:
        System.out.println("\nOUTPUT #3:");

        List<String> list = Arrays.asList(split);
        list.forEach( value -> {
            System.out.println(value);
        });

Using a Concrete List (ArrayList in this case)::
Code:
        System.out.println("\nOUTPUT #4:");
        List<String> list2 = new ArrayList(Arrays.asList(split));
        list2.forEach( value -> {
            System.out.println(value);
        });

OUTPUT 1,2,3 & 4 will all be the same


edit:
also if you want to rebuild the string you could use something like StringBuilder.
Code:
        StringBuilder sb = new StringBuilder();
        for ( String part : split ) {
                sb.append(part);
                sb.append(", ");
        }
        System.out.println(sb.toString());
spinFX is offline  
post #6 of 65 (permalink) Old 11-15-2017, 05:35 PM
Software 'Engineer'
 
jakethesnake438's Avatar
 
Join Date: Oct 2008
Location: Noo Zolond
Posts: 871
Rep: 53 (Unique: 48)
Quote:
Originally Posted by spinFX View Post

Getting ahead of yourself is the best thing you can be doing! Don't let the course hold you back if you are ready for more.

Let him learn himself man. Very easy to cut and paste code and learn nothing

Is this still broken?
Xeon machine
(13 items)
CPU
Xeon E5-2667V2
Motherboard
HP Z620 2012
GPU
Sapphire RX 580 4GB
RAM
32GB 1333MHZ
Hard Drive
2x 256GB SATA SSD
Operating System
Windows 10
Operating System
MacOS Mojave
Monitor
Dell P2418D 1440p
Monitor
Dell U2414H 1080p
Keyboard
Apple Kbd
Mouse
Steelseries QCK
Mouse
Logitech G602
Audio
Senheiser HD449
▲ hide details ▲
jakethesnake438 is offline  
post #7 of 65 (permalink) Old 11-15-2017, 05:35 PM - Thread Starter
New to Overclock.net
 
TheReciever's Avatar
 
Join Date: Nov 2009
Posts: 11,316
Rep: 434 (Unique: 322)
Quote:
Originally Posted by jakethesnake438 View Post

Yeah you are getting ahead of yourself.
Go ahead and learn how to construct and loop over arrays. Then come back to it, you will learn how to read the array.
It will make sense.

Good luck, happy coding

Ok thanks! I'd rather be dumb founded because I am expecting something I shouldnt than the opposite lol

Quote:
Originally Posted by spinFX View Post

Getting ahead of yourself is the best thing you can be doing! Don't let the course hold you back if you are ready for more.

-snip-

Oh I remember this from code academy I did a while back smile.gif
Quote:
Originally Posted by jakethesnake438 View Post

Let him learn himself man. Very easy to cut and paste code and learn nothing

This is true, its why I am forcing myself to use the comments for each line. If I cant put it in my own words, then I dont know what I am doing with the method.

Biased rPGA and MXM 3.0A/B Elitest.
TheReciever is offline  
post #8 of 65 (permalink) Old 11-15-2017, 05:59 PM
New001
 
Join Date: Feb 2016
Posts: 2,668
Quote:
Originally Posted by jakethesnake438 View Post

Let him learn himself man. Very easy to cut and paste code and learn nothing

I'm not stopping him from learning himself, man. I thoroughly disagree with you on the second statement in this context also, given that I pasted 4 different pieces of code to pull of the same thing, it would be hard NOT to learn something from copying and pasting that code and looking at the output.
Quote:
Originally Posted by TheReciever View Post

Oh I remember this from code academy I did a while back smile.gif
Huh? smile.gif Not sure what you mean, never used code academy
Quote:
This is true, its why I am forcing myself to use the comments for each line. If I cant put it in my own words, then I dont know what I am doing with the method.

Yeah well what I have there is 4 ways to output the exact same thing,
starting with a print of "OUTPUT #X" so it's easy to see the separate outputs
Just copy and paste that code and look at the outputs and you should be able to see whats going on.
ie.
Quote:
OUTPUT #1:
Peter
John
Andy
David

OUTPUT #2:
Peter
John
Andy
David

OUTPUT #3:
Peter
John
Andy
David

OUTPUT #4:
Peter
John
Andy
David

Code:
        String names = "Peter, John, Andy, David";  // create a string with comma delimiters
        String[] split = names.split(", ");  // split the string with split method in the String class
        // result: split[0] = "Peter"
        //            split[1] = "John"
        //            split[2] = "Andy"
        //            split[3] = "David"
        // (4 Items)

        System.out.println("\nOUTPUT #1:"); // print to console *new line* & "OUTPUT #1"

        for ( int i = 0; i < split.length; i++ ) { // start of loop from 0 to 3
            String name = split[i];  // get name String from String Array at position i
            System.out.println(name);  // print name String to console
        } // end of loop
spinFX is offline  
post #9 of 65 (permalink) Old 11-15-2017, 06:22 PM - Thread Starter
New to Overclock.net
 
TheReciever's Avatar
 
Join Date: Nov 2009
Posts: 11,316
Rep: 434 (Unique: 322)
Quote:
Originally Posted by spinFX View Post

I'm not stopping him from learning himself, man. I thoroughly disagree with you on the second statement in this context also, given that I pasted 4 different pieces of code to pull of the same thing, it would be hard NOT to learn something from copying and pasting that code and looking at the output.
Huh? smile.gif Not sure what you mean, never used code academy
Yeah well what I have there is 4 ways to output the exact same thing,
starting with a print of "OUTPUT #X" so it's easy to see the separate outputs
Just copy and paste that code and look at the outputs and you should be able to see whats going on.
ie.
Code:
        String names = "Peter, John, Andy, David";  // create a string with comma delimiters
        String[] split = names.split(", ");  // split the string with split method in the String class
        // result: split[0] = "Peter"
        //            split[1] = "John"
        //            split[2] = "Andy"
        //            split[3] = "David"
        // (4 Items)

        System.out.println("\nOUTPUT #1:"); // print to console *new line* & "OUTPUT #1"

        for ( int i = 0; i < split.length; i++ ) { // start of loop from 0 to 3
            String name = split[i];  // get name String from String Array at position i
            System.out.println(name);  // print name String to console
        } // end of loop

Its all good man, I have seen others copy/paste code until they get to the project at the end of the course and then flunk their degree because they couldnt finish the course on time since they didnt actually learn what each function does.

Not that doing it legit 1 time will make you learn it, in its entirety either but its typically a better route to take from a merit stance.

Code academy is a free kind of guided tutorial, its not bad, not the greatest either but lets you walk through most of the basic functions.

Thanks for sharing, I have Arrays in the next section but took a break from it, ill be experimenting with your examples in the morning though!

Thanks everyone, reminds me of why I liked OCN, truly exceptional <3

Biased rPGA and MXM 3.0A/B Elitest.
TheReciever is offline  
post #10 of 65 (permalink) Old 11-16-2017, 06:53 AM - Thread Starter
New to Overclock.net
 
TheReciever's Avatar
 
Join Date: Nov 2009
Posts: 11,316
Rep: 434 (Unique: 322)
Hey Guys!

I am back with another question, I didnt think it would be suitable to create another thread so I'll just ask again here smile.gif

So as you know I was jumping ahead of myself a bit, and the book didnt even use the same attributes for the split() method instead choosing to show int[]. Ill paste a snippet of what I am working with now.




The question I have for you guys is this.

For
Code:
int[] userAge3 = new int[5];

When I
Code:
System.out.println(userAge3[0]);

I get the output of 0. I dont think its incorrect but can someone explain to me why its 0 instead of 5?

Thanks!

EDIT:

One more question!



Can someone tell me why dest[0] outputs 16?

I know its in the source but why isnt 12 the starting point?

Biased rPGA and MXM 3.0A/B Elitest.
TheReciever is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off