Question

In: Computer Science

This for Java Programming Write a java statement to import the java utilities. Create a Scanner...

This for Java Programming

  1. Write a java statement to import the java utilities.
  2. Create a Scanner object to read input.
  3. int Age;

    Write a java statement to read the Age input value

4 . Redo 1 to 3 using JOptionPane

Solutions

Expert Solution

Here is the Java code for the given question.

Code for 1,2,3:

import java.util.*;    /* (1) Imports Java utilities */

public class ReadAge {

    public static void main(String[] args){

        Scanner scanner=new Scanner(System.in);    /* (2) Creates a Scanner object to read input */

        int Age;

        Age=scanner.nextInt();     /* (3) Statement to read Age input value */
    }
}

Output:

According to the question, the program produces no output ,but input is taken as follows:

Code for 4:

import javax.swing.*;   /* (1) imports java swing*/

public class ReadAgeJOptionPane {

    public static void main(String[] args){

        int Age;   /*used to store Age*/

        JOptionPane optionPane=new JOptionPane();    /* (2)creates a new JOptionPane object*/

        Age= Integer.parseInt(optionPane.showInputDialog("Enter Age:"));      /* (3)statement to read Age input value*/

    }
}

Output:

According to the question, the program produces no output ,but input is taken as follows:


Related Solutions

Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
JAVA program Create a class called Array Outside of the class, import the Scanner library Outside...
JAVA program Create a class called Array Outside of the class, import the Scanner library Outside of main declare two static final variables and integer for number of days in the week and a double for the revenue per pizza (which is $8.50). Create a method called main Inside main: Declare an integer array that can hold the number of pizzas purchased each day for one week. Declare two additional variables one to hold the total sum of pizzas sold...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the computer user to enter his/her: • Name: a string representing the user’s first name • month of birthday: an integer representing the month of the user’s birthday • day of birthday: an integer representing the day of the user’s birthday • year of birthday: an integer representing the year of the user’s birthday Consider the following aspects that your program shall perform: VALIDATE USER’S...
7) Create the following using Java. Create a scanner Declare double variables for price and tax...
7) Create the following using Java. Create a scanner Declare double variables for price and tax Declare character variable reply Create do while loop Inside of do loop Prompt the console to display headline Product Price Check Prompt the user to enter initial price and relate to scanner Prompt the user to enter the tax rate and relate to scanner Calculate price which is equal to price multiply (1+tax/100) Display in console the cost after tax which is price Check...
Multithreaded programming Write a multithreaded program (JAVA) that prints messages with thread IDs. 1. Create at...
Multithreaded programming Write a multithreaded program (JAVA) that prints messages with thread IDs. 1. Create at least three user-threads. 2. Each thread needs to be terminated after printing each thread ID.
Create a Java method findLongestPalindrome that takes a Scanner scn as its parameter and returns a...
Create a Java method findLongestPalindrome that takes a Scanner scn as its parameter and returns a String. It returns the longest token from scn that is a palindrome (if one exists) or the empty string (otherwise). (Implementation note: Use the built in isPalindrome method. This method calls for an optimization loop.) Where the isPalindrome Method takes a String s as a parameter and returns a boolean. It returns true if s reads the same forwards and backwards, i.e., is a...
Write a program in Java with a Scanner. Given an array and a number k where...
Write a program in Java with a Scanner. Given an array and a number k where k is smaller than the size of the array, write a program to find the k'th smallest element in the given array. It is given that all array elements are distinct. Example: Input: arr[] = {7,10,4,3,20,15} k = 3 Output: 7
JAVA PROGRAMMING 1)BuildLists: Write a program to create an ArrayList<Integer>. Fill it with numbers from 1...
JAVA PROGRAMMING 1)BuildLists: Write a program to create an ArrayList<Integer>. Fill it with numbers from 1 to 1000. Then remove every even number. Then remove every multiple of 3 remaining Then remove every multiple of 5 Then remove every multiple of 7 Then sum the array, and print.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT