Question 0:
package hw3;
public class Question0 {
/*
* TODO: Complete the method isSorted that
* takes in as input an array of String
* and returns back a boolean value whether it
* is sorted in Lexicographical order or not.
* You can read up more on this here:
* https://en.wikipedia.org/wiki/Lexicographical_order
*/
public static boolean isSorted(String[] array)
{
}
/*
* Do not write any code inside the main method and expect it to get marked.
* Any code that you write inside the main method will be ignored. However,
* you are free to edit the main function in any way you like for
* your own testing purposes.
*/
public static void main(String[] args)
{
String[] items={"a","b","c"};
System.out.println(Question0.isSorted(items)); //must print true
String[] items1={"c","b","a"};
System.out.println(Question0.isSorted(items1)); //must print false
String[] items2={"111","112","131","132"};
System.out.println(Question0.isSorted(items2)); //must print true
String[] items3={"a","aa","b","bb","c","ca"};
System.out.println(Question0.isSorted(items3)); //must print true
String[] items4={"z","zz","zzz","zzzz"};
System.out.println(Question0.isSorted(items4)); //must print true
}
}package hw3;
public class Question0 {
/*
* TODO: Complete the method isSorted that
* takes in as input an array of String
* and returns back a boolean value whether it
* is sorted in Lexicographical order or not.
* You can read up more on this here:
* https://en.wikipedia.org/wiki/Lexicographical_order
*/
public static boolean isSorted(String[] array)
{
for (int i = 1; i < array.length; i++) {
if (array[i-1].compareTo(array[i]) > 0) {
return false;
}
}
return true;
}
/*
* Do not write any code inside the main method and expect it to get marked.
* Any code that you write inside the main method will be ignored. However,
* you are free to edit the main function in any way you like for
* your own testing purposes.
*/
public static void main(String[] args)
{
String[] items={"a","b","c"};
System.out.println(Question0.isSorted(items)); //must print true
String[] items1={"c","b","a"};
System.out.println(Question0.isSorted(items1)); //must print false
String[] items2={"111","112","131","132"};
System.out.println(Question0.isSorted(items2)); //must print true
String[] items3={"a","aa","b","bb","c","ca"};
System.out.println(Question0.isSorted(items3)); //must print true
String[] items4={"z","zz","zzz","zzzz"};
System.out.println(Question0.isSorted(items4)); //must print true
}
}
Question 0: package hw3; public class Question0 { /* * TODO: Complete the method isSorted that...
Complete the code below, test cases to use are at the bottom package Labs; public class ResizingQueue { private final int INITIAL_SIZE = 10; private int [] A = new int[INITIAL_SIZE]; // array to hold queue: front is always at Q[0] // and rear at A[next-1] int next = 0; // location of next available unused slot // interface methods public void enqueue(int key) { //TODO: push the key onto the back of the queue // YOUR CODE HERE! }...
LAB PROMPT: Lab 06 For this lab you are going to practice writing method signatures, implementing if statements, and improve your skills with for loops. The methods you will be writing have nothing to do with each other but allow you to use the skills you have gained so far to solve a series of small problems. Power For this method you will practice using methods from the Math class. The first step you must take is to write the...
complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null;...
JAVA program Note: you can't change anything is already written Student.java public class Student { private String name; private String major; private double gpa; public Student(String name, String major, double gpa) { // TO-DO: Assign the given parameters to the data fields. Use the this keyword. } public double getGPA() { // TO-DO: return this.gpa } public String getName() { // TO-DO: return this.name }...
Please help me. package a1; public class Methods { /* * Instructions for students: Use the main method only to make calls to the * other methods and to print some testing results. The correct operation of * your methods should not depend in any way on the code in main. * * Do not do any printing within the method bodies, except the main method. * * Leave your testing code...
Fix the todo in ball.java Ball.java package hw3; import java.awt.Color; import java.awt.Point; import edu.princeton.cs.algs4.StdDraw; /** * A class that models a bounding ball */ public class Ball { // Minimum and maximum x and y values for the screen private static double minX; private static double minY; private static double maxX; private static double maxY; private Point center; private double radius; // Every time the ball moves, its x position changes by...
What will be the output of the following Java code? class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } } a) 0 b) 1 c) false d) true
Check if an array is a heap in Java. Complete the method isHeapTree Together, these methods are meant to determine if an array of objects corresponds to a heap. The methods are generic, and they should work with an array of any type T that implement Comparable<T>. Implement the second method so that it uses recursion to process the complete tree/subtree whose root is at position i in the array arr. The method should return true if that tree/subtree is...
Complete the code: package hw4; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.Scanner; /* * This class is used by: * 1. FindSpacing.java * 2. FindSpacingDriver.java * 3. WordGame.java * 4. WordGameDriver.java */ public class WordGameHelperClass { /* * Returns true if an only the string s * is equal to one of the strings in dict. * Assumes dict is in alphabetical order. */ public static boolean inDictionary(String [] dict, String s) { // TODO Implement using binary search...
java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main { { return true; } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main { { String ans = name.toUpperCase();...