Methods and File Output and Exceptions
Outcome:
Program Specifications:
You to write a menu driven program. The program will use a switch statement. The cases will be as follows:
Submission Requirements:
YOU CANNOT:
Code:
//Menu.java
import java.util.Scanner;
public class Menu {
public static void main(String[] args) {
/*
* Creating an Scanner class object which is used to get the
inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
int choice;
do
{
System.out.println("\n::MENU::");
System.out.println("1.Echo Name");
System.out.println("2.Double Your Age");
System.out.println("3.Check Teenager or not");
System.out.println("4.Display Triangle");
System.out.println("5.Exit");
System.out.print("Enter Choice:");
choice = sc.nextInt();
switch (choice) {
case 1: {
System.out.print("Enter your name");
String name=sc.nextLine();
for(int i=1;i<=20;i++)
{
System.out.println(name);
}
break;
}
case 2: {
int age;
System.out.print("Enter age :");
age=sc.nextInt();
System.out.println("Your age :"+age);
System.out.println("Doubled age :"+(2*age));
break;
}
case 3: {
int age;
System.out.print("Enter age :");
age=sc.nextInt();
if(age>=13 && age<=19)
{
System.out.println("Since you are "+age+" years old.Your are a
Teenager");
}
else
{
System.out.println("Since you are "+age+" years old.Your are not a
Teenager");
}
break;
}
case 4: {
int rows;
do
{
System.out.print("Enter a number (between 3 and 50):");
rows=sc.nextInt();
if(rows<3 || rows>50)
{
System.out.println("** Invalid.Must be between 3 and 50 **");
}
}while(rows<3 || rows>50);
printTriangle(rows);
break;
}
case 5:{
break;
}
default: {
System.out.println("** Invalid Choice **");
break;
}
}
}while(choice!=5);
}
private static void printTriangle(int size) {
char ch='*';
for (int a = 0; a < 2 * size - 1; a++) {
if (a % 2 == 0) {
for (int b = 0; b < (2 * size - 1) - a; b++) {
System.out.print(" ");
}
for (int c = 0; c <= a; c++) {
System.out.print(ch+" ");
}
System.out.println();
}
}
}
}
___________________________
Output:
::MENU::
1.Echo Name
2.Double Your Age
3.Check Teenager or not
4.Display Triangle
5.Exit
Enter Choice:1
Enter your name:Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
Williams
::MENU::
1.Echo Name
2.Double Your Age
3.Check Teenager or not
4.Display Triangle
5.Exit
Enter Choice:2
Enter age :23
Your age :23
Doubled age :46
::MENU::
1.Echo Name
2.Double Your Age
3.Check Teenager or not
4.Display Triangle
5.Exit
Enter Choice:3
Enter age :16
Since you are 16 years old.Your are a Teenager
::MENU::
1.Echo Name
2.Double Your Age
3.Check Teenager or not
4.Display Triangle
5.Exit
Enter Choice:4
Enter a number (between 3 and 50):6
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
::MENU::
1.Echo Name
2.Double Your Age
3.Check Teenager or not
4.Display Triangle
5.Exit
Enter Choice:5
##Please like rate to my answer ,very helpful for me
Methods and File Output and Exceptions Outcome: Student will demonstrate the ability to write, use and...
thats the third time i ask for this questions and it comes out wrong do it on eclipse.... make sure it runs Outcome: Student will demonstrate the ability to write, use and call methods Student will demonstrate the ability to pass values to and from methods Student will demonstrate the ability to catch exceptions Student will demonstrate the ability to create a text file Student will demonstrate the ability to validate input data Program Specifications:...
Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...
* C PROGRAMMING* Outcomes: Demonstrate the ability to create and use linked lists in dynamic memory Demonstrate the ability to add nodes and remove nodes from a linked list of structs Program Specifications: Write a program that creates the following struct (you can give it whatever name you want): char name[100]; int age; float weight; Create the following menu system: Add a Record Display All Records Quit When the user selects (1) you will prompt them for a name, age,...
***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability to create an array on the heap allowing user to choose the number of values to store. Demonstrate the ability to store an array of Struct values on both the stack and the heap. Program Specifications: 1. Create a struct with at least 3 fields - any struct you want but explain it in your comments in the code. Populate at least 10 elements...
The following needs to be in C programming ! Outcomes: Demonstrate the ability to design a menu driven program. Demonstrate the ability to reuse previous code to create a new assignment. Demonstrate the ability to use appropriate program logic. Program Specifications: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program...
Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...
Java Exceptions Suppose a library is processing an input file containing the titles of books in order to remove duplicates. Write a program that reads all of the titles from an input file called bookTitles.inp and writes them to an output file called uniqueTitles.out. When complete, the output file should contain all unique titles found in the input file. Create the input file using Notepad or another text editor, with one title per line. Make sure you have a number...
(Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...
Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...
: Files and Exceptions: Write a program to create and use a grade book for a course. The gradebook is created as a file named as “Course_Name.dat” and includes the following information about students: Student ID, First Name, Last Name, and Grade. Assume the following structure for the gradebook file:1.Students’ records are separated by a new-line character.2.No field includes any white-space character, and fields are separated by space.3.The order of the fields is the same for all the records.Based on...