Group Lesson Homework Assignments
Homework from Unit 1-5 Lessons (6 was ours)
import java.util.Scanner;
public class PrimitivesCalculator {
public static void main(String[] args) {
Scanner input;
boolean separateCategory;
float currentGrade;
float desiredGrade;
float percentOfFinal;
input = new Scanner(System.in);
System.out.print("Do you want separate categories? ");
separateCategory = input.nextBoolean();
System.out.println(separateCategory);
if(separateCategory == true) {
System.out.print("Enter current grade? ");
currentGrade = input.nextInt();
System.out.println(currentGrade);
System.out.print("Enter desired grade? ");
desiredGrade = input.nextInt();
System.out.println(desiredGrade);
System.out.print("Enter percent of grade that is final? ");
percentOfFinal = input.nextFloat();
System.out.println(percentOfFinal);
input.close();
float gradeNeeded = (desiredGrade - currentGrade * (1-percentOfFinal))/percentOfFinal;
System.out.println(gradeNeeded);
}
}
}
public class WordMatch
{
/** The secret string. */
private String secret;
/** Constructs a WordMatch object with the given secret string of lowercase letters. */
public WordMatch(String word)
{
/* implementation not shown */
}
/** Returns a score for guess, as described in part (a).
* Precondition: 0 < guess.length() <= secret.length()
*/
public int scoreGuess(String guess)
{
int result = 0;
for (int a = 0; a < secret.length(); a++)
{
if(secret.substring(a).indexOf(guess) == 0)
{
result++;
}
}
return result * guess.length() * guess.length();
}
}
b)
// public int scoreGuess(String guess)
// { /* to be implemented in part (a) */ }
/** Returns the better of two guesses, as determined by scoreGuess and the rules for a
* tie-breaker that are described in part (b).
* Precondition: guess1 and guess2 contain all lowercase letters.
* guess1 is not the same as guess2.
*/
public String findBetterGuess(String guess1, String guess2)
{
if(scoreGuess(guess1)>scoreGuess(guess2))
{
return guess1;
}
if(scoreGuess(guess2) > scoreGuess(guess1))
{
return guess2;
}
if(guess1.compareTo(guess2) > 0 )
{
return guess1;
}
return guess2;
}
Unit 3 - Boolean Expressions and If Statements
Completed as team - link to Meena's blog post.
public class CaesarCipher {
public static void main(String[] args) {
String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String message1 = "Kfzb gly!";
String message2 = "zlab zlab zlab";
String message3 = "prmbozxifcoxdfifpqfzbumfxifalzflrp";
}
}
public class StepTracker {
// accessing and showing our private instance variables
private int totalSteps;
private int minimumSteps;
private int daysActive;
private int days;
// constructor with the parameter
public StepTracker(int least){
minimumSteps = least;
totalSteps = 0; // values to initialize variables
daysActive = 0;
days = 0;
}
//added the dailySteps method as the "AddDailySteps"
public void AddDailySteps(int steps){
totalSteps += steps; //shows active days and the incremental counting
days++;
if (steps >= minSteps){
daysActive++; // updates the other instance variables
}
}
//the activeDays method
public int getdaysActive(){ // declared and implemented into program
return days;
}
public double avgSteps(){
if (days == 0){
return 0.0;
}
else{
//returns the calculated double of the average number of steps walked
return (double) totalSteps / days;
}
}
}