Write a guessing game with Java where the user guesses a number between one and 100 and you give tips based on how close or far they are. If they are 20+ digits away you can laugh at them! If they are within 10-20, say they are within a decent range, otherwise say they are getting closer!
You may work with a classmate or two or by yourself.
When you are finished you may add the random number ability:
int ranNumber = (int)(Math.random()*100);
if(ranNumber > 50)
{
System.out.println(ranNumber + " is greater than 50");
}
else if(ranNumber > 25)
{
System.out.println(ranNumber + " is greater than 25");
}
else
{
System.out.println("Your number sucks!");
}
Monday, September 8, 2008
Wednesday, September 3, 2008
First Post: What are your expectations for the class?
Just briefly let me know what your expectations are for this class!
Client.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bankaccount;
/**
*
* @author dfreer
*/
public class Client {
//Client properties
private String firstName;
private String lastName;
private double balance;
private int socialSecurity;
//methods for the Client
public String returnName()
{
return firstName + lastName;
}
public double getBalance(){
if(balance > 0)
return balance;
else
return -9999;
}
public void deposit(double amt)
{
balance = balance + amt;
}
//this is the constructor for the client object
public Client(String fn, String ln, double b, int ss){
firstName = fn;
lastName = ln;
balance = b;
socialSecurity = ss;
}
public static void main (String [] args)
{
Client ourFirstClient = new Client("Dwyane", "Wade", 6787456.24, 123456798);
//we make an object of Client for Dwyane Wade and return his balance
System.out.println(ourFirstClient.getBalance());
//6787456.24 is expected
ourFirstClient.deposit(1000000);
System.out.println(ourFirstClient.getBalance());
//boolean a = true;
//add to the constructor an address, preferred customer capability,
//add a method to withdraw money but do not let customer withdraw more than they
//have
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bankaccount;
/**
*
* @author dfreer
*/
public class Client {
//Client properties
private String firstName;
private String lastName;
private double balance;
private int socialSecurity;
//methods for the Client
public String returnName()
{
return firstName + lastName;
}
public double getBalance(){
if(balance > 0)
return balance;
else
return -9999;
}
public void deposit(double amt)
{
balance = balance + amt;
}
//this is the constructor for the client object
public Client(String fn, String ln, double b, int ss){
firstName = fn;
lastName = ln;
balance = b;
socialSecurity = ss;
}
public static void main (String [] args)
{
Client ourFirstClient = new Client("Dwyane", "Wade", 6787456.24, 123456798);
//we make an object of Client for Dwyane Wade and return his balance
System.out.println(ourFirstClient.getBalance());
//6787456.24 is expected
ourFirstClient.deposit(1000000);
System.out.println(ourFirstClient.getBalance());
//boolean a = true;
//add to the constructor an address, preferred customer capability,
//add a method to withdraw money but do not let customer withdraw more than they
//have
}
}
Wednesday, August 27, 2008
First minor assignment
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.
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.
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));
}
}
Subscribe to:
Posts (Atom)
