Preview

Bluej Menu Driven Program

Good Essays
Open Document
Open Document
1040 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Bluej Menu Driven Program
Menu Driven BlueJ Program on Odd, Even and Perfect Numbers

The question here is that, Write a BlueJ program which will ask the user to enter a choice and based on the choice the following operation will take place. if choice=1; then sum of even nos. from the series of 10 nos. if choice=2; then sum of odd nos. from a series of 10 nos. if choice=3; then it will check whether the no is perfect or not from a series of 10 nos.

Codes of the Menu driven BlueJ Program

import java.io.*; class Menu
{
BufferedReader br; int arr[]=new int[10]; public static void main(String args[])throws IOException { Menu ob=new Menu (); ob.accept(); } Menu () { br=new BufferedReader(new InputStreamReader(System.in)); } public void accept()throws IOException
{
int choice; for(int i=0;i<10;i++)
{
System.out.println("Enter number:"); arr[i]=Integer.parseInt(br.readLine().trim());
}
System.out.println("Enter Your Choice (1 for adding even numbers, 2 for adding odd number and 3 for checking perfect number:"); choice=Integer.parseInt(br.readLine().trim()); if(choice==1) addEven(); else if(choice==2) addOdd(); else if(choice==3) showPerfect(); else
System.out.println("Wrong Choice:");
}
private void addEven()
{
int sum=0; for(int i=0;i<10;i++) { if(arr[i]%2==0) sum=sum+arr[i]; } System.out.println("Sum of Even Numbers="+sum);
}

private void addOdd()
{
int sum=0; for(int i=0;i< 10;i++) { if(arr[i]%2!=0) sum=sum+arr[i]; } System.out.println("Sum of Odd Numbers="+sum);
}
private void showPerfect()
{
int sum; for(int i=0;i<10;i++) { sum=0; for(int j=1;j< arr[i];j++) { if(arr[i]%j==0) sum=sum+j; } if(sum==arr[i]) System.out.println(arr[i]+ " is a Prefect Number");
}
}
}

Sample input and output of the BlueJ program

Enter number:
22
Enter number:
4
Enter number:
35
Enter number:
4
Enter number:

You May Also Find These Documents Helpful

  • Powerful Essays

    4. The calculation should be executed only after all the valid input values are provided.…

    • 1488 Words
    • 6 Pages
    Powerful Essays
  • Satisfactory Essays

    cout << "You are in factorial program of C++. Please enter a +ve integer:- ";…

    • 426 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    It/210 Final Exam

    • 1235 Words
    • 5 Pages

    4. The calculation should be executed only after all the valid input values are provided.…

    • 1235 Words
    • 5 Pages
    Good Essays
  • Powerful Essays

    System.out.println("i = " + i + " f = " + f + " d = " + d);…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    2.Write a program to (a) display a “?” (b) read two decimal digits whose sum less than 10 (c) display them and their sum on the next line. Page: 80…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Nt1310 Unit 3 Assignment

    • 256 Words
    • 2 Pages

    Write a program to input a string and then display it in Upper Case and also print the frequency of any character from the string.…

    • 256 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    As the user is deciding which they would like to select an international currency type. When the user enters a number between 5 and 26 corresponding with a currency type, then the program is set to false. If 26 is selected the program displays “Quitting Currency Conversion.” But if the user does not enter a number between 5 and 26 the program displays “Error 4: Invalid Menu Selection” and the set it true.…

    • 1052 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Week 9 Eng 101 Checkpoint

    • 326 Words
    • 2 Pages

    Enter the correct answer for each item by typing either a or b in the second column. Provide an explanation for each choice in the Rationale column. The boxes expand to accommodate your text.…

    • 326 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Mis 302 Flowchart

    • 262 Words
    • 2 Pages

    Complete Java Program to accept the required input and accordingly produce the output as expected.…

    • 262 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    math 239 assignment 1

    • 1831 Words
    • 8 Pages

    I; in (3), 8 is the number of remaining letters to be selected after choosing the letters M, I, and 4 is the…

    • 1831 Words
    • 8 Pages
    Good Essays
  • Good Essays

    a) The first test should determine if the shipping option in cell B15 is blank, and if so, then cell C17 should be blank.…

    • 724 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    This Is a Paper

    • 469 Words
    • 2 Pages

    * The design is not robust as there are no statements for error handling and handling exceptions. To make this code more robust I would add error handling statements like the user can only enter numbers that are between 0 and 100. Also the user cannot enter any strings like winding and other data types, for other numbers and data types the system will display "invalid input. Please enter a number between 0 and 100." Also notice that it doesn't handle the case of entering 49. You need <= 49, as it is now, when you enter 49 all it will say is "how did u do?" same thing with entering 100 and for anything over 100.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Macro Examples

    • 1120 Words
    • 5 Pages

    7. The If…Then…Else…End If code allows code to be conditionally executed depending on whether a specified logical condition has been met.…

    • 1120 Words
    • 5 Pages
    Good Essays
  • Good Essays

    POW Free Think Football

    • 531 Words
    • 3 Pages

    After I did that I had to come up with four other scoring systems. So the first scoring system that I came up with was 4 and 8. I wanted to see how the results of two even numbers would come out. So I used the same method as I did before and I also created a table.…

    • 531 Words
    • 3 Pages
    Good Essays
  • Best Essays

    MSc Clinical Leadership

    • 5046 Words
    • 16 Pages

    Bnet (2008) How to Implement a Decision. [online]. Available at: http://jobfunctions.bnet.com/abstract.aspx?docid=359455 [Accessed 7 January 2010].…

    • 5046 Words
    • 16 Pages
    Best Essays