CPS 1231 – Lab Arrays Grades The lab this week is to write a program that reads grades in the integer range 1 – 100 from a user, writes out the grades in an organized fashion, computes their average...

1 answer below »
I need to have 5 Labs completed for Beginners Java Class. (Arrays, Looping, Method) and 2 Worksheets (Methods and Looping) Approximately 16 Pages. Each Lab would need to be in own PDF file.



CPS 1231 – Lab Arrays Grades The lab this week is to write a program that reads grades in the integer range 1 – 100 from a user, writes out the grades in an organized fashion, computes their average rounded to the nearest tenth, and finds out how many grades are above average and how many grades are below average. All output should be written to the console window. Basic - 20 grades Mid-Level - ask the user for the number of grades before accepting input Advanced - keep asking for integer input until the user puts in a number that isn’t an int Output: Grades entered: 95 70 90 82 55 90 92 99 100 70 80 90 100 75 85 80 84 87 90 100 {95, 70, 90, 82, 55, 90, 92, 99, 100, 70, 80, 90, 100, 75, 85, 80, 84, 87, 90, 100 } The average is 85.7. There are 11 grades above average. There are 9 grades below average. The range is 46 (between 55 and 100). Requirements (methods should ONLY take an array of integers as a parameter): · Write a method that will print out the items of the array on a single line. · Write a method that calculates and then returns the average of the array of information. · Write a method that determines how many grades are above the average and returns that number. This method only takes the array as the parameter. · Write a method that determines how many grades are below the average and returns that number. This method only takes the array as the parameter. · Write a method that determines the range of the grades. The range is found by subtracting the highest grade from the lowest grade. · The main method should handle output (Methods to calculate the average and how many grades are above and below the average should return values, and not print out anything). CPS 1231 –- Lab - Arrays, File Input, Strings Within the program you are to create, and you will store a collection of the words in the text document. Store all words in an array from one of the following documents. There are 3 text documents that you can test your program on. File1.txt, File2.txt and File3.txt. (Each file is attached separately) Write a commented program with the main method appropriately calling each of the following methods and print out their results. Recall all printing should be done in the main method. Write the following static methods: findLongestWord( String [] arr ) takes a String Array and finds the longest word within the array. Ties can be broken any way you wish (first longest word, last longest word, etc). The method returns the longest word. findShortestWord( String [] arr ) takes a String Array and finds the shortest word within the array. Ties can be broken any way you wish (first in the alphabet, last in the alphabet, etc). The method returns the shortest word. countWordsEndingWith( String [] arr, String str ) takes a String Array and a String, and counts all of the words in the Array that end with this String. The method returns the count. countWordsStartingWith (String [] arr, String str ) takes a String Array and a String, and counts all of the words in the Array that begin with this String. The method returns the count. AS Description: Create three programs that utilizes loops in order to create the desired effects. AS Instructions: Write a commented program that completes the tasks outlined in the assignment. Loops and Strings 1. Write a program that keeps asking the user for a password until they correctly name it. Once they correctly enter the password, the program congratulates the user and tells them how many guesses it took. Be sure to be grammatically correct with the guess/guesses output. Call the program LastNamePassword. Example (user input in italics) What is the password? monkeys Incorrect. Guess again. dishwasher Incorrect. Guess again. aardvark Correct! You got the password, and it took you 3 guesses to get it correct. 2. Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K 3. Write a program where the user enters a string, and the program outputs a string where for every char in the original, there are two chars except if the character is the number 2. If that happens, do not duplicate the 2. Call your program LastNameDoubles. Input Output The → TThhee AAbb → AAAAbbbb Hi-There → HHii—Tthheerree 1234→1123344 CPS 1231 – Method Labs AS Description: Create a program that utilizes methods given in the description and called in the sample main method. AS Instructions: Write a commented set of methods that would work with the given main method. Utilize the call to the method, the comments and the description in order to put together these methods. Methods Working Together In the following main method, there are three methods that are working together in order to complete a variety of tasks. Go ahead and copy and paste the code. Do not alter the main method. Your program will be graded using a different main method so any changes you make there won’t necessarily help. import java.util.Scanner; public class BauerMethodLab{ //change your name here! public static void main (String [] args) { Scanner in = new Scanner(System.in); System.out.println("Enter a number"); //Getting the value from the user. int num = in.nextInt(); System.out.println("Your number is the following: " + num); System.out.println("Your number is " + oddOrEven(num) ); //oddOrEven will return the string either odd or even depending on the value of the parameter. num = multByRand(num); //multByRand multiplies the parameter by a random number between 8 and 15. System.out.println("The new number is " + num); printBoxes(num, num + 1); // printBoxes will output the following when num = 3. // [] [] [] // [] [] [] // [] [] [] // [] [] [] } } It is now your task to write the methods that this program uses. The descriptions are listed below. oddOrEven: takes an integer parameter and returns the string “odd” if the number is odd and “even” if the number is even. multByRand: takes the integer parameter and returns that number times a random number between 8 and 15. printBoxes: takes two integer parameters. The first parameter is how many boxes per row it will output, and the second parameter is how many rows to output. It does not return any value, only prints out the boxes. CPS 1231 – Project #1 You are to create a single program that collects 5 words from the user and prints them out in various ways. Store them so you can access them throughout this program. There are 4 parts to this program - make sure you are commenting your code with descriptions of each section of code and Write my name “Jon Bauer” in Each Part. Also place in PDF Format. Part 1: Ordering Lexicographic order is dictionary order, except that all the uppercase letters precede all the lowercase letters. For example b comes before c, but b comes after Y. Java uses methods to determine which words come first Lexicographically. Print the 5 words out in Lexicographic order. Part 2: Pig Latin Pig Latin is a language used by kids and annoying adults. Here are the rules for converting an English word into Pig Latin. If the word begins with a consonant, move the consonant to the end of the word and add “ay” after it. If the word begins with a vowel, add “yay” to the end of the word. English Pig Latin dog ogday Apple Appleyay easy easyyay Cattle attleCay Print out the first and second words from Part 1 in Pig Latin. Part 3: Reversing letters Print the 2nd and 3rd words from Part 1 again but switch the first letter with the last letter. For example, the word computer would become romputec. Part 4: Mixing up Words Take the 4th and the 5th words from part 1 and print out both of their celebrity couple names. Celebrity couples are made from taking half of the first name and combining it with the other half of the other name. The first half of the first name combines with the second half of the second name and the first half of the second name combines with the second half of the first name. Odd length names can be handled any way you wish, but all letters of both original words must be used between the two new words. For example - Joey and Amanda would become Jonda and Amaey Example: An example run of this program with the words given as inputs: Camel Elephant Alligator Bison Dog Part 1: Alligator Bison Camel Dog Elephant Part 2: Alligatoryay isonBay Part 3: nisoB lameC Part 4: Dhant Elepog
Answered Same DaySep 27, 2021

Answer To: CPS 1231 – Lab Arrays Grades The lab this week is to write a program that reads grades in the...

Aditya answered on Oct 01 2021
149 Votes
Solution/ArrayLab4.docx
Code:
import java.util.Scanner;
public class ArraysLab4
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int size;
System.out.print("Enter number of grades: ");
size= sc.nextInt();
int arr[] = new int[size];
System.out.println("Enter elements in array");
for(int i =0;i {
int num = sc.nextInt();
boolean valid = true;
while(valid)
{
if(num >= 1 && num <= 100)
{
arr[i] = num;
valid = false;
}
else
{
System.out.println("Enter in range 1 - 100");
}

}
}
printArray(arr);
System.out.println("\nThe average is "+getAverage(arr)+".");
System.out.println("There are "+getAboveAverage(arr)+" grades above average. ");
System.out.println("There are "+getBelowAverage(arr)+" grades below average. ");
System.out.println("The range is "+getRange(arr)+".");
}

public static void printArray(int arr[])
{
System.out.println("Elements in array");
for(int i =0 ;i {
System.out.print(arr[i]+" ");
}
}

public static float getAverage(int arr[])
{
float average = 0;
for(int i =0 ;i {
average = average + arr[i];
}
average = average/(float)arr.length;
return average;
}

public static int getBelowAverage(int arr[])
{
int count = 0;
float average = getAverage(arr);
for(int i =0 ;i {
if(arr[i] {
count++;
}
}
return count;
}

public static int getAboveAverage(int arr[])
{
int count = 0;
float average = getAverage(arr);
for(int i =0 ;i {
if(arr[i]>average)
{
count++;
}
}
return count;
}

public static int getRange(int arr[])
{
int range = 0;
int max = arr[0];
int min= arr[0];
for(int i =0 ;i {
if(arr[i]>max)
{
max = arr[i];
}

if(arr[i] < min)
{
min = arr[i];
}
}
range = max - min;
return range;
}
}
Output:
Solution/ArrayLab4-converted.pdf
Code:
import java.util.Scanner;
public class ArraysLab4
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int size;
System.out.print("Enter number of grades: ");
size= sc.nextInt();
int arr[] = new int[size];
System.out.println("Enter elements in array");
for(int i =0;i {
int num = sc.nextInt();
boolean valid = true;
while(valid)
{
if(num >= 1 && num <= 100)
{
arr[i] = num;
valid = false;
}
else
{
System.out.println("Enter in range 1 - 100");
}
}
}
printArray(arr);
System.out.println("\nThe average is "+getAverage(arr)+".");
System.out.println("There are "+getAboveAverage(arr)+" grades above average. ");
System.out.println("There are "+getBelowAverage(arr)+" grades below average. ");
System.out.println("The range is "+getRange(arr)+".");
}
public static void printArray(int arr[])
{
System.out.println("Elements in array");
for(int i =0 ;i {
System.out.print(arr[i]+" ");
}
}
public static float getAverage(int arr[])
{
float average = 0;
for(int i =0 ;i {
average = average + arr[i];
}
average = average/(float)arr.length;
return average;
}
public static int getBelowAverage(int arr[])
{
int count = 0;
float average = getAverage(arr);
for(int i =0 ;i {
if(arr[i] {
count++;
}
}
return count;
}
public static int getAboveAverage(int arr[])
{
int count = 0;
float average = getAverage(arr);
for(int i =0 ;i {
if(arr[i]>average)
{
count++;
}
}
return count;
}
public static int getRange(int arr[])
{
int range = 0;
int max = arr[0];
int min= arr[0];
for(int i =0 ;i {
if(arr[i]>max)
{
max = arr[i];
}
if(arr[i] < min)
{
min = arr[i];
}
}
range = max - min;
return range;
}
}
Output:
Solution/jbcps.docx
Code:
//Jon Bauer
import java.util.Scanner;
public class CPS1231Project1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter word sepeared by space: ");
String line = sc.nextLine();
String[] word = line.split("\\s+");

//part 1
for (int i = 0; i < word.length-1; ++i) {
for (int j = i + 1; j < word.length; ++j) {
if (word[i].compareTo(word[j]) > 0) {
String temp = word[i];
word[i] = word[j];
word[j] = temp;
}
}
}
System.out.print("Part 1: ");
for (int i = 0; i < word.length; i++) {
System.out.print(word[i]+" ");
}
String word2[] = new String[word.length];
for (int i=0; i word2[i] = word[i];
//part 2
String temp;
for (int i = 0; i < word2.length; ++i) {
if((word2[i].startsWith("a"))||(word2[i].startsWith("A"))||(word2[i].startsWith("e"))||(word2[i].startsWith("E"))||(word2[i].startsWith("i"))||(word2[i].startsWith("I"))||(word2[i].startsWith("o"))||(word2[i].startsWith("O"))||(word2[i].startsWith("u"))||(word2[i].startsWith("U"))){
word2[i]+="yay";
}
else
{
temp=Character.toString(word2[i].charAt(0));
word2[i]=word2[i].substring(1);
word2[i]+=temp;
word2[i]+="ay";
}
}

System.out.print("\nPart 2: ");
for (int i = 0; i < 2; i++) {
System.out.print(word2[i]+" ");
}
//part 3
char[] ch;
char x;
ch= word[1].toCharArray();
x = ch[0];
ch[0] = ch[ch.length - 1];
ch[ch.length - 1] = x;
word[1]= String.valueOf(ch);
ch= word[2].toCharArray();
x = ch[0];
ch[0] = ch[ch.length - 1];
ch[ch.length - 1] = x;
word[2]= String.valueOf(ch);
System.out.print("\nPart 3: "+word[1]+""+word[2]);

//Part 4
String word4 = word[3];
String word5 = word[4];
System.out.println("");
String newWord = word4.substring(0, word4.length()/2 )+word5.substring(word5.length()/2 ,word5.length());
String newWord1 = word5.substring(0, word5.length()/2)+word4.substring(word4.length()/2 ,word4.length());
System.out.println("Part 4: "+newWord+""+newWord1);

}

}
Solution/jbcps-converted.pdf
Code:
//Jon Bauer
import java.util.Scanner;
public class CPS1231Project1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter word sepeared by space: ");
String line = sc.nextLine();
String[]...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here