Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,120 members, 7,818,359 topics. Date: Sunday, 05 May 2024 at 01:24 PM

Satmaniac's Posts

Nairaland Forum / Satmaniac's Profile / Satmaniac's Posts

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (of 12 pages)

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 10:27pm On Jun 07, 2016
pachman:
Lol,am also a beginner,just started classes and objects but i would start following op,he explains well,i have even saved his page sef

I tried modifying my code to reflect yours, but, the loop no want stop. It seem what I suspected initially was correct. Sharp guy! You don enter Classes ans Objects? Nawa 4 u o.
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:19pm On Jun 07, 2016
pachman:


You tried very well.. Thumbs up but it would gv a logical error if the user inputs three values less than 3..


Look at inside the while statement that I would put into for loop






import java.util.Scanner;

public class Array{

public static void main(String[]args){
int i=0;
int[]Scores;
double average=0;
int total=0;


System.out.println("This program collect Scores of students in ten subjects and also display their average."wink;
Scores = new int[10];

Scanner stdio = new Scanner(System.in);



for(i=0;i<Scores.length;i++){

System.out.println("Please enter Test Score" + i + ":"wink;
Scores[i] = stdio.nextInt();
//you should use || and not &&..
while (Scores[i]<=-1 || Scores[i]>100){
System.out.println("Score is less than zero, or greater than 100, please, enter a valid score!"wink;
Scores[i]=stdio.nextInt();
}






total+=Scores[i];


}



average=total/Scores.length;
System.out.println("Your average is:" + " " + average);






}


}

Looking at your while loop block, I have no doubt it will work. Initially, the lack of the count increment, almost got me confused, as that is what will render the condition in the while braces false at a point in the program, thereby terminating the iteration. I later realised that if the value you enter is not less than zero nor greater than 100, the condition in the while loop braces will rendered the input as false.

Thank you very much pachman, you really save someone sanity. I have been on this for days now.



Thank ya @ pachman(try change dat name to packwoman). Are you also a beginer like me?

1 Like

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 7:33am On Jun 07, 2016
Fulaman198:


It's correct (briefly skimmed through it, but looks great), nicely done, you kind of took it a step further and instead asked the user for the number of tests they would ideally like to work it. Good job for going the extra km.

I did something nearly similar to Korlahwole,s codes, the first day you posted the assignment, but, I was not sure if I it was correct, for, I reasoned what if the user of the programme entered numbers that are less than zero, say three times, when the programme can not iterate more than than the array size, in this case Scores.length? That means the scores entered will not be up to ten, if you minus the wrong scores entered. As a result of this problem I wasted time looking for a way to do it better. Is there a way someone can write the programme, to accommodate such or more wrong entries from the user? Because, I tried and was having a RuntimeException- array-out-of-index error.



The initial code below:


I had to modify the codes as it, it didn't work as expected, But this does. Sir Fulaman198 pachman make una help me touch light am

import java.util.Scanner;

public class Array{

public static void main(String[]args){
int i=0;
int[]Scores;
double average=0;
int total=0;


System.out.println("This program collect Scores of students in ten subjects and also display their average."wink;
Scores = new int[10];

Scanner stdio = new Scanner(System.in);



for(i=0;i<Scores.length;i++){

System.out.println("Please enter Test Score" + i + ":"wink;
Scores[i] = stdio.nextInt();

if(Scores[i]<=-1 & Scores[i]>100){
System.out.println("Score is less than zero, or greater than 100, please, enter a valid score!"wink;
Scores[i]--;
}




Scores[i]++;
total+=Scores[i];


}



average=total/Scores.length;
System.out.println("Your average is:" + " " + average);






}


}
Programming / Re: Things I Wish I Knew Before Releasing My First App by satmaniac(m): 3:56pm On Jun 05, 2016
larisoft:


wow thanks for the thumbs up satmaniac. You can reach me on larypetero at gmail.com

You got mail.
Programming / Re: Things I Wish I Knew Before Releasing My First App by satmaniac(m): 8:27am On Jun 05, 2016
larisoft:

mmm...FrankLampard. This one you are hailing me by my real name. I dey wonder how you come know the name oh. Thanks for stopping by my brother.

E be like say you know no say your name dey on your blog o. Abi you think say people no dey read your sense making article on your potentials filled blog? I go soon flash you grin grin grin Na joke o.

However I got a coding problem and it seem this is the perfect opportunity to lay bare the problem to you, but I don't know what is wrong with nairaland PM, for I have tried PMing you and for some unknown reasons I couldn't get to type into the text field on the PM page.

1 Like

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:10pm On Jun 01, 2016
ANTONINEUTRON see wetin u don cause? Now him wan push bone come give us. Fear don catch me already.


Fulaman198:


I'll post the assignment soon
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 2:17pm On May 31, 2016
ANTONINEUTRON:

L gringrin L

Why you come dey open teeth? Abi you wan show our tisha(Fulaman198) say you get strong teeth scatter bones and hard 'pomo'?
Oga tisha, no look this guy big and strong teeth come give us hard pomo(assignment) o, as I no follow get that kind teeth o. if na lie check am cheesy see? na emmpty oo!
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 1:57pm On May 31, 2016
Fulaman198:


Hey my friend, I'll check it out

Will appreciate it oo. As I am typing on my tecno h5 phone, my eyes glued to lesson 4 page I opened on the screen of my 15th century Nigerian laptop. Let me know if I am ready to join you guys in lesson 6, pls.
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 8:03am On May 30, 2016
You made it looked so easy, but I am sure the assignment is definitely going to be as tough as poorly cook 'pomo', but I like that.

And I will like to hear what you think about the corrected version of assignment I submitted. Do I need to go back to lesson 4?
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 12:02am On May 29, 2016
Fulaman198:
I'm sorry ladies and gentlemen, I have not forgotten about you and I will try and make it up to you tomorrow or Monday. I'm really sorry but I have been so busy. Please tolerate my absence. I will be posting again sometime soon. In the meantime, I hope that you are all doing well.

No wahala bro, I and I guess others too know how busy you are.
Phones / Re: Best Data Plan Comparison Between MTN Etisalat Airtel GLO by satmaniac(m): 9:29am On May 24, 2016
DjAndroid:
On glo, if you recharge any amount with *223*PIN# you will get the amount recharged plus the corresponding data and that same amount to call family and friends.

Eg. If you have 200 recharge card, recharge with *223, 200 naira will be credited to you plus 200mb plus another 200 to call family and friends. You can recharge just any amount and get that same amount in data.

On the screenshot below, I recharged #200 and got that.
Politics / Re: Goodluck Jonathan Visits Nigerians In Newark, New Jersey, Us(photos) by satmaniac(m): 8:54am On May 24, 2016
Abagworo:


Biko stop spreading lies authoritatively. Thank God for Internet.

http://www.premiumtimesng.com/business/182543-nigerian-govt-borrowing-billions-to-pay-salaries-okonjo-iweala.html

http://www.pmnewsnigeria.com/2015/05/06/fg-borrows-n473bn-to-pay-salaries-okonjo-iweala/


The federal government has borrowed 473 billion naira to
meet up with recurrent expenditure including paying of
salaries while it is yet to release funds for capital projects.
According to Reuters, Nigeria has already used half the
borrowing allowance it has budgeted for and has not
released any funds for capital expenditure so far this year,
as lower oil prices eat into its revenues, the country’s
finance minister said on Tuesday.


“We have serious challenges,” Finance Minister Ngozi
Okonjo-Iweala said in an emailed statement. “Things have
been tough since the beginning of the year and they are
likely to remain so till the end of the year.”

The borrowed money has been spent to cover overhead,
including salaries, the minister said.
Lawmakers in Africa’s biggest economy and oil producer
last week passed a 4.49 trillion naira ($23 billion) budget
for 2015, 3.2 percent lower than last year’s spending plans.
It was forced to cut spending after global oil prices
slumped.


The budget took longer than usual getting through
parliament, worsening the cash squeeze, because of the
closely fought general elections in March, which saw
incumbent President Goodluck Jonathan defeated.
“As a result of the 50 percent decline in oil revenues, the
country has faced a difficult cash crunch … Out of the 882
billon naira budgetary provision for borrowing, the
government has borrowed 473 billion naira to meet up with
recurrent expenditure,” the finance ministry said.
Okonjo-Iweala had projected annual domestic borrowing
last year would fall to below 500 billion naira from 577
billion naira in 2013.


The borrowing requirement this year could crowd out
lending to the real economy, raising domestic interest rates
and yields on government bonds, which could hurt growth.
Forecasts for growth have already been lowered twice this
year.
The ministry said that inflation is still in single digits and
that the Nigerian economy is projected to grow by 4.8
percent this year.


Government revenues have shrunk sharply since oil sales
account for up to 80 percent of them and its currency, the
naira, has weakened drastically, despite the central bank’s
spending billions of U.S. dollars to prop it up.
The lack of funds for capital expenditure means badly
needed infrastructure development will be put on hold.
Funding for large projects such as bridges and roads had
already begun to dry up in 2014, forcing construction firms
companies with government contracts to cut back and fire
thousands of workers.

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 8:58am On May 11, 2016
Sugarhugs:



Looooool, I'm innocent o, like innocent idibia grin


shocked Blasphemy!!! How dare you call a serial 'impregnator' innocent? Is that how innocent you are grin grin grin grin?
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 8:45am On May 11, 2016
Fulaman198:
@Antonineutron and @the comedian satmaniac lol I will grade your assignments hopefully before tomorrow, I'm caught up in a storm of stuff right now. Please bare with me, I will hopefully have them graded no later than Wednesday.


Aha got it....project tinz. Remember rest is also a weapon against sickness.

1 Like

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 5:41am On May 10, 2016
ANTONINEUTRON:

It is not about changing from Python to Ruby.
All of them are thesame[C-based languages].
Since u wanna go into Web Development, I'll advice u go with HTML/CSS.

If u are done!
Go and practice.
When praticing, and u are getting better, u should start learning Javascript - Which is a Programming Language.

d fun part of learning Javascript at thesame time practicing HTML is dat Javascript code are implemented in HTML - <script></script> tag - which help u getting familiar with Html mre and mre.

If u are good with d three languages [HTML/CSS/JAVASCRIPT].
U can learn a scripting languages like python, Ruby, php, asp.Net e.t.c.

What will make ur learning of any scripting language fun is the knowledge of Javascript u earlier had.
So what u will nid to strt creating Web Apps with the scripting languages is their framework like Django(python), Ruby on Rails(Ruby) e.t.c

Wit knowledge of a SQL u re good 2 go!!

Good morning everybody smiley Oya make una wake up, I see teacher dey come class. Shebi na 2day in dey teach us arrange....sorry...erm...wetin be the name self....hit head and stamp feet on the ground...Ok now I don get am. Array.

cheesy So dis guy too don tey for the game. Thumb up bro. Come o! This one wey our teacher never show face so, hope say that fine lady never carry her feet match our teacher face o grin Bia, Sugarhugs, come explain yasef before we pronounce you guilty.
You know say, the instruction was to put feet on his face, no go match our oga face o sad
Politics / Re: DSS Embarrass Ezeife And Pat Utomi In Awka by satmaniac(m): 9:14am On May 09, 2016
freeborn76:

These politicians just want to remain relevant; for all you know, the President may not have a hand in this. One thing I have come to accept about the Igbos is that the Biafran War left a deep sense of 'victimhood' on their psyche. Everything that happens is always rashly interpreted as victimisation or marginalisation. The sad thing about victim mentality is that you will NEVER rise above your supposed 'perpetrator'...that clearly explains why we may never have an Igbo president (it can happen in Biafra though). As little in population as the Cross River/Akwa Ibom axis are, they are more developed and more politically united, I will rather vote an Efik or Ibibio man for President than a sulking Igbo man...I don talk my own.

Dr freeborn76 don find the problem o, make una kuku go find solution to una problem grin grin

Ezeife talk something and una just believe say na wetin happen be that? Una need cure for this una hatred.

1 Like

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 8:40am On May 09, 2016
And the assignment 2 Day 5, I hope I dey right:


import java.util.Scanner;
import java.lang.Math;

public class Guess{

public static void main(String[]args){

int count = 0;
int numberGuessed = 0;

int randomNumber = (int)((Math.random() * 100) + 1);
Scanner stdio = new Scanner(System.in);

while(numberGuessed!=randomNumber){
System.out.println("Please guess a number between 1 and 100"wink;
numberGuessed = stdio.nextInt();
count++;
}

System.out.println("You win! After" + " " + count++ + " " + "times" );








}


}
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 8:31am On May 09, 2016
Alternatively, using if-else-if-else flow control statement, assignment 1 Day 5 will look like this:


import java.util.Scanner;

public class HelloWorld{



public static void main(String[]args){
int selectedConversionUnit = 0;
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(selectedConversionUnit>=0){
System.out.println("please enter a value here:"wink;
selectedConversionUnit = stdio.nextInt();
tries++;

if(selectedConversionUnit==1){
System.out.println("Enter your value in centemeter here:"wink;
centemeter = stdio.nextDouble();
cmresult = centemeter/2.54;
System.out.println(centemeter+ " " + " equivalent in inch is " + " " + cmresult + "inches "wink;
}
else if(selectedConversionUnit==2){
System.out.println("Enter your value in metres here:"wink;
metres = stdio.nextDouble();
ftresult =metres/3.28;
System.out.println( metres + "equivalent in feet is: " + " " + ftresult + "feets" );
}
else if(selectedConversionUnit==3){
System.out.println("Enter your value in Celsius here:"wink;
celsius = stdio.nextDouble();
clresult = 32+(9/5)*celsius;
System.out.println(celsius + " " + " equivalent in fahreinheits is " + " " + clresult +" " + "fahreinheits."wink;
}
else if(selectedConversionUnit==4){
System.out.println("Enter your value in Naira:"wink;
naira = stdio.nextDouble();
nrresult = naira/227.96;
System.out.println(naira + " " + "equivalent in euro is " + " " + nrresult + " " + "euros"wink;
}else if(selectedConversionUnit==5){
System.exit(0);
}
}





}













}


Sorry o! I don develop some kind of bias towards if-else-if-else control statement, so, include am
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 8:26am On May 09, 2016
Fulaman198:


LOL no, the Goddess earlier asked some questions about it and being the foot slave/boy the gentleman that I try to be towards beautiful women, I tried to be courteous and answer the question(s).

With that said, I'm just waiting on the others to formulate correct solutions to the problems given, I see there has been an update to one of the answers, I will check it out soon, but right now reading books on machine learning and stuff. So I'll be back later. The next lesson will be about Arrays. So be ready.


I am sorry @crotonite, for I am the one holding us back. I finished the corrections based on the advice of oga Fulaman198, since yesterday. I will hasten to post them one after the other, in a separate post, so we could move ahead.
Oga, Fulaman198, here is assignment 1 Day 5:


import java.util.Scanner;

public class Convert{

public static void main(String[]args){
int count=0;
int selectedConversionUnit = 0 ;
double centimeter;
double celsius;
double naira;
double meter;
Scanner stdio = new Scanner(System.in);
while(selectedConversionUnit>=0) {


System.out.println("Please enter a digit here:"wink;
selectedConversionUnit = stdio.nextInt();
count++;
switch(selectedConversionUnit){



case 1: System.out.println("Please enter a value in centimeter here:"wink;
centimeter = stdio.nextDouble();
System.out.println(centimeter + " " + "Equivalent in inches is:" + " " + centimeter/2.54 + "inches"wink;
break;

case 2: System.out.println("Please enter a value in meter here:"wink;
meter = stdio.nextDouble();
System.out.println(meter + " " + "Equivalent in feets is:" + " " + meter/3.28 + "feets"wink;
break;

case 3: System.out.println("Please enter a value in Celsius here:"wink;
celsius = stdio.nextDouble();
System.out.println(celsius + "C" + " " + "Equivalent in fahreinheits is:" + " " + 32+(9/5)*celsius + "fahreinheits"wink;
break;

case 4: System.out.println("Please enter a value in Naira here:"wink;
naira = stdio.nextDouble();
System.out.println( naira + "Naira" + " " + "Equivalent in Euros is:" + " " + naira/227.96 + "euros"wink;
break;

case 5: System.exit(0);
break;

default:

}

}
}
}

1 Like

Programming / 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.
Programming / 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"wink;
enter = stdio.nextInt();
count++;



if(enter==rndm){

System.out.println("You win! You got it after" + " " + count++ + " " + "attempts"wink;
}else{

System.out.println("Wrong guess"wink;
}










}


}

}
Programming / 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:"wink;
enter = stdio.nextInt();
count++;
switch(enter){



case 1: System.out.println("Please enter a value in centimeter here:"wink;
centimeter = stdio.nextDouble();
System.out.println(centimeter + " " + "Equivalent in inches is:" + " " + centimeter/2.54 + "inches"wink;
break;

case 2: System.out.println("Please enter a value in meter here:"wink;
meter = stdio.nextDouble();
System.out.println(meter + " " + "Equivalent in feets is:" + " " + meter/3.28 + "feets"wink;
break;

case 3: System.out.println("Please enter a value in Celsius here:"wink;
celsius = stdio.nextDouble();
System.out.println(celsius + "C" + " " + "Equivalent in fahreinheits is:" + " " + 32+(9/5)*celsius + "fahreinheits"wink;
break;

case 4: System.out.println("Please enter a value in Naira here:"wink;
naira = stdio.nextDouble();
System.out.println( naira + "Naira" + " " + "Equivalent in Euros is:" + " " + naira/227.96 + "euros"wink;
break;

case 5: System.exit(0);
break;

default:

}

}
}
}
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:11am On May 06, 2016
Fulaman198:


Ok, so practically, I wanted you to use a Switch-case conditional structure within a for 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!

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 grin
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 grin
Rush back to SS4....erm...class4....sorry, I mean assignment4, before senior crotonite comot im koboko grin

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 grin grin

1 Like

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:29am On May 05, 2016
Fulaman198:


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!


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:"wink;
enter = stdio.nextInt();
tries++;

if(enter==1){
System.out.println("Enter your value in centemeter here:"wink;
centemeter = stdio.nextDouble();
cmresult = centemeter/2.54;
System.out.println(centemeter+ " " + " equivalent in inch is " + " " + cmresult + "inches "wink;
}
else if(enter==2){
System.out.println("Enter your value in metres here:"wink;
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:"wink;
celsius = stdio.nextDouble();
clresult = 32+(9/5)*celsius;
System.out.println(celsius + " " + " equivalent in fahreinheits is " + " " + clresult +" " + "fahreinheits."wink;
}
else if(enter==4){
System.out.println("Enter your value in Naira:"wink;
naira = stdio.nextDouble();
nrresult = naira/227.96;
System.out.println(naira + " " + "equivalent in euro is " + " " + nrresult + " " + "euros"wink;
}else if(enter>=5){

}
}





}













}
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 3:46pm On May 04, 2016
Fulaman198:
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?


(int)(Math.random() * 6) + 1); //generate a random number between 1 and 6


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:


(int)(Math.random() * n)


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:


(int)((Math.random() * n) + 1)


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




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:"wink;
enter = stdio.nextInt();
tries++;

if(enter==1){
System.out.println("Enter your value in centemeter here:"wink;
centemeter = stdio.nextDouble();
cmresult = centemeter/2.54;
System.out.println(centemeter+ " " " equivalent in inch is " + " " + cmresult + "inches "wink;
}
else if(enter==2){
System.out.println("Enter your value in metres here:"wink;
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:"wink;
celsius = stdio.nextDouble();
clresult = 32+(9/5)*celsius;
System.out.println(celsius + " equivalent in fahreinheits is "clresult +" " + "fahreinheits."wink;
}
else if(enter==4){
System.out.println("Enter your value in Naira:"wink;
naira = stdio.nextDouble();
nrresult = naira/227.96;
System.out.println(naira + "equivalent in euro is "nrresult + " " + "euros"wink;
}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"wink;
count = stdio.nextInt();
count++;



if(count==rndm){

System.out.println("You wint it took you" + count++ + "times to get it right"wink;
}else{

}










}


}

}

Advice, tips, and everything that can improve my codes will be appreciated, thanks Fulaman198.
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 12:58am On Apr 29, 2016
Fulaman198:
In the code segment given, an integer variable 'i' is declared and initialised to 0. After that a while statement is performed with the expression (i < 20), we tell the computer to output to the console "This is a test " with the value of i next to it. After we output, we increment the value of i by one via the 'i++'.

The loop will repeat until i reaches 19 because the condition to be met in the expression is "i is less than 20".


We re grateful sir. We are gradually progressing in this journey
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 2:06am On Apr 20, 2016
Fulaman198:
I will update this thread with a tutorial on iteration hopefully Friday or Saturday and have your assignments that you guys have submitted hopefully by Thursday. Iteration will cover for loops, do-while loops, and while loops. If you want, you can read ahead now before I do the tutorial and give you guys more practise assignments. Best of luck!

It's all right, I understand how busy you are I mean I.can see that your last comment was posted at 11:01pm and before that you posted 8:45pm. I know a lot of thread that lack of time killed, but, you still manage to take us this far, we know we are approaching page 5 now and still have a long way to go. I want you to know that we know how difficult a journey it is and we are with you to the end. May God bless and balance you. Thank you once again, Fulaman198.
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 1:42pm On Apr 17, 2016
My second assignment our teacher Fulaman198 please check it up.


import java.util.Scanner;

class FleetWeight
{
public static void main(String[]args)
{
double weight;
Scanner stdio = new Scanner(System.in);
System.out.println("Please enter your vehicle weight in lbs."wink;
weight = stdio.nextDouble();

if(weight<=6000l)
{
System.out.println("Your vehicle is class 1 GVWR or VIUS light duty."wink;
if(weight>=6001 && weight<=10000)
{
System.out.println("Your vehicle is class2 GVWR or VIUS Light Duty."wink;
}

}else if(weight>=10001 && weight<=14000 )
{
System.out.println("Your Vehicle is class3 GVWR or VIUS Medium Duty."wink;
}

else if(weight>=14001 && weight<=16000)
{
System.out.println("Your vehicle is class4 GVWR or VIUS Medium Duty"wink;

}

else if(weight>=16001 && weight<=19500)
{
System.out.println("Your vehicle is class5 GVWR Medium Duty"wink;
}

else if(weight>=19501 && weight<=26000)
{

System.out.println("your vehicle is class6 GVWR Medium Duty"wink;
}


else if(weight>=26001 && weight<=33000)
{

System.out.println("Your Vehicle is class7 GVWR or VIUS Heavy Duty"wink;
}

else if(weight>=33001)
{
System.out.println("Your vehicle is class8 GVWR && VIUS heavy duty"wink;
}



}
}


I am sorry for inconviniencing you, I hope to receive some tips advice and corrections that could improve the code. Thanking you in advance.
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 9:03am On Apr 17, 2016
Fulaman198:
This assignment must be tough for you guys. No one has turned it in yet.


I did some googling and discovered that the if-else and else-if control statement can be used for range of values as well as single values. For example, 1-99.99,100-199.99 and so on. On the other hand, according to the tutorial I have gotten from the result of the search I did, the SWITCH control statement can only be use for a definite values, hence can't be use for range of values. Now I am thinking of how to control the flow of execution using the switch in number range of such a large range. Imagine me using switch statement for a range as large as 6001-10000lbs, when it can't not be used for range of values. How possible is that? Anyway, you gave us option of using either Switch or if-if-else-else-if, with you preferring us using the switch. So, I will turn my assignment in using the if-if-else-else-if statement and hope you show us a way to use the switch statement on very large range of values.
This is my dilemma.


import java.util.Scanner;

class SwitchScore

{

public static void main(String[]args)

{
int scores;
Scanner stdio = new Scanner(System.in);

System.out.println("Please, enter your score here"wink;

scores = stdio.nextInt();



switch(scores)
{
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
case 98:
case 99:
case 100: System.out.println("You got an A"wink;
break;

case 60:
case 61:
case 62:
case 63:
case 64:
case 65:
case 66:
case 67:
case 68:
case 69: System.out.println("You got a B"wink;
break;

case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 59: System.out.println("You got C"wink;
break;

default: System.out.println("We don't give lower than C grade"wink;
break;
}



}


}
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 12:43pm On Apr 15, 2016
asalimpo:

if the op doesnt mind or his student ...

That statement creates a package - a group of related classes grouped together as a unit.
the package can be imported for use in other programs , facilitating code-reuse and avoiding name collision conflicts.
e.g if you have a class with the same name as a native class, you can differentiate yours and avoid confusing the compiler by placing yours in a package.

When compiled, a folder is created in the order of the package name. subfolders appear according to their
dot separation in the package name.
e.g
for the class SwitchUsage
in package
com.fullermannairalandtutorial
the following folder structure will be created com/fullermannairalandtutorials
with the class SwitchUsage in the last folder , fullermannairalandtutorials .


to use this class in other programs, you use the import statement.

like this:
import com.fullermantutorials.SwitchUsage -

if you are importing more classes but dont want to specify every class by name u , use the wildcard character:
e.g
you'll often see codes like this:
import java.util.*
That statement imports all the classes in the java.util package.

by convention , package names are specified in lowercase letters.
classes, in uppercase.
You can't create a package that begins with java - that name is reserved to avoid confusion and clashes with the pre-built java packages.

Just like the vigilante in the seasonal film "Arrow" you always come to the rescue. Thanks Oga asalimpo.
Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 12:41pm On Apr 15, 2016
Fulaman198:
Day 4 Assignment:

Read the following documentation in order to supplement what you have learned today from this tutorial:

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Your assignments are as follows:

1. Write a Programme that takes the grade programme that was posted earlier today and transform it using the Switch statement. The resulting output should be the same as with the if, else if and else statements

2. Write a programme that asks the user to enter the weight of a vehicle in kg. 2.2 lbs = 1 kg in case you don't know. Based on the table below, write your programme. You can use either a Switch statement or an if statement. That's up to you, but personally for this problem I would use a Switch statement.

This one strong o! See as I just dey sweat on top the assignment and still I am not making any headway. I have been having this illegal-start-of-an-expression error on my compiler. Hmm could it be that our teacher is trying to drive home some points about the difference in using the switch and the if-else-ifelse? Who don succeed make e come give me expo na. Or are we allowed to used google to helep solve this issue, our teacher Fulaman198?

1 Like

Programming / Re: Learning To Program With Java by the Fulaman by satmaniac(m): 10:51am On Apr 15, 2016
Fulaman198:
Alternatively, there is another way to write this programme. The alternative method to writing it is with a switch statement. The switch statement is another way to test conditional statements. The Switch statement works with byte, short, char and int primitive types. it also works with enum types which we will get to later, the String class and other classes capable of wrapping primitive types.

Let's say for instance that I would like to check the number of the month and correlate it to the proper month, how would I do that with a Switch statement? Very simply put like so:


package com.fulamannairalandtutorials;
import java.util.Scanner; //import a scanner object

public class SwitchUsage {
public static void main(String[] args) {
Scanner stdio = new Scanner(System.in );
int theMonth;

System.out.println("Please enter a numerical value for month" );
theMonth = stdio.nextInt();

switch(theMonth) {
case 1: System.out.println("The Month is January." );
break;

case 2: System.out.println("The Month is February." );
break;

case 3: System.out.println("The Month is March." );
break;

case 4: System.out.println("The Month is April." );
break;

case 5: System.out.println("The Month is May." );
break;

case 6: System.out.println("The Month is June." );
break;

case 7: System.out.println("The Month is July." );
break;

case 8: System.out.println("The Month is August." );
break;

case 9: System.out.println("The Month is Septembre." );
break;

case 10: System.out.println("The Month is Octobre." );
break;

case 11: System.out.println("The Month is Novembre." );
break;

case 12: System.out.println("The Month is Decembre." );
break;

default: System.out.println("You did not enter a valid number" );
break;
}

}
}


Care to explain the line of code in blue, up above?

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (of 12 pages)

(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. 149
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.