

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information about quiz 7 for the cmsc 131 java programming course. It includes instructions for the written quiz, which covers material from exercises on methods, stacks, and arrays. Students are expected to write code for problems involving implementing double.parsedouble, creating a mystack class, extending the student class to create a roster class, and generating an array of even random numbers.
Typology: Quizzes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


CMSC 131 Quiz 7 Worksheet
The next quiz will be on Monday , Nov 8 during your lab session (either at 10 am or 11 am). The following list provides more information about the quiz: .
The following exercises cover the material to be covered in Quiz #7. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with TAs and instructors during office hours.
When asked for a “piece of code” you do not need to provide an entire class definition or even an entire method. Just present the Java statements and any variable declarations as needed to make your solution clear.
Problem 1
Write a method that implements the functionality of Double.parseDouble. That is, a method that transforms a string into a double. Examples include “14.234”, “-13”, “+.234”, and “0.0100”.
Problem 2
A Stack is a data structure frequently used in Computer Science. In this structure elements are inserted and removed from the same end (similar to a stack of clean plates in a dinner). Implement a class called MyStack which represents a Stack of String objects. The specifications associated with the class are:
Instance variable
String[] array; // Array used to represent the stack. // Feel free to add any other variables you may need.
Methods
The following illustrates how to use the class MyStack:
MyStack myStack = new MyStack(); myStack.push(“Hello”); myStack.push(“Everybody”); System.out.println(myStack.top()); // It will print “Everybody”. myStack.pop(); System.out.println(myStack.top()); // It will print “Hello”.
Problem 3
A student class has the following definition:
public class Student { private String name; private int id;
public Student(String sname, int sid) { name = sname; id = sid; }
public Student(Student student) { name = new String(student.name); id = student.id; }
public int getId() { return id; }
public String toString() { return name + " " + id; } }
Define a class called Roster which has the following specifications:
Instance variable
Student[] array; // array used to represent the roster