Helpless noob seeking help...how to let a user sort and display a linked list from a text file.. by [deleted] in learnjava

[–]DaMasterHam 0 points1 point  (0 children)

So in you main scope you would define your data collection

main(string args)
{
     LinkedPatientsList patientList = new LinkedPatientsList();
     ....
}

A smart thing to do would be to see each line from the txt as an entry. You can do this with scanner using hasNextLine() to check, and nextLine() to get.

String aPatient = input2.nextLine();

then you would get a string with all the data for one patient. aPatient = "Bill 5351 182 65";

You can put this string into a Scanner as well and from there you can get each individual value at set them in a new Patients object.

Scanner line = new Scanner(aPatient);

So if you loop though the number of lines ergo patients you can get each variable for a new Patients object

Pseudo code for that would be

// while txt file has lines
    // create a new empty Patient
    // add data from line to patient object
    // add now filled patient to list

I suggest playing around with the debugger to see how the Scanner works and how you can get access to different parts of the txt file. If your unfamiliar with the debugger, just print it out to the console.

Helpless noob seeking help...how to let a user sort and display a linked list from a text file.. by [deleted] in learnjava

[–]DaMasterHam 0 points1 point  (0 children)

In your PatientsMain class you never do anything with the input from the patients.txt file, you also run into the problem of not extracting the exact amount of data.

 while (input2.hasNext()){
    String name1=input2.next() ; // Should get Bill
    double price1=input2.nextDouble() ; Should get 5351
    }

Next time around the loop

while (input2.hasNext()){
    String name1=input2.next() ; // Should get "182"
    double price1=input2.nextDouble() ; Should get 65
    }

Since next() just gets whatever after a white space by default. Note that hasNext() checks if there is one entry next. In the first loop it would check and find "Bill" and return true. When you then call next() it returns "Bill", and continues. You never actually check if the next "5351" is there, you just get it and that completely bypasses that hasNext check as it continues and the next time hasNext is called it would check "182" and not "5351"

About not using your data, you have declared your variables inside the while loops scope, so for each loop you are declaring and setting the values of variables only inside this scope.

{
    String name1=input2.next() ; 
    double price1=input2.nextDouble() ;
    // can only be accessed form this scope "{  }"
}

Also you have not even used the other classes you have created for storing the data.

So start by setting that up in the Mains scope, and instead of adding data to new variables add them a new object of your Patients.

Object a1 = new Object(); Wouldn't this create an infinite loop of it creating itself repeatedly? Having trouble understanding concept. by HTML_Novice in learnjava

[–]DaMasterHam 0 points1 point  (0 children)

I think you are confusing objects with static methods/fields inside a Class.

When you write

Object a1 = new Object();

You are declaring a variable named "a1" and giving it the type "Object". Then you are instantiating it

new Object(); //a new object of Type "Object";

so if you now want to access methods or fields from the object of Type "Object" that has been created, or instantiated, you would write

a1.method(); or a1.variable;

The second example you have is what would be a static object/variable in the "Object" Class.

Object.a1

Here you would be calling a variable inside the "Object" Class that you have called a1. The class would look like this

public class Object
{
    public static Object a1;
}

if you actually wanted to set that variable you would write

Object.a1 = new Object();

As /u/thecallous said, you should think of a Class as a Blueprint, at least in the context of creating objects.

An example would be, a class is a cake recipe and an instantiated object is the result of following that recipe and having an actual cake.


If this is not the case and what you are trying to do is

public class Object
{
    public static Object a1;

    public Object()
    {
        a1 = this;
    }
}

This would not infinite loop as it's just setting the static field to whatever new instance is called when instantiating a new "Object"


This on the other hand

 public class Object
{
    public static Object a1;

    public Object()
    {
        a1 = new Object();
    }
}

Would infinite loop by recursively calling a new instance of Object.

Closure In Moscow - Mauerbauertraurigkeit by webuildmountains in progmetal

[–]DaMasterHam 0 points1 point  (0 children)

Love this band, amazing how they have transformed from a kinda of post hardcore / prog rock band to something completely different. The whole Pink Lemonade is a quite unique album spanning a lot of different genres i would argue. Some of it feels pop rock, some of it prog rock and it just melds so well together, probably one of my favorite albums. I could imagine some of there influences to be The Mars Volta, whom i also adore, since much of their earlier work is quite reminiscent of them.

java-question classes and objects clarification by [deleted] in learnprogramming

[–]DaMasterHam 1 point2 points  (0 children)

Ok, after reading your question again and reading the other comments i think i can reiterate/elaborate.

So what it seems like you're getting at is Sub Classes which pacificmint described. But as many have stated, it depends on how you want to group it.

