Here is a sample of the instructions (caller) in
Test.java:
String s = " 2 , 3/4, 1/16, 2 3/2, 2 2/4,,,1 5/2,";//code to read
from keyboard via Scanner
s = Utility.clean(s);
System.out.println("CleanOrig=|" + s+"|" ); //Outputs: "2,3/4,1/16,2 3/2,2 2/4,1 5/2"
SortSP obj = new SortSP(s);
System.out.println("init array of Fractions = " + obj ); //Outputs: "2,3/4,1/16,7/2,5/2,7/2"
obj.bubbleSP(); // sort array using bubble, insertion, or selection
System.out.println("Fractions in increasing order = " + obj ); //Outputs: "1/16,3/4,2,5/2,7/2,7/2"
Outline of class SortSP:
a. Name of class is "Sort" followed by your initials in upper
cases.
b. There are 2 attributes: (Note: You should not add any extra
attributes)
String sSP; //name of string started with "s" followed by your initials in upper cases.
Fraction[] aSP;// name of array started with "a" followed by your initials in upper cases. c. methods:
resetSP: to set the second attribute to be its original, (not create any unnecassary new fractions) .
bubbleSP: to sort the 2nd attribute in increasing order.
additional methods to make the sample work
Note: SP are the initials of your instructor. You need to replace
they by yours.
CODE
import
java.util.*;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class SortGopi{
int[] array;// Variable to store integer array
//
Constructor
public SortGopi(int[] array){
this.array=array; // Storing into class variable using this
keyword
}
// Method to Bubble sort array
void bubbleGopi()
{
int n = this.array.length; // Getting length of array
for (int i = 0; i < n-1; i++)
{
for (int j = 0; j < n-i-1; j++) {
if (this.array[j] > this.array[j+1])
{
// swap arr[j+1] and arr[i]
int temp = this.array[j];
this.array[j] = this.array[j+1];
this.array[j+1] = temp;
}
}
}
}
/* Prints the array */
void printArray()
{
int n = this.array.length;
for(int i:this.array){
System.out.print(i+" ");
}
System.out.println("]");
}
}
public class Main
{
public static int[] clean (String clean)
{
// Removing unwanted character except int and ,
String cleaned = clean.replaceAll ("[/]", "");
System.out.println("Clean String : "+cleaned);
Pattern p = Pattern.compile("\\d+");//Finding integers in clean
string
Matcher m = p.matcher(cleaned);// Getting Integers again
int size=0;
// Finding total integers existed
while(m.find()) {
size++;
}
m = p.matcher(cleaned);// Getting Integers again for staring
value
int[] integers=new int[size];
int index=0;
while(m.find()){
// adding integers to list
integers[index++]=Integer.parseInt(m.group());
}
return integers; // returning list
}
public static void main (String[]args)
{
// Creating scanner class object
Scanner scanner = new Scanner(System. in);
String s = scanner. nextLine();//Reading string
int[] values=clean(s); // Calling cleaning method
//Creating Class instance object
SortGopi obj=new SortGopi(values);
System.out.print("Array of Fractions : [");
obj.printArray();
// Bubble sorting array
obj.bubbleGopi();
System.out.print("Fractions in Increasing order : [");
obj.printArray();
}
}
Code Screenshots
OUTPUT:-
Please upvote sir
Here is a sample of the instructions (caller) in Test.java: String s = " 2 ,...
*****Requiremrnt: 1. Please do not use any array or arraylist 2. collects only a single String input 3. uses at least 3 String methods 1) Just Initials: Print just the initials in upper case letters separated by periods 2) Last Name First With Middle Initial: Print the last name in lower case with the first letter capitalized, followed by a comma and the first name in in lower case with the first letter capitalized and then the middle initial capitalized...
Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray(); char[] reverse = new char[original.length]; for(int i =0; i<s.length(); i++){ reverse[i] = original[original.length-1-i]; } return new String(reverse); } /** * Takes in a string containing a first, middle and last name in that order. * For example Amith Mamidi Reddy to A. M. Reddy. * If there are not three words in the string then the method will return null * @param name in...
**** ITS MULTI-PART QUESTION. PLEASE MAKE SURE TO ANSWER THEM ALL. SOLVE IT BY JAVA. **** *** ALSO MAKE SURE IT PASS THE TESTER FILE PLEASE*** Often when we are running a program, it will have a number of configuration options which tweak its behavior while it's running. Allow text completion? Collect anonymous usage data? These are all options our programs may use. We can store these options in an array and pass it to the program. In its simplest...
DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress, Cart and Main. ITEM CLASS Your Item class should contain: Attributes (protected) String name - name of the Item double price - price of the item Methods (public) void setName(String n) - sets the name of Item void setPrice(double p) - sets the price of Item String getName() - retrieves name double getPrice() - retrieves price String formattedOutput() returns a string containing detail of...
in java no mathcall please ennas are out of date.Please sign was wkollieemail.cpeedu so we can verily your subscription Sign In ASSIGNMENT Unit 9 Methods, Arrays, and the Java Standard Class Library Reimplementing the Arrays class (60 points) The Arrays class, which is also part of the Java standard class library, provides various class methods that perform common tasks on arrays, such as searching and sorting. Write a public class called MyArrays, which provides some of the functionality which is...
Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods. Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement Element to be found */ int findAll(int...
1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash is quite common in many Bloom Filters, the hashing algorithm to be implemented is a mix of the the following algorithmic models, specifically, a multiply & rotate hash colloquially known as a murmur hash, and an AND, rolale, & XOR hash colloquially known as an ARX hash. 2 Requirements • Inputs. Read the input file which contains strings...
Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...