₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,134 members, 8,420,503 topics. Date: Thursday, 04 June 2026 at 10:27 PM

Toggle theme

Java Programming Problem - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingJava Programming Problem (1095 Views)

1 Reply (Go Down)

Java Programming Problem by Nobody: 11:13pm On Aug 27, 2014
Hello fellow nairalnder. I'v developed interest in programming language and started with Java programming language. I bought this text book titled "Java How to Programm" do not know if any one here have access to the book. While studing i encountered a task on chapter six of the textbook. the problem i have with the textbook is this:
i am suppose to calculate the percentage score after a pupil has entered the answer to the r10 andom questions displayed. if the pupil score is greater than 75%, the program should congralutes the pupil and reset itself for the next user else display a message that refers tthe pupil to their instructor.

The challenge i'm having is that each time an answered is entered the messages refering the people to the instructor is always displayed.
Bellow is the source code. I will appreciate any assistance. Thanks.
package COMPUTER_ASSISTED_INSTRUCTION;


import java.util.Scanner;
import java.util.Random;

//class Declaration
public class COMPUTER_ASSISTED_INSTRUCTION
{
private static final Random randomNumbers = new Random();// radom number generator
private static final Scanner input = new Scanner (System.in);// class Scanner to accept user's input

// TODO code application logic here
public static void main(String[] args)
{
for(int count = 1; count <=10; count++)//starts for loop
{
int product = randomvalue();

}//ends for loop
}//ends maain class

public static int randomvalue()

{
//pick random values
int Num1 = 1 + randomNumbers.nextInt(9);//first numbner generator
int Num2 = 1 + randomNumbers.nextInt(9);//Second number generator
int totalScore = 0;
double percentageScore ;
int product = Num1 * Num2; // initialize sum product of first and second number

//prompt statement
System.out.printf("How much is %d times %d:\n",Num1,Num2);
// assign users answer to variable product
product = input.nextInt();
if (product == Num1 * Num2)
{
totalScore = 1 + totalScore
int responce = 1 + randomNumbers.nextInt(4);
switch (responce)
{
case 1:
System.out.println("Very Good!"wink;
break;
case 2:
System.out.println("Excellent!"wink;
break;

case 3:
System.out.println("Nice Work!"wink;
break;

case 4:
System.out.println("Keep up the Good work!"wink;
break;
}
}
else
{
totalScore = 0 + totalScore;
int responce = 1 + randomNumbers.nextInt(4);
switch (responce)
{
case 1:
System.out.println("Answer not correct. Please try again!"wink;
break;
case 2:
System.out.println("Wrong answer. Try once more!"wink;
break;
case 3:
System.out.println("Incorrect answer. Don't give up!"wink;
break;
case 4:
System.out.println("Nooo. Keep trying!"wink;
break;
}
}
percentageScore = (totalScore / 10.0) * 100;

if (percentageScore < 75)
{
System.out.println("You need to ask your teacher for more help"wink;
}
else
System.out.println("Congratulation, you are ready to go to the next level"wink;
return product;
}
//end of class declaration
}
Re: Java Programming Problem by Javanian: 4:00am On Aug 28, 2014
http://pastebin.com/xpYfrdDk

Compare and Contrast this code with yours. It should work now.

Take note of the changes i made including indentation. It is always cool to indent your code. smiley

On a side not, There is no need to give your Package name and Class name the same name and also no need to write them in upper case letters.

Nice job by the way.
Re: Java Programming Problem by opezyhick: 2:10pm On Aug 28, 2014
Explain this aim of the java programm
Re: Java Programming Problem by Nobody: 3:02am On Aug 31, 2014
Javanian: http://pastebin.com/xpYfrdDk

Compare and Contrast this code with yours. It should work now.

Take note of the changes i made including indentation. It is always cool to indent your code. smiley

On a side not, There is no need to give your Package name and Class name the same name and also no need to write them in upper case letters.

Nice job by the way.
I am sure there is an explanation for the count++ at the end of your for loop. I didn't run your code, but I think its unnecessary. You'll have <10 iterations. Also, there is no need to calculate percentage in the iteration..
Re: Java Programming Problem by Javanian: 3:16am On Aug 31, 2014
olukenzo: I am sure there is an explanation for the count++ at the end of your for loop. I didn't run your code, but I think its unnecessary. You'll have <10 iterations. Also, there is no need to calculate percentage in the iteration..
Did you read the o.p's post and code before making this comment?
Re: Java Programming Problem by Nobody: 3:38am On Aug 31, 2014
i am suppose to calculate the percentage score after a pupil has entered the answer to the r10 andom [10 random] questions displayed.
Javanian: Did you read the o.p's post and code before making this comment?
You had:

for (count=1; count<=10; count++){
If(foo){}
else{}
count++;
percentage = ( total/10) * 100;
}
Re: Java Programming Problem by Intellab(m): 9:29am On Sep 01, 2014
I think the error is from your looping.
Make the program look attracted by using JOptionPane Library.
-> import javax.swing.JOptionPane;
1 Reply

Is Java Programming Harder Than Microsoft.net ProgrammingJava Programming Vs Networking: Which Is More Profitable In Nigeria?Java Programming For Dummies234

Google Adsense, Needed Adsense Account To Buy Us Or Naija Verified AccountAll Expert & Newbies In Programming Come Here Please!!Creating An Android And Ios Mobile App