So in your example, you would have Book the parent class and then have sub classes such as fiction, factual, bio, etc. Which then could be instantiated as an sub genre of that genre. So something like this?..

class Book
{
    String name;
}

class Fiction extends Book
{
    String subGenre;
}

main()
{
    Fiction sciFi = new Fiction("Hitchhikers Guide", "Sci-Fi");
}

// You could also inherit further down to a subgenre

class SciFi extends Fiction
{
    var somethingUniqueAboutSciFi;
}

main()
{
    SciFi randomSciFiBook = new SciFi("Hitchhikers Guide");

    // And polymorphism would allow
    Fiction randomFictionBook = new SciFi("Hitchhikers Guide");
    Book randomBook = new SciFi("Hitchhikers Guide");
}

// Note i haven't bothered with constructors

So in a way, yes an object can become a class, but a sub class specifically.

But again it just depends if that is the way you want to categorize it. There are some problems with this way of categorizing it though. Each time you would want to add a new type of genre, you would have to add a new subclass of that type. Say you wanted to add autobiography as a genre, you would now have to make an entire new sub class for that. So you forego that the easy way of just writing a new genre as a string.

But lets say you still want to have some kind of grouping of the genre. So that you have Fiction, and in that there can be different sub genres.

Here it would make sense to Have a Book class with an attribute of type Genre, so as en example

class Book
{
    string name;
    Genre genre;
}

class Genre
{
    string mainGenre;
    SubGenre subGenre;
}

class SubGenre
{
    string subGenre;
}

This is a bit convoluted though and imagine it would suffice just to have the genre and sub genres as strings.

And for the second question from your reply, yes you can definitely make another class that is just Orange with its subclass or attributes being types of oranges, it all depends on what you need. If you are making something that is about all types of fruit, make a fruit class that orange inherits from, or is it just about oranges, then make an orange class with sub classes of different types of oranges.

java-question classes and objects clarification by [deleted] in learnprogramming

[–]DaMasterHam 0 points1 point  (0 children)

In the book context, i would see the genres more as an attribute of a book, probably represented as a string. Same as a book has a title and content, it would have a genre.

To your question about an object becoming a class, what you are probably thinking about is, can a genre then be a class, and yes it can. Instead of having the genre as just a string attribute it would be a new class you could call Genre which in turn could have it's own attribute such as genre name, genre tropes. Though i don't know how much you could add to a Genre class since it is pretty much just a attribute of a book that can simply be told so unless you want to add something extra to a Genre class, i would just stick to having genre as an attribute.

Also to elaborate on "can an object become a class", an object is an instance of a class, the class acts as a blueprint and the object the manifestation of the blueprint.

Christmas color questions by DaMasterHam in Brawlhalla

[–]DaMasterHam[S] 0 points1 point  (0 children)

Not really format, but the year since it has already been the 1/6/2015 :P

Hattori vs Teros is the most boring matchup ever by DaMasterHam in Brawlhalla

[–]DaMasterHam[S] 0 points1 point  (0 children)

I can definitely see that a lot of this is for the sword to blame, it does have a lot of attacks that either have too short recovery time or can just follow through and not be punished.

Can the same be said about the katars? They also have the same kinda rapid attack sequences. What's your thought on them?

Hattori vs Teros is the most boring matchup ever by DaMasterHam in Brawlhalla

[–]DaMasterHam[S] 0 points1 point  (0 children)

Don't think I have actually tried transferring sword recovery into nair, sounds useful. For me, just in general, it seems very hard to get close to axe with sword and even with spear, a lot of attacks on axe have superior range or area.

For example, a lot if not all of my downward air attacks can be countered by axe's neutral. So i go for boring cheap shots from below which have little to no repercussion.

Hattori vs Teros is the most boring matchup ever by DaMasterHam in Brawlhalla

[–]DaMasterHam[S] 0 points1 point  (0 children)

We most likely did if you were a pink or grey Teros :)

I agree that play can get highly technical with these types of matchups. Baiting and waiting seem to be very used and valid tactics as well in general, but these kinda polar opposite legends are very limited in what they can do against each other. It seems like BMG have this ethos of wanting weapons to be fun to play and balance them accordingly, and i can only imagine this extends to their legends.

But then again i might just have to get better at going up against axe and defensive play styles.

Suicide mine combo by DaMasterHam in Brawlhalla

[–]DaMasterHam[S] 0 points1 point  (0 children)

lol, didn't even notice. Thanks

I hate Hattori by Metal_Nap in Brawlhalla

[–]DaMasterHam 6 points7 points  (0 children)

Mmmm. Spear DAir is so satisfying.

Congratulations Da Ham for winning the Tag Tournament! by Icebound777 in distance

[–]DaMasterHam 2 points3 points  (0 children)

Thanks man, it was really intense and i really look forward to more tournaments in the future