Premium Essay

Arraylist, Hashmap, Queue Student Assignment

In:

Submitted By doyers
Words 366
Pages 2
import java.text.DecimalFormat; import java.util.ArrayList;

public class Student {

// Declare the variables

private String name; private ArrayList homeworks;

// Constructor with one argument

public Student(String name) { this.name = name; this.homeworks = new ArrayList(); }

// setter or mutator methods change the field values public void setName(String name) { this.name = name; }

//Accessor or getter methods provide the field values public String getName() { return name; }

public void addHomeworkGrade(int newGrade){ this.homeworks.add(newGrade); }

//average homework score public double getComputeAverage(){ int total = 0; //loop through homeworks, add to total for(Integer grade : this.homeworks){ total += grade; }

//calculate average double average = total / (double)this.homeworks.size(); return average; }

//Override the toString method to return the string representation public String toString() { DecimalFormat pattern = new DecimalFormat("0.00"); return (getName() + "'s average grade is " + pattern.format(getComputeAverage()));

}
}
------------------------

import java.io.FileReader; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; import java.util.Set; import java.util.StringTokenizer;

public class Test {

public static void main(String[] args) { String inputFileName = "data.txt"; FileReader fileReader = null; // Create the FileReader object try { fileReader = new FileReader(inputFileName); } catch (FileNotFoundException e) { e.printStackTrace(); }

Queue studentQueue = new LinkedList(); HashMap studentMap = new HashMap();

Similar Documents

Premium Essay

Cmmkfgdk

...quotations in critical articles or reviews. For more information, contact support@careercup.com. Printed in United States of America 978-1-450-59320-5 9781450593205 (ISBN 13) Table of Contents Foreword Introduction Behind the Scenes The Microsoft Interview The Amazon Interview The Google Interview The Apple Interview The Yahoo Interview Interview War Stories Before the Interview Resume Advice Behavioral Preparation Technical Preparation The Interview and Beyond Handling Behavioral Questions Handling Technical Questions Five Algorithm Approaches The Offer and Beyond Top Ten Mistakes Candidates Make Frequently Asked Questions Interview Questions Data Structures Chapter 1 | Arrays and Strings Chapter 2 | Linked Lists Chapter 3 | Stacks and Queues Chapter 4 | Trees and Graphs Concepts and Algorithms Chapter 5 | Bit Manipulation Chapter 6 | Brain Teasers 4 5 7 8 9 10 11 12 13 20 21 23 25 28 29 31 34 37 39 41 44 46 47 49 51 53 56 57 59...

Words: 47808 - Pages: 192

Free Essay

Lol Girl

...the United States of America. Preface You will find this book to be somewhat unusual. Most computer science texts will begin with a section on the history of computers and then with a flurry of definitions that are just “so many words” to the average student. My approach with Blue Pelican Java is to first give the student some experience upon which to hang the definitions that come later, and consequently, make them more meaningful. This book does have a history section in Appendix S and plenty of definitions later when the student is ready for them. If you will look at Lesson 1, you will see that we go right to work and write a program the very first day. The student will not understand several things about that first program, yet he can immediately make the computer do something useful. This work ethic is typical of the remainder of the book. Rest assured that full understanding comes in time. Abraham Lincoln himself subscribed to this philosophy when he said, “Stop petting the mule, and load the wagon.” The usual practice in most Java textbooks of introducing classes and objects alongside the fundamental concepts of primitive variable types, loops, decision structures, etc. is deferred until the student has a firm grasp of the fundamentals. Thus, the...

Words: 31284 - Pages: 126

Free Essay

Exercise Java

...Programming Exercises For Chapter 2 -------------------------------------------------------------------------------- THIS PAGE CONTAINS programming exercises based on material from Chapter 2 of this on-line Java textbook. Each exercise has a link to a discussion of one possible solution of that exercise. http://www.java2s.clanteam.com -------------------------------------------------------------------------------- Exercise 2.1: Write a program that will print your initials to standard output in letters that are nine lines tall. Each big letter should be made up of a bunch of *'s. For example, if your initials were "DJE", then the output would look something like: ****** ************* ********** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ******** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ***** **** ********** See the solution! : visit this website http://java2s.clanteam.com/ -------------------------------------------------------------------------------- Exercise 2.2: Write a program that simulates rolling a pair of dice. You can simulate rolling one die by choosing one of the integers 1, 2...

Words: 18137 - Pages: 73

Free Essay

Resume Google

...To my mother and grandmother, whose engineering endeavors paved the way for my own. Copyright © 2011 by Gayle Laakmann. All rights reserved. Published by John Wiley & Sons, Inc., Hoboken, New Jersey. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies...

Words: 72645 - Pages: 291