100 Lockers For Students

Apr 4, 2015

A school has 100lockers and100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denotedL2, and closes every other locker. Student S3beginswiththethirdlocker and changes every third locker (closes it if it was open, and opens it if it was closed). Student S4begins with locker L4 and changes every fourth locker. StudentS5 starts with L5andchanges every fifth locker, and soon,until student S100 changesL100.

After all the students have passed through the building and changed the lockers, which lockers are open?Write a program to find your answer. The program should display the answer like this:

Locker x is open Locker y is open...
Locker z is open
Design requirement:
Use a method and an array of100 boolean elements,each of which indicates
whether a locker is open (true) or closed (false). Initially,all lockers are closed.

I'm not sure why it's giving me errors in my code. I'll post it below.

1
2 public class Assignment5 {
3
4 public static void main(String[] args) {
5 //create array
6boolean locker[] = new boolean[100];
7 //make them all closed
8for( int i = 0; i <= 99; i++){
9locker[i]= false;

[Code] ....

I have errors in line 12 and 14 but not sure why or how to fix them.

View Replies


ADVERTISEMENT

Grouping Students From ArrayList

Jan 12, 2015

I have an ArrayList filled with Student objects and all these students have a name. What I have to do is group these students in teams of 2 and make sure that 1. a student is not grouped with itself and 2. a student is not grouped twice.

The problem shows up when I iterate through the ArrayList and crosscheck a randomly generated number (for picking random students) with an ArrayList that contains already selected students, to make sure that we have no duplicates.

Here is my code:

public void generateTeams() {
Iterator<Student> iteration = studentsArray.iterator();
 while(iteration.hasNext()) {
student1 = iteration.next();
// getRandomStudent returns a random Student object from the arraylist
student2 = getRandomStudent();
 
[Code] .....

If I run it like this the program will freeze an take up a lot of CPU. This is probably because the final student has no other students left to pair with and will therefore keep randomly generating a number (the while loop in the middle). The list of students is 27 long so it has to work with an odd amount of students.

Any good way to crosscheck if the student has been picked before? I have tried emptying the original ArrayList before but that ends up with the same problem of there being no students to match with.

In the while loop I have edited out the part that causes it to generate random numbers infinitely. I do need to make sure the student hasn't been picked before though.

View Replies View Related

Students Grading - Two Dimensional Arrays

Jun 18, 2014

I have the program bellow that grades students(based on a two dimensional array with the answers) and i need to make it display the students based on the grades/scores in ascending order . I did that in two ways (using a array and a two dimensional array) but i have a hunch it can be done much more simple then i did it (but still using array object and nothing else ) .

public class GradeExam {
/** Main method */
public static void main(String args[]) {
// Students' answers to the questions
char[][] answers = {

[code]....

My first solution creating an array with the grades for sorting :

public class C8_3 {
public static void main(String args[]) {
// Students' answers to the questions
char[][] answers = {
{'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},

[code]....

View Replies View Related

Determining Letter Grade Of Students

Apr 14, 2014

The purpose of this project is to determine the letter grade of students. The program needs to accept two command line arguments:

The first being the name of a disk file that contains the names of students, and their test scores, separated by commas followed by one or more spaces. Each line in the file will contain scores for one student.

The second argument is the name of an output disk file. The program is supposed to create a new output disk file using that name.

The number of students in the input file is unknown during compile time. The name of input and output files could be anything and only known during run time. Additionally, the average scores, along with the minimum and maximum scores for each test are to be displayed in the console.

Calculation: Final Score = quiz1 * .10 + quiz2 * .10 + quiz3 * .10 + quiz4 * .10 + midi * .20 + midii * .15 + final * .25
Final Score >= 90% then letter grade is A, 80%-89% B, 70%-79% C, 60-69% D, <= 59% F

input_data.txt:

firstName lastName, 100, 90, 80, 100, 89, 99, 88
firstName lastName, 90, 90, 100, 100, 99, 100, 95
firstName lastName, 100, 90, 100, 70, 78, 78, 80
firstName lastName, 80, 90, 90, 100, 89, 99, 85
etc.

output_data.txt

firstName lastName: B
firstName lastName: A
firstName lastName: F
firstName lastName: B
firstName lastName: C

averages (to appear in console)
Q1 Q2 Q3 Q4 MidI MidII Final
Average: 82.25 80.38 82.85 83.88 81.38 84.13 78.63
Minimum: 60 54 38 62 62 60 50
Maximum: 100 90 100 100 99 100 95

Press ENTER to continue...

Here's what I have so far :

import static java.lang.System.out;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
public class LetterGrader {

[Code] .....

View Replies View Related

Students GPA Database - Return String With All Information

Dec 13, 2014

Here is the question with my Pseudocode:

Create an application that keeps track of students. The application should have 3 new classes.

1. Create a class which will represent an instance of 1 student:

I want to be able to display the user's name (Last, First), Age (in years as an integer) and GPA (to 2 decimal points). This class only needs a constructor and a toString method.

2. Create a Team class that will represent a group of students.

This class should allow the driver class to manage students for a given course. The class will keep track of the course name and section, the students in the class, and allow the driver to specify the max number of students to keep track of.

Methods:
1.Constructor
2.It should have a method to insert a single student into the array and return a Boolean indicating success or failure.
3.It should also have a method which returns a string with all of the course and student information formatted for display. You should make the name 12 characters long.

3. Create a driver class that will manage the whole process.

Pseudocode:

BEGIN Driver main method
Initialize student count to 0
Input size of the array
Instantiate a copy of the Team class
Input a student name (or quit)
WHILE (the student name is not quit)
Input student age
Input student GPA

[Code] ....

View Replies View Related

Gradebook Program - Calculate Averages Of 25 Students Using 2D Arrays

Apr 16, 2014

I am making a gradebook program that calculates the averages of 25 students using 2D arrays in which the students have four test grades. I have figured out how to display the averages of each student in one column but I cant seem to figure out how to display the letter grade of the average into another column.

Right now my program reads from a .txt doc

Heres what I've got.

TestGradeBook.java

import java.util.*;
import java.io.*;
public class TestGradeBook {
public static void main (String [] args ) throws IOException{
//Declarations
final int ROWS = 100;
final int TESTS = 4;

[Code] .....

GradeBook_Data.txt
Name100100100100
// basic name and grades

View Replies View Related

Scheduling Software - Display Chart Showing Lesson Times For Particular Teacher And Students

Aug 27, 2014

I want to develop a dynamic scheduling application that I hope to use at work, but I have some questions about the design approach since this is my first undertaking of this kind of project.

The purpose of the application is to display a chart showing the lesson times for a particular teacher and her students.

Here's are more important details:

-The chart displays the current day's schedule.
-The top row displays the teacher's name. There are at least 4 teachers each day.
-The leftmost column shows the times (from 3:00 to 8:00).
-The table is filled with the names of the students.

My current problem is deciding on the best approach to storing this data containing the teacher and her students and times. I should also note that there are about 500 students and around 20 teachers (i.e. the dataset is small). Is this a problem solved using a database and JDBC or could I just write the data to file? Are there other approaches that would solve this problem?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved