Question

"Please Solve Problem 2 Please" Program 1(Total Point 15): You will use scanner class and ask...

"Please Solve Problem 2 Please"

Program 1(Total Point 15): You will use scanner class and ask users to enter numbers from 0 to 10 numbers. You will then extract only non prime numbers and store it in the set. You will then print the entire set contents.

Problem 2(Total Point 15): Write a Java program that performs following things.

Generate 10 random numbers
Store all the numbers into the set
Use the iterator or any other class to extract all the elements from the set
Perform addition
Display output

Problem 3(Total Point 15):


Create the tree map that should store following strings.

- Hello

- Today

- Is

- Monday

Once you stored all the data in the tree map, then loop thru the tree map and remove Monday

Program 4(Total Point 15): You will use the scanner class and ask users following things.

- Student Age (Value)

- Student Name (Key)

You will store information for at least 10 students on Map. You will then use iterator to print all the values. You will print the youngest student’s name.

Program 5(Total Point 15):

Create the logic to print below series.

Num1: 1
Num2: 3
Num3: 5
Num4: 7
Num5: 9

You then need to store the entire series into the Hash map and tree map and then print the entire series.

Problem 6(Total Point 15):

Create the set that should store following strings.

-This
-Class
-is
-good
-We
-have
-learned
-lot
-of
-things.

Once you stored all the data in the set/map, then loop thru the set using iterator and remove all the strings that starts with either C or o.
And print the entire set as the single statement.

Problem 7(Total Point 10)

You need to create a base class that should have the following functionality.

- Calculate avg. Students grade. Input parameter to this method is an array that shows grades for at least ten courses.

You need to create a child class that inherits the base class. The child class should have a method to calculate max grade from 10 courses.

You need to write a demo class. The demo class should have a main method that calls child class and able to provide max and avg. Grade.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for Problem 2:

import java.util.*;
class Main
{
   public static void main(String args[])
   {
       int i,n,sum=0;
       Set<Integer> numbers = new HashSet<Integer>(); // Creating a Set Object
       Random rand = new Random();             //Creating a Random Object
       for(i=0;i<10;i++)
       {
           numbers.add(rand.nextInt(1000)); //Generating random numbers below 1000 and adding them to set
       }
       Iterator iterator = numbers.iterator();           //Creating an Iterator Object
       while(iterator.hasNext())                       //Checking whether set has elements or not
       {
           n = (Integer)iterator.next();                // iterating set to get next element
           sum=sum+n;              
       }
       System.out.println("Sum of 10 Random Numbers:"+sum);
      
   }
}

Outputs for the program:

Add a comment
Know the answer?
Add Answer to:
"Please Solve Problem 2 Please" Program 1(Total Point 15): You will use scanner class and ask...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with a Java question... A) Create the tree map that should store following...

    I need help with a Java question... A) Create the tree map that should store following strings. Hello Today Is Monday Once you stored all the data in the tree map, then loop thru the tree map and remove things B) Then, Create a set that stores the folling strings. -This -Class -is -good -We -have -learned -lot -of -things. Once you stored all the data in the set/map, then loop thru the set using iterator and remove all the...

  • How to solve this Problem in C++ . The Problem Write program that uses a class...

    How to solve this Problem in C++ . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the set...

  • Using Dev C++, write a program to solve the problem as stated below. Write a program...

    Using Dev C++, write a program to solve the problem as stated below. Write a program will input a single integer value (all input will be exactly 8 digits long) and will store pairs of digits as individual integer values. The program will display the five 2-digit numbers as well as the average of these, each on their own line. Use a switch statement to print out Grade: and then either A (>=90), B ([80..89]), C ([70..79]), D ([60..69]) or...

  • Using Dev C++, write a program to solve the problem as stated below. Make use of...

    Using Dev C++, write a program to solve the problem as stated below. Make use of a repetition structure (counter-controlled while loop) to shorten part of your code Dont use array. Write a program will input a single integer value (all input will be exactly 8 digits long) and will store pairs of digits as individual integer values. The program will display the five 2-digit numbers as well as the average of these, each on their own line. Use a...

  • Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able...

    Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...

  • Task 1: 1. Write a generic class named MyList, with a type parameter T. The type...

    Task 1: 1. Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of type T. Write the class constructor to create the ArrayList. 2. Write a public method named add, which accepts a parameter of type T. When an argument is passed to the method, add it to the ArrayList. 3. Write a public method...

  • In Java, Please do not forget the ToString method in the Student class! In this exercise,...

    In Java, Please do not forget the ToString method in the Student class! In this exercise, you will first create a Student class. A Student has two attributes: name (String) and gradePointAverage (double). The class has a constructor that sets the name and grade point average of the Student. It has appropriate get and set methods. As well, there is a toString method that prints the student's name and their grade point average (highest is 4.0) You will then write...

  • Using JAVA Lab Exercises 1. Complete the class AVLTree that extends BST. It should have four...

    Using JAVA Lab Exercises 1. Complete the class AVLTree that extends BST. It should have four methods RotateLeft, Rotate Right RotateLeftRight, and RetateRightLeft. You have to provide the methods rotate Right(), rotateLeftRight and rotateRightLeft, Provide the method delete() to delete elements in the AVL tree. 2. Create an AVL tree in which the following keys are inserted in the given order: 8, 12, 14, 18, 20, 23, 15, 13, 7, 16 Then ask the user to provide any 3 elements...

  • Write a program in C++ that uses a class template to create a set of items....

    Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...

  • You will create a class to store information about a student�s courses and calculate their GPA....

    You will create a class to store information about a student�s courses and calculate their GPA. Your GPA is based on the class credits and your grade. Each letter grade is assigned a point value: A = 4 points B = 3 points C = 2 points D = 1 point An A in a 3 unit class is equivalent to 12 grade points (4 for the A times 3 unit class) A C in a 4 unit class is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT