Evaluate 1.1.2 Quality Feedback Quest
In your blog, provide a student work sample and accompanying feedback that showcases some of the expectations listed above and offers a sound example of quality, authentic feedback. Discuss aspects of the sample that align with the best practices discussed in this quest.
The assignment was to write a menu-dirven program.
Richard, This is a very good example of how to break down the program into parts. You did a nice job of creating managable methods and then reusing them when appropriate. The program is excellent and I would like to use it next year in the AP class when I speak of methods. Can I?
*/
import java.util.*;
import java.io.*;
public class StudentMenu {
//Creating Variables
static public int rand;
static public int[] Lines = new int[21];
static String[] fn = new String[21];
static String[] ln = new String[21];
static public int[] yog = new int[21];
static public int[] grades1 = new int[21];
static public int[] grades2= new int[21];
static public int[] grades3 = new int[21];
static public int[] grades4 = new int[21];
static public int[] grades5 = new int[21];
static public int[] ID = new int[21];
static public Scanner scan = new Scanner(System.in);
static public double[] averages = new double[21];
static public Scanner fileReader;
static int choice;
//Main Function
public static void main(String[] args){
init();
menu();
}
//Init Function
public static void init(){
//Start File Scanner
fileReader = null;
try{
fileReader = new Scanner(new File("StudentStats.txt"));
System.out.println("File found. Loading Resources.");
}catch(FileNotFoundException e){
System.out.print("StudentStats.txt not Found. Exiting...");
System.exit(0);
}
//Assign things to Variables.
double average;
for (int i = 0; i < 21; i++){
fn[i] = fileReader.next();
ln[i] = fileReader.next();
yog[i] = fileReader.nextInt();
ID[i] = fileReader.nextInt();
grades1[i] = fileReader.nextInt();
grades2[i] = fileReader.nextInt();
grades3[i] = fileReader.nextInt();
grades4[i] = fileReader.nextInt();
grades5[i] = fileReader.nextInt();
Lines[i] = i;
averages[i] = ((double)(grades1[i]) + (double)(grades2[i]) + (double)(grades3[i]) + (double)(grades4[i]) + (double)(grades5[i])) / 5;
}
System.out.print("Resources Loaded. Press enter to continue.");
scan.nextLine();
clear(20);
}
//The menu itself. This will be seen often.
public static void menu(){
System.out.println("What would you like to do?\n\n");
System.out.println("1. Find a student by last name.");
System.out.println("2. Find a student by Year of Graduation.");
System.out.println("3. Finds a student by looking for an average.");
System.out.println("4. Find a student by Student ID.");
System.out.println("5. Find a student's average.");
System.out.println("6. See all Students.");
System.out.println("7. Give the student with the highest average.");
System.out.println("8. Give student with the lowest average.");
System.out.println("9. Quit.\n\n");
System.out.print("\n\nWhat would you like to do? ");
choice = scan.nextInt();
if (choice == 1){
lastNameSearch();
}else if (choice == 2){
yearSearch();
}else if(choice == 3){
averageSearch();
}else if(choice == 4){
IDSearch();
}else if(choice == 5){
findAverage();
}else if(choice == 6){
printAll();
}else if(choice == 7){
highestAverage();
}else if(choice == 8){
lowestAverage();
}else if(choice == 9){
System.out.println("\n\n\nGoodbye.");
System.exit(0);
}else System.out.print(choice + " is not a valid choice. Please enter a valid choice.");
}
//Functions keyed by the menu
public static void lastNameSearch(){
System.out.print("What name are you looking for? ");
String EnteredName = scan.next();
boolean found = false;
System.out.print("\n\n");
for (int i = 0; i <=20; i++){
//System.out.println("Flag: " + ln[i]);
if (EnteredName.equals(ln[i])){
System.out.println("We found a Student. Here's their info:");
System.out.println(fn[i] + " " + ln[i] + " " + yog[i] + " " + ID[i] + " " + averages[i]);
found = true;
}
}
if (found == false) System.out.print("Name not found!");
}
public static void yearSearch(){
System.out.print("What year did the student graduate, or is expected to graduate? ");
int EnteredYear = scan.nextInt();
boolean found = false;
System.out.print("\n\n");
for (int i = 0; i < 21; i++){
if (EnteredYear == yog[i]){
System.out.println("\nWe found a Student. Here's their info:");
System.out.println(fn[i] + " " + ln[i] + " " + yog[i] + " " + ID[i] + " " + averages[i]);
found = true;
}
}
if (found == false) System.out.print("We couldn't find a student with that Year of Graduation.");
}
public static void averageSearch(){
System.out.print("What is the student's Average? ");
String EnteredAverage = scan.next();
boolean found = false;
System.out.print("\n\n");
for (int i = 0; i < 21; i++){
if ((EnteredAverage + "").equals(averages[i] + "")){
System.out.println("We found a Student. Here's their info:");
System.out.println(fn[i] + " " + ln[i] + " " + yog[i] + " " + ID[i] + " " + averages[i]);
found = true;
}
}
if (found == false) System.out.print("We couldn't find a student with that average. Sorry.");
}
public static void IDSearch(){
System.out.print("What is the student's ID? ");
int EnteredID = scan.nextInt();
boolean found = false;
System.out.print("\n\n");
for (int i = 0; i < 21; i++){
if (EnteredID == ID[i]){
System.out.println("We found a Student. Here's their info:");
System.out.println(fn[i] + " " + ln[i] + " " + yog[i] + " " + ID[i] + " " + averages[i]);
found = true;
}
}
if (found == false) System.out.print("We couldn't find a student with that ID");
}
public static void findAverage(){
System.out.print("Enter the first name of the student: ");
String EnteredName = scan.next();
boolean found = false;
for (int i = 0; i <= 20; i++){
//System.out.println("Flag: " + ln[i]);
if (EnteredName.equals(fn[i])){
System.out.print("We found the student. Here's their average: " + averages[i]);
found = true;
}
}
if (found == false) System.out.print("We couldn't find the student. Sorry.");
}
public static void printAll(){
String answer;
System.out.print("Would you like them sorted by First Name, Last Name, or neither? ");
answer = scan.next();
if ((answer.substring(0)).equals("f")){
BubbleSorting(fn);
}else if ((answer.substring(0)).equals("F")){
BubbleSorting(fn);
}else if ((answer.substring(0)).equals("l")){
BubbleSorting(ln);
}else if ((answer.substring(0)).equals("L")){
BubbleSorting(ln);
}else for (int i = 0; i <21;i++) System.out.println((i+1) + ") " + fn[i] + " " + ln[i] + " " + yog[i] + " " + ID[i] + " " + averages[i]);
}
public static void highestAverage(){
int hai= 0;
for (int i = 0; i < 21; i++){
if (averages[i] > averages[hai]) hai = i;
}
System.out.println("The highest average we found is " + averages[hai]);
System.out.println("\nHere is the student's info:");
System.out.println(fn[hai] + " " + ln[hai] + " " + yog[hai] + " " + ID[hai]);
}
public static void lowestAverage(){
int hai= 0;
for (int i = 0; i < 21; i++){
if (averages[i] < averages[hai]) hai = i;
}
System.out.println("The lowest average we found is " + averages[hai]);
System.out.println("\nHere is the student's info:");
System.out.println(fn[hai] + " " + ln[hai] + " " + yog[hai] + " " + ID[hai]);
}
public static void clear(int times){
for (int i=0; i <=times; i++) System.out.print("\n");
}
public static void BubbleSorting(String[] names){
String tempS;
int tempI;
double tempD;
int i = 0;
int hai = 0;
while (hai < 21){
hai++;
for(i = 0; i<names.length-1; i++){
if (names[i].compareToIgnoreCase(names[i+1])>0) {
//First name
tempS = fn[i];
fn[i] = fn[i+1];
fn[i+1] = tempS;
//Last NAme
tempS = ln[i];
ln[i] = ln[i+1];
ln[i+1] = tempS;
//Year of Graduation
tempI =(yog[i]);
yog[i] = yog[i+1];
yog[i+1] = tempI;
//Grades 1
tempI = (grades1[i]);
grades1[i] = grades1[i+1];
grades1[i+1] = tempI;
//Grades 2
tempI =(grades2[i]);
grades2[i] = grades2[i+1];
grades2[i+1] = tempI;
//Grades 3
tempI = (grades3[i]);
grades3[i] = grades3[i+1];
grades3[i+1] = tempI;
//Grades 4
tempI = (grades4[i]);
grades4[i] = grades4[i+1];
grades4[i+1] = tempI;
//Grades 5
tempI = (grades5[i]);
grades5[i] = grades5[i+1];
grades5[i+1] = tempI;
//Average
tempD = (averages[i]);
averages[i] = averages[i+1];
averages[i+1] = tempD;
}
}
if (i > 20) i = 0;
}//while
System.out.println("\nFirst, Last, Average, ID");
for (int o = 0; o < 20; o++){
System.out.println(fn[o] + " " + ln[o] +" "+ averages[o] +" "+ ID[o]);
}
}
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home