Development > Coding

Learning Java Programming on Linux

<< < (2/4) > >>

Homework:

--- Quote from: justme2 on July 25, 2017, 03:41:50 PM ---I have no idea if that is the problem, but the text editor I use (Leafpad) has an option to set the required line terminator to CRLF or just LF. I can only suggest trying it as I do not use Java.

--- End quote ---

Hi justme2, Lite's text editor has this option too but it did not work for me. Thanks for suggesting it though.


--- Quote from: bitsnpcs on July 25, 2017, 08:02:14 PM ---Hello,
I use the gedit and terminal for the Python book I use, I had a look on Google it says gedit can be used for Java with the terminal.

I think they call it ethical because it is legal like pentesting.


--- End quote ---

Thanks bitsnpcs, I'll install gedit later this evening and try it out.

bitsnpcs:
Hello,
I use the gedit and terminal for the Python book I use, I had a look on Google it says gedit can be used for Java with the terminal.

I think they call it ethical because it is legal like pentesting.

justme2:

--- Quote from: Homework on July 25, 2017, 11:19:29 AM ---
--- Quote from: justme2 on July 24, 2017, 03:53:06 PM ---I'm not familiar with java either, but one thing springs to mind - I think windows and linux use different line terminators in text editors, CRLF and LF.  Could that be the problem?

--- End quote ---

Hello justme2, thank you for pointing out the difference!
So I found this article: https://blog.codinghorror.com/the-great-newline-schism/, unfortunately I'm still none the wiser on how this would affect Lite text editor processing the empty spaces.

Windows text editor save encoding as ANSI, while Lite text editor save encoding as UTF-8. Could this be the reason for this problem?

--- End quote ---

I have no idea if that is the problem, but the text editor I use (Leafpad) has an option to set the required line terminator to CRLF or just LF. I can only suggest trying it as I do not use Java.

Homework:

--- Quote from: justme2 on July 24, 2017, 03:53:06 PM ---I'm not familiar with java either, but one thing springs to mind - I think windows and linux use different line terminators in text editors, CRLF and LF.  Could that be the problem?

--- End quote ---

Hello justme2, thank you for pointing out the difference!
So I found this article: https://blog.codinghorror.com/the-great-newline-schism/, unfortunately I'm still none the wiser on how this would affect Lite text editor processing the empty spaces.

Windows text editor save encoding as ANSI, while Lite text editor save encoding as UTF-8. Could this be the reason for this problem?

Homework:

--- Quote from: firenice03 on July 24, 2017, 01:29:46 PM ---Giving it a quick look... The part listed...

--- Code: ---new Name("Cookie" + "Monster" + "Jr")
--- End code ---
Although you have spacing between " + there isn't any coded spaces..


Maybe try, see if it results properly

--- Code: ---new Name("Cookie " + "Monster " + "Jr")
--- End code ---

--- End quote ---

Hello firenice03, thank you for your suggestion. It did work, but there are still extra empty spaces that appeared in front of the name due to the toString method.
newName is supposed to appear as indicated by the toString method which has a space in between first, middle, and last name. The idea of the exercise is to to input each name alone without any spaces just like anyone filling up a field on a form etc., that's why toString method is used.
There are two Java files and they both worked together, and here's the first set of code (called Name.java) that sets the foundation (if that's how programmer(s) put it?):

--- Code: ---public class Name
{
private String first;
private String middle;
private String last;

// constructor methods allow us to declare class objects and provide those objects with some data.
public Name(String f, String m, String l)
{
first = f;
middle = m;
last = l;
}

public Name(String f, String l)
{
first = f;
middle = "";
last = l;
}

public Name(String l)
{
first = "";
middle = "";
last = l;
}

//default constructor - it's a good idea to add one that doesn't have data in them
public Name()
{
first = "";
middle = "";
last = "";
}

public String toString()
{
return first + " " + middle + " " + last;
}
}
--- End code ---

And here's the other file that has the data called NameTest.java:

--- Code: ---public class NameTest
{
public static void main(String[] args)
{
// instantiation - creating an instance of the Name class
Name myName = new Name("Cookie" + "Monster" + "Jr");
Name yourName = new Name("Great" + "Cookie");
Name aName = new Name("Durr");
System.out.println("myName: " + myName.toString());
System.out.println("yourName: " + yourName.toString());
}
}
--- End code ---

NameTest.java would not work without Name.java. These are the two files in their entirety. Hope this would give clarity to what the codes are supposed to do.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version