Hello i'm having a problem with a program. Let me tell you first what program should do.
The program should allow the tutor to enter in the various marks which the students have been awarded, until the tutor enters in a mark exceeding 100. At this point the program should display a histogram. Each star represents a student who achieved a module mark in the range shown.
0-29 *** (3 students received a mark between 0-29)
30-39 *****
40-69 ********
70-100 ****
20 students in total.
As the tutor enters each mark, a counter should count the number of student’s marks which have been entered.
Use the same 4 category ranges shown here.
Make sure the display is neatly formatted as above.
this is the problem to be solved.
package cw23rdattempt;
import java.util.Scanner;
/**
*
* @author Boss
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int counter = 1;
int marks = 0;
while( counter <= 20)
{
Scanner input = new Scanner(System.in);
System.out.println("enter student marks");
marks = input.nextInt();
if(marks <=29)
{
System.out.println("0-29 *");
}
if(marks >= 30 && marks <=39)
{
System.out.println("30-39 *");
}
if(marks >= 40 && marks <=69)
{
System.out.println("40-69 *");
}
if(marks >= 70 && marks <=100)
{
System.out.println("70-100 *");
}
if(marks >100)
{
System.out.println("invalid mark \nmarks can not exceed 100");
}
counter++;
}//end while
}//end class
}//end main
it sort of works, but it print answer separately for every entry, and i want to print it in the format as above in description.
could you please help me out?. ps i'm very new to programing so dont get harsh on me ;p