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...
USING THE IF STATEMENT & Scanner for input and println for output - Write a java...
USING THE IF STATEMENT & Scanner for input and println for output - Write a java program where the user enters a temperature as a whole number from input, and outputs a “most likely” season [either SUMMER, SPRING, FALL or WINTER] depending on the temperature entered. SUMMER would be 90 or higher SPRING   would be 70 to less than 90 FALL       would be 50 to less than 70 WINTER would be less than 50 Consider it an error if the...
Java Programming import java.io.File; import java.util.LinkedHashMap; import java.util.Scanner; import javax.swing.JFrame; import org.math.plot.Plot2DPanel; import java.awt.Container; import java.awt.BorderLayout;...
Java Programming import java.io.File; import java.util.LinkedHashMap; import java.util.Scanner; import javax.swing.JFrame; import org.math.plot.Plot2DPanel; import java.awt.Container; import java.awt.BorderLayout; public class Heart {     public static LinkedHashMap<String,double[]> readData(final Scanner fsc) {         final LinkedHashMap<String, double[]> result = new LinkedHashMap<String, double[]>();         fsc.nextLine();         String State;         String line;         String[] parts;         double[] values;         while (fsc.hasNextLine()) {             line = fsc.nextLine();             parts = line.split("\t");             State = parts[0];             values = new double[parts.length - 1];             for (int i = 1; i < parts.length; i++) {                 values[i - 1] = Double.parseDouble(parts[i]);             }                          result.put(State,...
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...
Java Starter Code: import java.util.Scanner; public class GameScore { static Scanner keyboard = new Scanner(System.in); public...
Java Starter Code: import java.util.Scanner; public class GameScore { static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int team1[] = new int[4]; int team2[] = new int[4]; for (int qtr = 0; qtr < 4; qtr++) { quarterScoring(team1, team2, qtr); } int team1Total = teamTotal(team1); int team2Total = teamTotal(team2); displayGameResults(team1, team2); if (team1Total > team2Total) { System.out.println("Team 1 has won the game!"); } else { System.out.println("Team 2 has won the game!"); } } static int teamTotal(int[]...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in);...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { // TODO code application logic here System.out.print("Enter any String: "); String str = br.readLine(); System.out.print("\nEnter the Key: "); int key = sc.nextInt(); String encrypted = encrypt(str, key); System.out.println("\nEncrypted String is: " +encrypted); String decrypted = decrypt(encrypted, key); System.out.println("\nDecrypted String is: " +decrypted); System.out.println("\n"); } public static String encrypt(String str,...
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...
// TASK #2 Add an import statement for the Scanner class // TASK #2(Alternate) // Add...
// TASK #2 Add an import statement for the Scanner class // TASK #2(Alternate) // Add an import statement for the JOptionPane class /** This program demonstrates how numeric types and operators behave in Java. */ public class NumericTypes { public static void main (String [] args) { // TASK #2 Create a Scanner object here // (not used for alternate) // Identifier declarations final int NUMBER = 2 ; // Number of scores final int SCORE1 = 100; //...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT