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...

  • 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...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • python language Problem Description: In this program we are going to explore a list or an...

    python language Problem Description: In this program we are going to explore a list or an array of integers using Python. Your program should read a set of integers from the user and store them in a list. Read numbers from the user until the user enters 0 to quit. Then store them in a list. Your program should them compute the sum of all the numbers in the list and output to the user. You will use lists and...

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
ADVERTISEMENT