Question

In: Computer Science

Part A Java netbeans ☑ Create a project and in it a class with a main....

Part A

Java netbeans


☑ Create a project and in it a class with a main.

We will be using the Scanner class to read from the user. At the top of your main class , after the package statement, paste

import java.util.Scanner;

As the first line inside your main method, paste

Scanner scan = new Scanner(System.in);

Remember when you are getting a value from the user, first print a request, then use the Scanner to read the right type from the user and put it in a variable of that type.

In the main, do the following:

(You can use if, if-else, nesting, or boolean operators. You may not use special math methods, just relational and algebraic operators.)

☑ Get an int n from the user and print "high" "middle" or "low" depending on whether n is above 75, between 25 and 75, or below 25, but if it is exactly 75 or 25 print "hard to say"

☑ Ask the user their favorite animal and get a String as their answer. For five possible values ("cat" "dog" "capybara" etc... your choice) if the user said that animal, print a specialized comment about it (e.g. if they said "cat" you might print "oh, purr!"). If they said none of the types your program covers, instead print a general comment for all other types of animal.

☑ At a certain amusement park, children under 5 get in for $4, children up to (inclusive) 12 get in for $10, teens up to 19 get in for $12, adults up to 59 for $15, seniors up to 79 for $10, and seniors 80 and over for $5. In your main, ask the user for their age. Create a a single compound if-else statement that goes through all the possibilities for admission price above and prints out the appropriate price, given the user's age.

[EC+10] read in an x from the user and print "even" if x is even and "odd" otherwise. You do not need any special math methods to do this.

Solutions

Expert Solution

//create class NestedIF.java and paste the code given below


import java.util.Scanner;

public class NestedIF {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
/*Get an int n from the user and print "high" "middle" or "low" depending on
*whether n is above 75, between 25 and 75, or below 25,
*but if it is exactly 75 or 25 print "hard to say"
*/
  
System.out.print("Enter number n:");
int number = scan.nextInt();
if (number > 75) {
System.out.println("high");
} else if (number > 25 && number < 75) {
System.out.println("middle");
} else if (number < 25) {
System.out.println("low");
}else if(number==75 || number==25)
{
System.out.println("hard to say");
}
  
/*Ask the user their favorite animal and get a String as their answer.
For five possible values ("cat" "dog" "capybara" etc... your choice) if the
user said that animal, print a specialized comment about it (e.g. if they said "cat"
you might print "oh, purr!"). If they said none of the types your program covers,
instead print a general comment for all other types of animal.*/
System.out.print("Enter Animal Name:");
String animal=scan.next();
if(animal.equalsIgnoreCase("cat"))
{
System.out.println("oh, purr!");
}else if(animal.equalsIgnoreCase("dog"))
{
System.out.println("Oh, Bark!");
}else if(animal.equalsIgnoreCase("capybara"))
{
System.out.println("Oh, Bark!");
}else if(animal.equalsIgnoreCase("lion"))
{
System.out.println("Oh, Roar!");
}else if(animal.equalsIgnoreCase("monkey"))
{
System.out.println("Oh,scream");
}else
{
System.out.println("Oh, General Animal");
}
  
  
/*
At a certain amusement park, children under 5 get in for $4,
children up to (inclusive) 12 get in for $10, teens up to 19 get in
for $12, adults up to 59 for $15, seniors up to 79 for $10, and seniors 80
and over for $5. In your main, ask the user for their age. Create a a single
compound if-else statement that goes through all the possibilities for admission price
above and prints out the appropriate price, given the user's age.
  
*/
System.out.print("Enter Your age:");
int age=scan.nextInt();
if(age<5)
{
System.out.println("Admission price :$4");//under 5
}else if(age<=12)
{
System.out.println("Admission price :$10");// children up to (inclusive) 12 get in for $10
}else if(age<19)
{
System.out.println("Admission price :$12");//teens up to 19 get in for $12   
}else if(age<59)
{
System.out.println("Admission price :$15");//adults up to 59 for $15
}else if(age<79)
{
System.out.println("Admission price :$10");//seniors up to 79 for $10,
}else
{
System.out.println("Admission price :$5");//seniors 80 and over for $5.
}
  
/*
read in an x from the user and print "even"
if x is even and "odd" otherwise. You do not need
any special math methods to do this.
*/
System.out.print("Enter number x:");
int x=scan.nextInt();
if(x %2==0)//check if x is even or odd
{
System.out.println("even");
}else
{
System.out.println("odd");
}
}

}

____________________________________________OUTPUT_______________________________________

Enter number n:20
low
Enter Animal Name:cat
oh, purr!
Enter Your age:18
Admission price :$12
Enter number x:20
even


Related Solutions

in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
Create a Netbeans project with a Java main class. (It does not matter what you name...
Create a Netbeans project with a Java main class. (It does not matter what you name your project or class.) Your Java main class will have a main method and a method named "subtractTwoNumbers()". Your subtractTwoNumbers() method should require three integers to be sent from the main method. The second and third numbers should be subtracted from the first number. The answer should be returned to the main method and then displayed on the screen. Your main() method will prove...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the class name YourlastnameLab7 with your actual last name. Create a Java class file for a Polygon class. Implement the Polygon class. Add a private instance variable representing the number of sides in the polygon. Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read and follow the instructions below, placing the code statements needed just after each instruction. Leave the instructions as given in the code. Declare and create (instantiate) an integer array called List1 that holds 10 places that have the values: 1,3,4,5,2,6,8,9,2,7. Declare and create (instantiate) integer arrays List2 and List3 that can hold 10 values. Write a method called toDisplay which will display the contents...
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder....
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder. 3. Import Scanner and Stacks from the java.util package. 4. Create a Stack object named basket. 5. The output shall: 5.1.Ask the user to input the number of fruits s/he would like to catch. 5.2.Ask the user to choose a fruit to catch by pressing A for apple, O for orange, M for mango, or G for guava. 5.3.Display all the fruits that the...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT