Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,659 members, 7,955,388 topics. Date: Sunday, 22 September 2024 at 02:10 AM |
Nairaland Forum / Science/Technology / Programming / Learning To Program With Java by the Fulaman (43076 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) ... (5) (6) (7) (8) (9) (10) (11) ... (16) (Reply) (Go Down)
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:36pm On May 05, 2016 |
ANTONINEUTRON: Hi, a few things, the objective of this programme is to keep looping until the user guesses the correct answer. You seem to be missing your iteration statement that tests the random number that is generated. Also in regards to if conditional statements, my question for you is why are you checking if the number is equal to, less than or greater than 47. Keep in mind that a randomly generated number between 1 and 100 can be anything within that range. Also, another note of advice. Please try to practise clean coding. What I mean by that is using proper indentation to make your programmes easier to read by other fellow programmers. I don't know if you have access to a computer, if not, then I'm sorry this is going to be a bit difficult for you, but it is still manageable if you can find online IDEs for Java, where you can compile your code from whichever device that you may be using. |
Re: Learning To Program With Java by the Fulaman by Nobody: 8:01pm On May 05, 2016 |
Fulaman198: i have not programmed in java before, but i read lots of java textbook books back-to-back. tnx |
Re: Learning To Program With Java by the Fulaman by Nobody: 8:27pm On May 05, 2016 |
Fulaman198: Okies sorry for late reply, busy, final year things thanks for your help! One day I shall reward you when I am rich enough to say thanks for being kind to me hehe |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:31pm On May 05, 2016 |
crotonite: Well I'm going to go on a whim and assume that you already know a C-based language? |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:38pm On May 05, 2016 |
satmaniac: Ok, so practically, I wanted you to use a Switch-case conditional structure within a while loop for the Converter programme. In your programme, You iterate your list 5 times, but that is not the instructions of the programme, so let's go through it carefully. You first initialize tries to 0, then the while loop begins, with while tries is less than or equal to 5, do the following, but before you prompt the user, you increment tries by 1 each time. So what your programme is doing (I haven't actually tested it yet) is going through an iteration 6 times (but displays a list of choices to the user 5 times). What you are supposed to do is keep displaying conversion choices for the user until they (the user) presses 5 to exit. To exit, you can use System.exit(0). The previous command allows the user to exit the programme without issues. If you can, you and ANTONINEUTRON I would like for you to read back on Day 4 and practise with Switch case structures. Then, come back and do this programme again. Thanks! |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:39pm On May 05, 2016 |
Sugarhugs: There are other ways to repay me like putting your feet on my face I'm kidding not thread appropriate. I'm joking It's just a joke haha. Don't get mad at me lol. But to be serious, you don't have to repay me, thanks for the thought though |
Re: Learning To Program With Java by the Fulaman by Nobody: 8:52pm On May 05, 2016 |
Fulaman198: Loool, you made me laugh out loud whats so special about my feet?? anyway, I shall get you 80 cows!!! |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:58pm On May 05, 2016 |
Sugarhugs: LOL I have enough cattle as is, though 80 cattle is no joke, that or feet on my face? I just like beautiful women with beautiful feet. I'm not completely submissive, but I admire beautiful women. |
Re: Learning To Program With Java by the Fulaman by Nobody: 9:58pm On May 05, 2016 |
Fulaman198: Loool, you are the second foot fetish person I have met, didn't know we have you guys in Africa |
Re: Learning To Program With Java by the Fulaman by Nobody: 10:01pm On May 05, 2016 |
Fulaman198: How did u deduce that actually, i knw little 'c,c++,asm,php'. very little of them. |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 10:20pm On May 05, 2016 |
Sugarhugs: What did the first one say when he saw your feet? There are quite a few of us, we are just in hiding because people think foot fetishism is weird in Africa lol. |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 10:22pm On May 05, 2016 |
crotonite: You write code pretty well. But we will see if you can maintain it as we progress. Hopefully you can! lolll 1 Like |
Re: Learning To Program With Java by the Fulaman by Nobody: 10:25pm On May 05, 2016 |
Fulaman198: Lol it is not weird to me though, its cool, the first one said he wanted me to step on his face as well lol. Okay enough of this talk o lets not derail this and change it from java to foot fetish talk, lol 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 10:54pm On May 05, 2016 |
Sugarhugs: LOL you are right sorry about the derailing of the thread. I'll save the foot fetishing talk for another time. |
Re: Learning To Program With Java by the Fulaman by Nobody: 10:56pm On May 05, 2016 |
Fulaman198: Sure sure sure 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 11:22pm On May 05, 2016 |
Sugarhugs: Hopefully very soon |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 7:43am On May 06, 2016 |
What is your take on dis new programme? On the Switch u told us to read, i thought Switch is equal to If-Else statement?? And that my former code, I didn't believe the code showed. Becuz my ba3 shutdown immediately i clicked submit, my phone went off-Reason For The Rough Code. |
Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:11am On May 06, 2016 |
Fulaman198: I corrected it and it is now working perfectly, I am going to post it and I hope this time, it is going to earn me pass mark So, it is now official that I have been demoted to class....erm...Day 4. I been dey think say nobody smart pass me, but now I know a lot of people are. crotonite, well done o! I go soon sabi pass you Rush back to SS4....erm...class4....sorry, I mean assignment4, before senior crotonite comot im koboko Abeg Sugarhugs will you do us a favour and cover your feet in those pair of black ninja socks? Make our teacher no go use feet do topic for Day7 1 Like |
Re: Learning To Program With Java by the Fulaman by Nobody: 9:26pm On May 06, 2016 |
satmaniac: Looooool! Okies! 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 10:28pm On May 06, 2016 |
satmaniac: Her new picture is making me lose focus even more all I can think of is being under this Goddesses feet. 1 Like |
Re: Learning To Program With Java by the Fulaman by Nobody: 10:57pm On May 06, 2016 |
Fulaman198: Lol please I have updated now ehn concertrate now ehn no more visible feets, me am almost done with HTML moving to CSS by tomorrow oo 2 Likes |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 1:26am On May 07, 2016 |
Sugarhugs: Na so? I'm very proud and happy for you , you will definitely excel at Cascade Style Sheets |
Re: Learning To Program With Java by the Fulaman by Nobody: 9:54am On May 07, 2016 |
Fulaman198: Yeah after that I wanna divide into python before java and others 1 Like |
Re: Learning To Program With Java by the Fulaman by satmaniac(m): 10:46am On May 07, 2016 |
Here is the Assignment 1 using Switch control statement: import java.util.Scanner; public class Convert{ public static void main(String[]args){ int count=0; int enter ; double centimeter; double celsius; double naira; double meter; Scanner stdio = new Scanner(System.in); while(count<=4) { System.out.println("Please enter a digit here:" enter = stdio.nextInt(); count++; switch(enter){ case 1: System.out.println("Please enter a value in centimeter here:" centimeter = stdio.nextDouble(); System.out.println(centimeter + " " + "Equivalent in inches is:" + " " + centimeter/2.54 + "inches" break; case 2: System.out.println("Please enter a value in meter here:" meter = stdio.nextDouble(); System.out.println(meter + " " + "Equivalent in feets is:" + " " + meter/3.28 + "feets" break; case 3: System.out.println("Please enter a value in Celsius here:" celsius = stdio.nextDouble(); System.out.println(celsius + "C" + " " + "Equivalent in fahreinheits is:" + " " + 32+(9/5)*celsius + "fahreinheits" break; case 4: System.out.println("Please enter a value in Naira here:" naira = stdio.nextDouble(); System.out.println( naira + "Naira" + " " + "Equivalent in Euros is:" + " " + naira/227.96 + "euros" break; case 5: System.exit(0); break; default: } } } } |
Re: Learning To Program With Java by the Fulaman by satmaniac(m): 10:56am On May 07, 2016 |
[center]Assignment 2 Day 5[/center] import java.util.Scanner; import java.lang.Math; public class Guess{ public static void main(String[]args){ int count = 0; int enter; int rndm = (int)((Math.random() * 100) + 1); Scanner stdio = new Scanner(System.in); while(count<=100){ System.out.println("Please guess a number between 1 and 100" enter = stdio.nextInt(); count++; if(enter==rndm){ System.out.println("You win! You got it after" + " " + count++ + " " + "attempts" }else{ System.out.println("Wrong guess" } } } } |
Re: Learning To Program With Java by the Fulaman by satmaniac(m): 11:08am On May 07, 2016 |
Fulaman198, sir, how can I implement a code that will tell me the number of times the user guessed before getting it right? I tried using count++ and I know it is wrong, otherwise, my code seems to run well for me here. I tested it by reducing the range from 1-5 instead of the one given and it work well. I will appreciate if you point out anything that is missing or not right in the codes. Thanks. |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 4:40pm On May 07, 2016 |
Sugarhugs: Lol that's great, you will do well for sure |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 4:47pm On May 07, 2016 |
satmaniac: This is a lot better than before, but you need to remember that your while loop tests for a Boolean expression, meaning that it tests for while a particular condition is or isn't true. I this particular case, the while loop should be testing the number that the user input. Please fix your code based on the advice. Thanks! |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 5:02pm On May 07, 2016 |
satmaniac: So a few things, when writing a programme, you want to make sure that whoever reading it understand your rhetoric very well. I'll give you some suggestions before I discuss your code. For one, if you get a coding job irrelevant of language, you want to make sure your variables are easy to understand. For instance, the user guess variable, you called it enter. Wouldn't a better variable name be "userGuess"? So each time a user guesses a new value, the value for user guess is updated. I understand that rndm stands for random, but I think a better variable name would have been rndmNumber. Think about the programme and whom reads it. Your colleagues will one day assess your code and you don't want to be notorious for writing code that looks "ugly". Now to discuss the programme your wrote, your while loop is not supposed to be testing the expression while the count is less than or equal to 100, in essence you are saying while the number of tries is less than or equal to 100, then do the following instructions within the while loop code block. The while loop expression should be testing "while the number the user enters is not the randomly generated number" check to see if user input number is less than, greater than or equal to the randomly generated number. Just like the instructions say. Do you understand now? If the user guesses incorrectly, the counter for the number of tries is incremented by one. 1 Like |
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:01pm On May 07, 2016 |
ANTONINEUTRON: Hello Antonineutron just a few things. Remember that you or whomever is playing your guessing game is attempting to guess the correct Random number. The while loop (or do-while loop) conditional should be testing for while the user's guess is not equal to the randomly generated number which in itself is stored to a variable. Remember, each time you start a new game, the randomly generated number is different. It's not a static number. So using a while loop to check for a number that was generated once is not a good idea. Remember what your variables are for. I hope that helps you out. Thanks! |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 8:08pm On May 07, 2016 |
Fulaman198:Ok!! Captain |
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 10:41am On May 08, 2016 |
Goodmrning Fulaman! Checkout my new code;
|
(1) (2) (3) ... (5) (6) (7) (8) (9) (10) (11) ... (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. 92 |