Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,268 members, 7,954,047 topics. Date: Friday, 20 September 2024 at 11:25 AM |
Nairaland Forum / Science/Technology / Programming / Learning To Program With Java by the Fulaman (43042 Views)
How To Program Arduino Uno / How To Program With Your Android Phone Using Aide IDE Environment / Which Training Center Can Someone Learn How To Program Quickly (2) (3) (4)
(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (16) (Reply) (Go Down)
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 5:00pm On May 02, 2016 |
ANTONINEUTRON: Your code has a lot of errors and wouldn't work. What I would recommend doing is using a switch structure within either a while loop or do-while loop iteration structure. Also, why are you attempting to use JOptionpane. That's not via the instructions and is a part of the swing GUI libraries which we won't be doing (not even in the future because Swing is becoming deprecated by Oracle). Instead, we will be using JavaFX in the future for GUI-based assignments. We will only touch on it briefly though because we are trying to solve problems with programming, not trying to make fancy looking GUIs. With that said, please redo your assignment with the suggestions given thanks! |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 5:01pm On May 02, 2016 |
crotonite: I will check your assignment within the next hour or two, need to wash some clothes. Thanks! |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 5:04pm On May 02, 2016 |
MuhdG: Alright little bro, do what makes you feel comfortable or happy. How is your Electrical Engineering major coming along? |
Re: Learning To Program With Java by the Fulaman by Nobody: 5:13pm On May 02, 2016 |
Fulaman198:Alhamdulillah.. but bamu fara majoring ba, still general electrical engineering 1 Like |
Re: Learning To Program With Java by the Fulaman by Nobody: 6:33pm On May 02, 2016 |
Fulaman198: Okies! 1 Like |
Re: Learning To Program With Java by the Fulaman by Nobody: 6:50pm On May 02, 2016 |
ANTONINEUTRON:sorry bro, i am currently on a resource constrained device. why not dowload the attached .java an run it. |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:43pm On May 02, 2016 |
MuhdG: Madalla |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:52pm On May 02, 2016 |
crotonite: Your programme is excellent. The only thing you were missing was menu option #5 "exit programme". You implemented it in code, but it is not one of the options to select. I know you just forgot it, so I'll give you an A for this assignment still. Very nicely done! 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:54pm On May 02, 2016 |
Sugarhugs: So how is it going on the assignment miss ? |
Re: Learning To Program With Java by the Fulaman by Nobody: 10:29pm On May 02, 2016 |
Fulaman198: oops! that escaped my debugging session. thanks 4 pointing that out. 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 9:14am On May 03, 2016 |
crotonite: No problem you did well. 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 9:37am On May 03, 2016 |
Another assignment for Day 5: I did not go over how to do random numbers, but I will briefly. Let's assume that you want to create a random number on a dice from 1 to 6, how would you go about doing that?
I know that you see an int in parenthesis, this is what we call casting in programming when you practically convert a datatype to another datatype. By default, Math.random() method returns a double, so when you place an (int) in front of it, it converts that datatype to an int (we will discuss this a lot more later on the course). So let's go over the random syntax. If I want to generate a random number between 0 and n, that expression would look something like this in Java:
if I wanted to generate a random number between 1 and n (where like in the previous example n is any integer) it would look like this:
Now for this assignment, I would like for you to create a guessing game that guesses a number between 1 and 100. Once the guess has been achieved, the computer outputs how many guesses it took to get to the random number. This game should not terminate until the user has guessed the correct answer. Example: see output below to see how game works
|
Re: Learning To Program With Java by the Fulaman by Nobody: 10:05am On May 03, 2016 |
Fulaman198: Hi, well been busy haven't settled down for it fully, but I'm going with HTML and CSS before java since I would like to create my own website, |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 10:12am On May 03, 2016 |
Sugarhugs: Ok thanks 1 Like |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 5:20pm On May 03, 2016 |
Finally my ban has been lifted!! 1 Like |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 5:25pm On May 03, 2016 |
Fulaman198:Ok!! I failed. But your new assignment is hard , Google couldn't provide anything tangible. A article regarding the assignment will help. 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:21pm On May 03, 2016 |
ANTONINEUTRON: Part of being a good Computer scientist is being able to solve difficult problems with a computer, that's what computer science is all about. We have gone over while loops and do while loops as well as the switch case conditional structure. You should try to use those things to solve this problem. 1 Like |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 8:50pm On May 03, 2016 |
Fulaman198:Ok |
Re: Learning To Program With Java by the Fulaman by Nobody: 9:33pm On May 03, 2016 |
Fulaman198: Hi dear, good evening, please I saw somewhere that says Linux is beat for programin?? Forgive me for my random quest I just wanna be sure and have knowledge of what I'm doing to make decision 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 10:18pm On May 03, 2016 |
Sugarhugs: Anything for a beautiful lady, Well Linux is great for programming because it has built-in tools that Windows does not have (yet) but will certainly have in the future. For one both Linux and Mac (Mac is a UNIX variant) have access to the Bash shell which stands for bourne again script. It allows you to use tools like sed, awk, grep, etc. Windows will soon have these tools because they are working side by side with U.K. company Canonical (makers of Ubuntu Linux) to incorporate these features used by programmers at the command line. So Windows developers need not worry as this future will probably be available to them sometime between June and August. |
Re: Learning To Program With Java by the Fulaman by Nobody: 6:43am On May 04, 2016 |
Fulaman198: Awww thanks for your help dear Please one more thing if one learns to programme with Linux can they still use windows to programme? 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:25am On May 04, 2016 |
Sugarhugs: Absolutely, you can have a Linux virtual machine using VMware or Virtual Box. Allocate like 35gb to your Linux VM machine and then keep your regular Windows machine. If you have any other questions, please feel free to ask. |
Re: Learning To Program With Java by the Fulaman by Nobody: 9:36am On May 04, 2016 |
Fulaman198: That will be all, thanks very much I can just install Ubuntu 1 Like |
Re: Learning To Program With Java by the Fulaman by satmaniac(m): 3:46pm On May 04, 2016 |
Fulaman198: First assignment Day 5 import java.util.Scanner; public class Converter{ public static void main(String[]args){ int enter; int tries = 0; double centemeter; double cmresult; double metres; double ftresult; double celsius; double clresult; double naira; double nrresult; Scanner stdio = new Scanner(System.in); while(tries<=5){ System.out.println("please enter a value here:" enter = stdio.nextInt(); tries++; if(enter==1){ System.out.println("Enter your value in centemeter here:" centemeter = stdio.nextDouble(); cmresult = centemeter/2.54; System.out.println(centemeter+ " " " equivalent in inch is " + " " + cmresult + "inches " } else if(enter==2){ System.out.println("Enter your value in metres here:" metres = stdio.nextDouble(); ftresult =metres/3.28; System.out.println( metres + "equivalent in feet is: " + " " + ftresult + "feets" ); } else if(enter==3){ System.out.println("Enter your value in Celsius her:" celsius = stdio.nextDouble(); clresult = 32+(9/5)*celsius; System.out.println(celsius + " equivalent in fahreinheits is "clresult +" " + "fahreinheits." } else if(enter==4){ System.out.println("Enter your value in Naira:" naira = stdio.nextDouble(); nrresult = naira/227.96; System.out.println(naira + "equivalent in euro is "nrresult + " " + "euros" }else if(enter>=5){ } } } } Solution to Assignment 2 Day 5 import java.util.Scanner; import java.lang.Math; public class Guess{ public static void main(String[]args){ int count = 0; double rndm = (int)((Math.random() * 100) + 1); Scanner stdio = new Scanner(System.in); while(count<=100){ System.out.println("Please guess a numbber between 1 and 100" count = stdio.nextInt(); count++; if(count==rndm){ System.out.println("You wint it took you" + count++ + "times to get it right" }else{ } } } } Advice, tips, and everything that can improve my codes will be appreciated, thanks Fulaman198. |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 5:56pm On May 04, 2016 |
Sugarhugs: You are welcome |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 5:57pm On May 04, 2016 |
satmaniac: When I get on a computer, I'll tell you where you went wrong. I can't type too well on a smartphone |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 9:06pm On May 04, 2016 |
satmaniac: In the future, when submitting assignments, please submit them in separate posts so that I can better advise you on each one separately. I will start off however with your first submission. Your code simply won't work, I don't know if you have a compiler to test it out (I haven't tested it), but simply by reading your code, I can assess that your code has a lot of issues. For one, you initialise tries to 0, but in your code, it remains zero because your never increment tries. A lot of your code is truly unnecessary, things can be made much simpler by using a Switch-Case conditional structure (which we went over) within a while or do-while loop structure. The Switch-Case conditional structure would handle user press events (as you know switch structures work with ints) so if the user presses 1, it does something, if the user presses 2, it does something else if the user presses 5, it exits the program. What i recommend doing is re-reading the section on conditional statements (which if I'm not mistaken should be day 4 in the tutorial). You would want to read the post on the Switch statement and the example(s) I gave. In regards to your second programme, you don't want to set your while loop to a specific count. The while loop as you remember tests a boolean expression. Kindly think about the code before you write it, remember, what are the requirements for the programme? while the number is not the randomly generated number, then you execute commands within the while block. In addition, your count variable is not rightfully placed. I want you to figure out the first part of the programme though with the while statement. Your randomly generated number syntax is on point and correct. However, the rest of the programme needs work. Please use the critique I have given. Thanks! |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 9:08pm On May 04, 2016 |
Sugarhugs: No problem miss just install it on VirtualBox to make sure you actually like using Linux first. I find it a very rewarding experience. Ubuntu (Debian-based) Linux is extremely fun. |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 10:09pm On May 04, 2016 |
import.java.util;
public class Guesser
{
public static void main (String[] args) throws java.lang.Exception
{
double GuessBot=(int) (math.random()*100)+1;
string GuessAsker = "'Please Guess a number between 1 and 100'"; } public static void TheGuesser() { system.out.printIn(GuessAsker ); system.out.printIn(GuessBot); } if(GuessBot==47){ system.out.printIn("You Are Correct" system.out.printIn(\n) system.out.printIn("YOU WIN" system.exit(0); } else if(GuessBot>47){ system.out.printIn("Too high, try again" return TheGuesser(); } else if(GuessBot<47){ system.out.printIn("Too low try again" return TheGuesser(); } } PLS GO THRU IT, THAT IS THE BEST I CAN CMEUP WITH CURRENTLY!! |
Re: Learning To Program With Java by the Fulaman by Nobody: 8:16am On May 05, 2016 |
DONE.
|
Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:29am On May 05, 2016 |
Fulaman198: Thanks a lot for the advice. About not incrementing tries, I did increment tries in the first assignment. Perhaps the spacing of the codes is too compact that you missed it, it is on the third statement inside the while block. Also, I tried using switch control statement and I have errrors on my compiler, whenever I compiled it, hence, I decided to use if-else-if control statement and it compiled and run without error. However, I will still try using the switch control statement and when it compile well, I will post it here too. On the second assignment, I compiled it too and it did not show me any error, but since I run the programme, I was not able to guess the correct answer, that is the value entered has not match the randomly generated number till now. So,it seem the problem I may be having is not with the syntax, maybe, logical problem. I will not pretend and act as if I understand what you said about not wanting to initialise my count to 0. If you don't mind could you throw more light on it? I mean why would I initialise tries to 0 in assignment 1 and can not do the same in assignment 2? About posting my assignment on a separate comment, this is a mistake I will never repeat again. Thanks. [size=10]MODIFIED[/size I checked the code I posted here on nairaland and I discovered that there are a lot of mistake mistake in it, especially, the concatenation. So, the compiler will definitely call out the errors. So, here is the code as it is on my notepad++ text editor: import java.util.Scanner; public class HelloWorld{ public static void main(String[]args){ int enter; int tries = 0; double centemeter; double cmresult; double metres; double ftresult; double celsius; double clresult; double naira; double nrresult; Scanner stdio = new Scanner(System.in); while(tries<=5){ System.out.println("please enter a value here:" enter = stdio.nextInt(); tries++; if(enter==1){ System.out.println("Enter your value in centemeter here:" centemeter = stdio.nextDouble(); cmresult = centemeter/2.54; System.out.println(centemeter+ " " + " equivalent in inch is " + " " + cmresult + "inches " } else if(enter==2){ System.out.println("Enter your value in metres here:" metres = stdio.nextDouble(); ftresult =metres/3.28; System.out.println( metres + "equivalent in feet is: " + " " + ftresult + "feets" ); } else if(enter==3){ System.out.println("Enter your value in Celsius here:" celsius = stdio.nextDouble(); clresult = 32+(9/5)*celsius; System.out.println(celsius + " " + " equivalent in fahreinheits is " + " " + clresult +" " + "fahreinheits." } else if(enter==4){ System.out.println("Enter your value in Naira:" naira = stdio.nextDouble(); nrresult = naira/227.96; System.out.println(naira + " " + "equivalent in euro is " + " " + nrresult + " " + "euros" }else if(enter>=5){ } } } } |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:31pm On May 05, 2016 |
crotonite: Well done, are you sure you haven't programmed in Java before? You seem to know about the Random class. |
(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (16) (Reply)
Sultan Akintunde Set For Guinness World Record For Longest Software Coding Time / What Are The Best Laptops For Programmers And Hackers?! / Basil Okpara Jr, Biography, Age, Nigerian Programmer Who Built 30 Mobile Games
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 105 |