Sort

Ads
 

Sort

Hi i would really be thankful if someone could help me with this

A program is required to ask users to rate the Java programming language using a number in the range 0 - 10.

The data input is ended by entering -1.

After all the votes have been counted, the program should output a table showing how many people gave each rating and the average rating.

import java.util.*;

class RateJava {

public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Rate Java(0-10): "); int rate = input.nextInt(); while (rate > 10 || rate < 0) {

catch(

private static class IOException {

public IOException() {
}

} ArithmeticException e

);
{
    System.out.println("Cannot calculate average - no data");

catch(IOException

);


{
    System.out.println("Error reading from file");

} } }

}
System.out.print("Invalid! Rate Java within the range(0-10): ");
    rate=input.nextInt();





System.out.println("You have rated Java: "+rate);
View Answers

December 9, 2011 at 4:56 PM

import java.util.*;
class RateJava 
{
    public static void main(String[] args) 
    {
        int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0,c10=0,c11=0;
        Scanner input=new Scanner(System.in);
        int rate=0;
        do{
        System.out.print("Rate Java(0-10): ");
        rate=input.nextInt();
            if(rate>10||rate<-1){
                System.out.print("Invalid! Rate Java within(0-10): ");
                rate=input.nextInt();
            }
            if(rate==0){
                c1++;
            }
            if(rate==1){
                c2++;
            }
            if(rate==2){
                c3++;
            }
            if(rate==3){
                c4++;
            }
            if(rate==4){
                c5++;
            }
            if(rate==5){
                c6++;
            }
            if(rate==6){
                c7++;
            }
            if(rate==7){
                c8++;
            }
            if(rate==8){
                c9++;
            }
            if(rate==9){
                c10++;
            }
            if(rate==10){
                c11++;
            }
            if(rate==11){
                c1++;
            }           
        }
            while(rate!=-1);
        System.out.println();
        System.out.println("*****RATINGS*****");
        System.out.println("Number of users rated Java 0: "+c1);
        System.out.println("Number of users rated Java 1: "+c2);
        System.out.println("Number of users rated Java 2: "+c3);
        System.out.println("Number of users rated Java 3: "+c4);
        System.out.println("Number of users rated Java 4: "+c5);
        System.out.println("Number of users rated Java 5: "+c6);
        System.out.println("Number of users rated Java 6: "+c7);
        System.out.println("Number of users rated Java 7: "+c8);
        System.out.println("Number of users rated Java 8: "+c9);
        System.out.println("Number of users rated Java 9: "+c10);
        System.out.println("Number of users rated Java 10: "+c11);
    }
}

Ads









Related Tutorials/Questions & Answers:
insertion sort
insertion sort  write a program in java using insertion sort
bubble sort
bubble sort  write a program in java using bubble sort
Advertisements
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  write a program in java using insertion sort
insertion sort
insertion sort  how many arrays needed for insertion sort and why
bubble sort
bubble sort  how to calculate the number of passes in bubble sort
buble sort
buble sort  ascending order by using Bubble sort programm   Java BubbleSort Example
SEARCH AND SORT
SEARCH AND SORT  Cam any one provide me the code in java that : Program to search for MAX,MIN and then SORT the set using any of the Divide and conquer method
Sort
quick sort
; System.out.println(" Quick Sort\n\n"); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++){ array[i...("Values after the sort:\n"); for(i = 0; i <array.length; i
quick sort
; System.out.println(" Quick Sort\n\n"); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++){ array[i...("Values after the sort:\n"); for(i = 0; i <array.length; i
quick sort
; System.out.println(" Quick Sort\n\n"); System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++){ array[i...("Values after the sort:\n"); for(i = 0; i <array.length; i
Insertion Sort Applet
Insertion Sort Applet  Please All , I need Insertion sort applet program
Insertion Sort Applet
Insertion Sort Applet  I need Insertion Sort Applet code was design by Dr. Daniel Liang Please
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
ModuleNotFoundError: No module named 'sort'
ModuleNotFoundError: No module named 'sort'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'sort' How to remove the ModuleNotFoundError: No module named 'sort' error
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
visualization Max-Heap-sort
visualization Max-Heap-sort  To Whom It May Concern, Would you please give the source code of applet Max-heap sort? I want to see the visualization of Max-Heap sort. Best Regards, saeideh
Insertion Sort Timer
Insertion Sort Timer  Welcome all I wanna program in java find the timer of insertion sort and find time complexity for random value thanks all
Help With Costructing Selection sort?
Help With Costructing Selection sort?  Using a selection sort, for each entry in the array, display the original index of the first dimension... in advance!   Please visit the following link: Java Selection Sort
Java insertion sort question
Java insertion sort question  I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertion sort algorithm. Then I need to write
Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort, insertion sort, bubble sort and other sorting methods, heap sort is used to sort an unsorted list. When compared to other sorting methods heap sort
Java Dictionary-Sort,Extract
Java Dictionary-Sort,Extract  *I need to make an English(other language) dictionary by collecting english/other language words in a text file;then using that text file I need to sort the words collected in alphabetical order
Merge Sort Java
Merge Sort in Java is used to sort integer values of an array. There are many methods to sort Java like bubble sort, insertion sort, selection sort, etc. In Merge sort unsorted values are divided into two equal parts
Version of com.htyleo>external-sort dependency
List of Version of com.htyleo>external-sort dependency
search and sort techniques in java
search and sort techniques in java  Hi i attened an interview recently... they asked to write all searching and sorting technique codes in java.. i said i would use collection frame work for it.. but they dosnt want me to use

Ads