Continuing the LunchCart class:
public class LunchCart
{
//properties of a LunchCart
private int num_Sandwiches;
private int num_Drinks;
private double price_of_sandwich;
private double price_of_Drinks;
private double total_value_of_sandwiches;
private double total_value_of_Drinks;
//setter methods for the LunchCart
public void setNumSandwiches(int x)
{
num_Sandwiches = x;
}
//getter methods for the LunchCart
public int getNumSandwiches()
{
return num_Sandwiches;
}
//setter method!
public void setNumDrinks(int y)
{
num_Drinks = y;
}
//getter method!
public int getNumDrinks()
{
return num_Drinks;
}
public static void main(String [] args)
{
LunchCart thisismylunchcart = new LunchCart();
thisismylunchcart.setNumSandwiches(55);
System.out.println(thisismylunchcart.getNumSandwiches());
thisismylunchcart.setNumDrinks(15);
System.out.println(thisismylunchcart.getNumDrinks());
}
}
Add the ability to set the other variables and calculate the value of the sandwiches and the value of the drinks.
Finish this assignment by next class. To do this, you'll most likely need to install Netbeans.
Here is how to install Java to use the command line.
Print out the code before next class. Even if you don't get all the getter and setter methods or calculations, print out what you have. This will be the last and only code that you have to print out. Usually you'll put it on an FTP server.
Wednesday, August 27, 2008
Monday, July 28, 2008
Minimum Fun!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package minimumfun;
/**
*
* @author dfreer
*/
public class Main {
public static int calcMinimum(int [] a, int counter, int minimum)
{
if(counter == a.length-1)
return minimum;
else
{
if(a[counter] > minimum)
{
return calcMinimum(a, ++counter, a[counter]);
}
return calcMinimum(a, ++counter, minimum);
}
}
public static int minimum(int [] a)
{
int minimum = a[0];
return calcMinimum(a, 0, minimum);
}
public static void main(String [] args)
{
int [] b = {3,4,5,6,2,5};
System.out.println(minimum(b));
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package minimumfun;
/**
*
* @author dfreer
*/
public class Main {
public static int calcMinimum(int [] a, int counter, int minimum)
{
if(counter == a.length-1)
return minimum;
else
{
if(a[counter] > minimum)
{
return calcMinimum(a, ++counter, a[counter]);
}
return calcMinimum(a, ++counter, minimum);
}
}
public static int minimum(int [] a)
{
int minimum = a[0];
return calcMinimum(a, 0, minimum);
}
public static void main(String [] args)
{
int [] b = {3,4,5,6,2,5};
System.out.println(minimum(b));
}
}
Pseudocode
package recursion;
/**
*
* @author dfreer
*/
public class SmallestNumber {
//How are we going to use recursion to figure out the smallest number???
//take in an array of integers
public static int findSmallest(int [] a)
{
//call another method with a counter
return findSmallestRecursively(a, 0);
//return smallest number (int)
}
public static int findSmallestRecursively(int [] a, int counter)
{
//base case
//if we've reached the end of the array, stop! return minimum!
//if statement to determine whether next number is smaller or larger
//keep track of the smallest number using a variable (int)
//call findSmallestRecursively from itself!! (this is what makes recursion)
//within the recursive call increment counter!
}
public static void main(String []args)
{
//call the first method!
}
/**
*
* @author dfreer
*/
public class SmallestNumber {
//How are we going to use recursion to figure out the smallest number???
//take in an array of integers
public static int findSmallest(int [] a)
{
//call another method with a counter
return findSmallestRecursively(a, 0);
//return smallest number (int)
}
public static int findSmallestRecursively(int [] a, int counter)
{
//base case
//if we've reached the end of the array, stop! return minimum!
//if statement to determine whether next number is smaller or larger
//keep track of the smallest number using a variable (int)
//call findSmallestRecursively from itself!! (this is what makes recursion)
//within the recursive call increment counter!
}
public static void main(String []args)
{
//call the first method!
}
Final Exam Review
Click here.
It will be 50% conceptual and 50% coding. The coding will be similar to the exam 4's.
8 people have A's after last test.
Here's the grades.
It will be 50% conceptual and 50% coding. The coding will be similar to the exam 4's.
8 people have A's after last test.
Here's the grades.
On your blog
Please write about the relationship between data structures and algorithms.
What is the difference between a stack and a queue?
Pick two sorting algorithms and explain how they work.
What is the difference between a stack and a queue?
Pick two sorting algorithms and explain how they work.
Final Major Project
What are you working on or planning to do for your last project? Major project 5.
Please post this on your blog.
Please post this on your blog.
Subscribe to:
Posts (Atom)
