PART TWO
Write a program which will populate an integer ArrayList with user input, and then provide a menu of various operations to perform on that ArrayList.
The first step is to have the user push a bunch of integers into a ArrayList. The second step is to perform various operations on that ArrayList. Your input must be in the format below. The user can enter either a positive integer or -99 to quit. The menu to present is:
Your output should resemble the example below:
Let's populate the ArrayList. Enter a number: 50
Enter your next number or -99 to quit: 42
Enter your next number or -99 to quit: 63
Enter your next number or -99 to quit: 126
Enter your next number or -99 to quit: 81
Enter your next number or -99 to quit: 86
Enter your next number or -99 to quit: 9
Enter your next number or -99 to quit: 39
Enter your next number or -99 to quit: 116
Enter your next number or -99 to quit: -99
Your ArrayList is: 50 42 63 126 81 86 9 39 116
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 1
Your ArrayList: 50 42 63 126 81 86 9 39 116
Sum of the ArrayList: 612
Your ArrayList is: 50 42 63 126 81 86 9 39 116
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 2
Your ArrayList: 50 42 63 126 81 86 9 39 116
Sum of the square of each ArrayList element: 53124
Your ArrayList is: 50 42 63 126 81 86 9 39 116
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 3
Your ArrayList: 50 42 63 126 81 86 9 39 116
Smallest ArrayList element: 9
Your ArrayList is: 50 42 63 126 81 86 9 39 116
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 4
Your ArrayList: 50 42 63 126 81 86 9 39 116
Largest ArrayList element: 126
Your ArrayList is: 50 42 63 126 81 86 9 39 116
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 5
Let's populate the ArrayList. Enter a number: 50
Enter your next number or -99 to quit: 50
Enter your next number or -99 to quit: -99
Your ArrayList is: 50 50
What would you like to do with this ArrayList? Enter:
1 | Sum elements
2 | Sum of each element squared
3 | Display smallest element
4 | Display largest element
5 | Create a new ArrayList and start over
6 | End program
Choice? --> 6
Program ending.
PART THREE==================================================
Write a program that will populate an ArrayList with positive integers that the user enters. When the user is done entering integers, they enter -99 to quit. Your program then prints out that original ArrayList in a simple format.
Then present the user with a menu choice: select 1 for evens and 2 for odds. Your program then will add numbers from the original ArrayList into a second ArrayList, but in reverse order, and only the evens/odds that the user picked.
This program will ask you to enter numbers into an ArrayList until
you quit; it will then push only those even/odd numbers (you pick)
in reverse into a separate ArrayList.
Enter a positive integer or -99 to quit: 50
Enter your next positive integer or -99 to quit: 53
Enter your next positive integer or -99 to quit: 56
Enter your next positive integer or -99 to quit: 59
Enter your next positive integer or -99 to quit: 62
Enter your next positive integer or -99 to quit: 65
Enter your next positive integer or -99 to quit: 68
Enter your next positive integer or -99 to quit: 71
Enter your next positive integer or -99 to quit: 74
Enter your next positive integer or -99 to quit: q
Original ArrayList:
50 53 56 59 62 65 68 71 74
Select: (1) Evens
(2) Odds --> 1
Reversed ArrayList with only evens:
74 68 62 56 50
PART FOUR ====================================================
Design a set of classes that work together to simulate a police office issuing a parking ticket. Design the following classes:
Write a demo program to show how these classes collaborate.
UML's:
/*
-----------------------------------------
Parked Car Class
-----------------------------------------
- make : String
- model : String
- color : String
- plate: String
- minutesParked : int
-----------------------------------------
+ ParkedCar(mk: String, mod: String,
col: String, lic: String, min: int)
+ ParkedCar(car2 : ParkedCar)
+ (setters and getters as needed)
+ toString() : String
-----------------------------------------
*/
/*
-----------------------------------------
ParkingMeter Class
-----------------------------------------
- minutesPurchased : int
-----------------------------------------
+ ParkingMeter(m : int)
+ setMinutesPurchased(m : int) : void
+ getMinutesPurchased() : int
-----------------------------------------
*/
/*
-----------------------------------------
PoliceOfficer Class
-----------------------------------------
- name : String
- badge : String
-----------------------------------------
+ PoliceOfficer(n: String, bn: string)
+ PoliceOfficer(officer2 : PoliceOfficer)
+ patrol(car: ParkedCar, meter: ParkingMeter):
ParkingTicket
+ (setters and getters as needed)
+ toString() : String
*/
/*
-----------------------------------------
ParkingTicket Class
-----------------------------------------
- car: ParkedCar
- officer: PoliceOfficer
- fine: double
- minutes: int
+ BASE_FINE: double = 25.0
+ HOURLY_FINE: double = 10.0
-----------------------------------------
+ ParkingTicket(aCar: ParkedCar,
anOfficer: PoliceOfficer, min: int)
+ ParkingTicket(ticket2 : ParkingTicket)
+ calculateFine() : void
+ (setters and getters as needed)
+ toString() : String
*/
PART TWO ---
I WAS NOT ABLE TO DO THE PART - 3 DUE TO TIME LIMIT.
import java.util.*;
import java.util.Scanner;
import java.util.Collections;
class HomeworkLib1
{
public static void main(String[] args)
{
Scanner sc=new
Scanner(System.in);
ArrayList<Integer> list=new
ArrayList<Integer>();
System.out.println("Let's populate
the Array List");
while(true)
{
System.out.println("Enter 1 To Enter No or -99 to quit");
Integer
choice=sc.nextInt();
switch(choice)
{
case 1:
{
System.out.println("Enter the
Number");
Integer
elements=sc.nextInt();
list.add(elements);
break;
} //endof case1
case -99 :
{
System.out.println("Your Array List is :");
System.out.println(list);
while(true)
{
System.out.println("What would you like to do
with this ArrayList ? Enter:")
System.out.println("1| Sum Elements");
System.out.println("2 | Sum of each Element
Squared");
System.out.println("3 | Display smallest
Element");
System.out.println("4 | Display largest
Element");
System.out.println("5 | Create a new ArrayList
and start over");
System.out.println("6 | End program");
Integer choice2=sc.nextInt();
switch(choice2)
{
case 1:
{
int
sum=0;
for(int
i=0;i<=list.size();i++)
{
sum=sum + list.get(i);
}
System.out.println(sum);
break;
}//case1
case 2:
{
int
sum=0;
for(int
j=0;j<=list.size();j++)
{
int k=list.get(j);
sum=sum + k*k;
}
System.out.println(sum);
break;
}//case2
case 3:
{
Object
min=Collections.min(list);
System.out.println(min);
break;
}//case3
case 4:
{
Object
max=Collections.max(list);
System.out.println(max);
break;
}//case4
case 5:
{
ArrayList<Integer> list1=new
ArrayList<Integer>();
while(true);
{
System.out.println("Enter 1 To Enter No or -99 to quit");
Integer
choice3=sc.nextInt();
switch(choice3)
{
case 1:
{
System.out.println("Enter the
Number");
Integer
elements1=sc.nextInt();
list1.add(elements1);
break;
}//case1
case -99 :
{
System.out.println("Your Array List is :");
System.out.println(list1);
break;
}//case -99
}//switch
break;
}//while
}//case5
case 6:
{
System.out.println("Program End");
System.exit(0);
}//case6
}//switch
}//while
break;
}//switch
}//while
}//main
} //end of class HomeworkLib1
THANK YOU.
PART TWO Write a program which will populate an integer ArrayList with user input, and then...
in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....
Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...
Write a program that receives a positive integer n from the user and then calculates the sum below by using a loop. Your program needs to ask the user to re-enter a different number if the user enters a non-positive one. Display the result. 1 SUM 1 2 3 ... n x x n = = = + + + +
1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...
Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to input 10 int numbers from the user...
JAVA:
(15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...
2) Write a complete program in which main creates two Integer arrayLists and then adds 1, 2, , 10 to the first ArrayList, and 21, 22, ^, 30 to the second ArrayList. main should call a method passing it the two ArrayLists. This method should create and return a third ArrayList, each slot of which contains the sum of the values in the corresponding slots of the first and second ArrayLists. On return to main, main should display the values...