Cheating Network
 
 

Go Back   Cheating Network > Programming > General
Reload this Page Java if you're bored...



General

This is a discussion about Java if you're bored... within the General section, where you will General Talk of Programming



Reply
 
LinkBack Thread Tools Display Modes
Old 03-25-2009, 05:25 PM   #1 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Unhappy Java if you're bored... PAYPAL IF YOU CAN FIGURE IT OUT!

GUIDLINES AND OVERVIEW OF PROJECT IN THIRD POST!!

That is the assignment....


Code:
//HOMEWORK 3- The Duration class that is used by the Exercise Calculator

public class Duration {
	private int hours;
	private int minutes;
	private int seconds;
	
	//Default constructor that sets the variables to zero
	public Duration(){
		hours = 0;
		minutes = 0;
		seconds = 0;
	}
	
	//This constructor takes the hours, minutes, and seconds as parameters and sets them
	//into the proper format with no more than 59 in the seconds and minutes
	public Duration(int hr, int min, int sec){
		if (min > 59){
			hr = hr + min / 60;
			min = min % 60;
		}
		
		if (sec > 59){
			min = min + sec / 60;
			sec = sec % 60;
		}
		
		hours = hr;
		minutes = min;
		seconds = sec;
	}
	
	//This constructor takes just seconds as the parameter. It then takes the seconds and
	//converts it to the hours, minutes, and seconds format.
	public Duration(int totalSeconds){
		hours = totalSeconds / 3600;
		totalSeconds = totalSeconds % 3600;
		minutes = totalSeconds / 60;
		seconds = totalSeconds % 60;
	}
	
	//This takes a Duration object as a parameter and then copies the info inside it to a
	//different Duration object.
	public Duration(Duration other){
		hours = other.getHours();
		minutes = other.getMinutes();
		seconds = other.getSeconds();		
	}
	
	//This returns the hours for the object called on.
	public int getHours(){
		return hours;
	}
	
	//This returns the minutes for the object called on.
	public int getMinutes(){
		return minutes;
	}
	
	//This returns the seconds for the object called on.
	public int getSeconds(){
		return seconds;
	}
	
	//This method sets the hours
	public void setHours(int hr){
		hr = hours;
	}
	
	//This method takes any int and separates into minutes and hours
	public void setMinutes(int min){
		if(min > 59){
			hours = hours + min / 60;
			minutes = min % 60;
		}
		else min = minutes;
	}
	
	//This method takes any int as seconds and separates it into minutes and seconds
	public void setSeconds(int sec){
		if(sec > 59){
			minutes = minutes + sec / 60;
			seconds = sec % 60;
		}
		else sec = seconds;
	}
	
	//This method takes a duration object as a parameter and adds the hours, minutes, and seconds
	//of that object to the object that is already running.
	public Duration add(Duration plus){
		Duration n = new Duration(hours+plus.getHours(), minutes+plus.getMinutes(), seconds+plus.getSeconds());
		return n;	
	}
	
	//This method takes an int as an argument and multiplies the hours, minutes, and seconds each 
	//by the the int passed in.
	public Duration multiply(int n){
		Duration s = new Duration(hours * n, minutes* n, seconds * n);
		return s;
	}
	
	//This returns the hours, minutes, and seconds of an object in a readable string
	public String toString(){
		return (hours+" hours "+minutes+" minutes "+seconds+" seconds");
	}
	
	//This takes a Duration object as an argument and tests if the hours, minutes, and seconds are the
	//same as the object already running. It returns true if they are equal and false if they are not 
	//equal or if the object equals null.
	public boolean equals(Duration equal){
		if (equal == null){
			return false;
		}
		if(hours == equal.getHours() && minutes == equal.getMinutes() && seconds == equal.getSeconds()){
			return true;
		}
		return false;
	}
	
	//This takes a Duration object and compares it to the object already running and returns 1 if the object
	//already running is bigger, -1 if it is smaller, and 0 if they are the same.
	public int compareTo(Duration compare){
		int sec = compare.getHours()*3600 + compare.getMinutes()*60 + compare.getSeconds();
		int originalSec = hours*3600 + minutes*60 + seconds;
		if(sec > originalSec) return -1;
		if(sec < originalSec) return 1;
		return 0;
	}
}
That is the Duration class that I coded....

Here is what I have so far in the Time Class.....

Code:
public class Time {
	
	private int hours;
	private int minutes;
	private int seconds;
	
	public Time(int hours1, int min1, int sec1) throws Exception{
		
		if(sec1<0 || sec1>59 || min1<0 || min1>59 || hours1<0 || hours1>23){
			throw new Exception("Invalid time entry");
		}
		
		hours = hours1;
		minutes = min1;
		seconds = sec1;
	}
	
	//This returns the hours for the object called on.
	public int getHours(){
		if(hours>12){
			hours -= 12;
		}
		return hours;
	}
	
	//This returns the minutes for the object called on.
	public int getMinutes(){
		return minutes;
	}
	
	//This returns the seconds for the object called on.
	public int getSeconds(){
		return seconds;
	}
	////////////////////////////////////////////////////HAVE TO RETURN AM/PM
	//This returns the hours, minutes, and seconds of an object in a readable string
	public String toString(){
		return (hours+" hours "+minutes+" minutes "+seconds+" seconds");
	}
	
	public static Time subtract(Time sub){
		if()		
	}

}
Because I'm not really sure how to finish the time class I don't really have an idea on how to finish it with writing the GymWeeklyExerciseManager class. If Anyone takes the time just to read through all of that let alone help me you are the man!

Last edited by icefisherman; 04-01-2009 at 06:25 PM..
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 03-25-2009, 05:34 PM   #2 (permalink)
Senior Member
 
fscrp's Avatar
 
Join Date: Feb 2008
Posts: 387
Reputation: 19
fscrp is on a distinguished road

cBay Rating:
Default

"Page not found" clicking your link
__________________
The nose causes the tail
fscrp is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 05:36 PM   #3 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

Shit I thought that would happen

Code:
ComS 227
Homework Assignment 3 300 points Due date: Friday, Apr 3, 2009, 11:59pm
Introduction
In homework 2 we have developed a Duration class used to represent a period of time. This homework will use this Duration class together with a Time class to keep track of weekly exercises. This assignment uses runtime exceptions to guard against illegal values such as a negative time. You will also use an enumerated type in this homework to represent the day of the week.
Detailed Class Specification
Enum Day A file called Day.java is given. The file contains the following definition: public enum Day { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} You should not need to change this file. Note that a useful method that is available to all enumerated types is called ordinal(). It returns the ordinal number of an enumerated type constant. For example, Day.Sunday.ordinal() returns 0, and Day.Tuesday.ordinal() returns 2.
Duration Class
The Duration class is the same as in Assignment 2. In this homework assignment, your Duration class itself will not be graded again, but you are responsible for its correctness wherever else it is used in this assignment.
Time Class
The Time class represents a time in hours, minutes, and seconds. It has the following requirements. All the constructor and methods specified below are public. You may have other methods for this class, but they must be set to be private. 1. No default constructor. 2. A specific constructor that takes hours, minutes, and seconds as parameters and creates a time object with the specific hours, minutes, and seconds. The constructor throws a RuntimeException if the seconds is not between 0 and 59, the minutes is not between 0 and 59, or the hours is not between 0 and 23. Note that this is 24-hour time and 22 hours, 31 minutes, 15 seconds represents 10:31:15 pm. 3. The methods getHours, getMinutes, and getSeconds are required and return int-type hours, minutes, and seconds, respectively. 4. A toString method that returns the time in 12-hour format is required. For example, 21 hours, 39 minutes, 22 seconds returns the string “9:39:22 PM”. 5. A static method called subtract that takes two Time objects as parameters and returns a Duration object that is the difference between the two Time objects. Note that if the first Time parameter is less than the second Time parameter, a RuntimeException is thrown.
GymWeeklyExerciseManager Class
This class represents a weekly exercise regimen for the members of a gym. It has the following requirements. All the constructor and methods specified below are public. You may have other methods for this class, but they must be set to be private. Note that in this assignment, a person is considered to be in the gym starting from the second he/she checks in. A person is considered to be out of the gym starting from the second he/she checks out. 1. A default constructor. 2. A method called checkIn with the following signature: void checkIn(String name, Day day, Time checkInTime); The method registers the time of day a given person checks in. If the person has already checked in, the method throws a RuntimeException. In other words, a checkIn must be closed by a checkout before a new checkIn for the same person is invoked; otherwise, a RuntimeException is thrown. 3. A method called checkOut with the following signature: void checkOut(String name, Time checkOutTime); This method registers the time a person checks out. Note that there is no day parameter, since the checkout has to happen on the same day as the check-in. If the checkout time is not later than the time the person checked in or the person is not checked-in, this method throws a RuntimeException. 4. A method called getTotalGymTime which contains an array that sums the amount of time spent in the gym by all users during each day of the week (Sunday through Saturday). This method throws a RuntimeException if there is any user left unchecked out. Duration[] getTotalGymTime(); 5. A method called getExerciseTimeOf. It returns an array of Duration which contains the total amount of time that a person called “name” spent in the gym during each day of the week, from Sunday and Saturday. If the person did not check into the gym on any given day, then the Duration value for that day is 0. This method throws a RuntimeException if the person called “name” is left unchecked out when the method is being invoked. Duration[] getExerciseTimeOf(String name); 6. A method called getBusiestDay which returns the day when the total amount of time spent in the gym by all users is highest. This method throws a RuntimeException if there is any user left unchecked out. Day getBusiestDay(); 7. A method called whoIsInGym which returns an array of the names of everyone who is in the gym at the specified time. This method throws a RuntimeException if there is any user left unchecked out. String[] whoIsInGym(Day day, Time time); 8. A method called getMaximumOccupancyOfTheWeek which returns the hightest number of people checked into the gym at the same time. This method throws a RuntimeException if there is any user left unchecked out. int getMaximumOccupancyOfTheWeek(); 9. A method called isInGym which returns true if the person called “name” is in the gym between the start and end time, inclusive. This method throws a RuntimeException if there is any user left unchecked out, or if the start time occurs later than the end time. boolean isInGym(String name, Day day, Time start, Time end); 10. A method called readCSVFile which reads information from a comma-separated values ( CSV ) file. The method has the following signature: void readCSVFile(String filename); The CSV file has the following format: Name,Day,checkInTime,checkOutTime. For example, a CSV file may look like: Sara Smith,Monday,17:30:00,18:00:00 Joe Smith,Wednesday,00:08:00,00:48:01 Sara Smith,Monday,07:30:00,08:10:00 Note that a person may come to the gym several times on a given day. If the CSV file is in a format other than specified, this method throws a RuntimeException. You are responsible for thoroughly testing each of the above constructors and methods. Feel free to share any test programs that may use these methods or any CSV files.
Edit: Fixed
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 06:02 PM   #4 (permalink)
Senior Member
 
Join Date: Mar 2008
Posts: 143
Reputation: -12
bigfatturd can only hope to improve

cBay Rating:
Default

How long have you been in java?
bigfatturd is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 06:05 PM   #5 (permalink)
Senior Member
 
Join Date: Dec 2007
Posts: 837
Reputation: 64
userrc651 will become famous soon enough

cBay Rating:
Default

Hey man, I'll be glad to help give me about half an hour (shower, read over the assignment) and I'll be back.
userrc651 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 06:44 PM   #6 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

bft- This is my first semester in java.

userrc- that would be awesome!
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 06:53 PM   #7 (permalink)
Senior Member
 
Join Date: Dec 2007
Posts: 837
Reputation: 64
userrc651 will become famous soon enough

cBay Rating:
Default

Ok, I'll start with the toString method since that's where it appears you left off.


Code:
public String toString()
{
String output;
if (hours > 12)
      output = hours%12 + ":" + minutes + ":" + seconds +"  PM";
else   output = hours%12 + ":" + minutes + ":" + seconds + "  AM";
return output;
}
And for the subtract method...

Code:
public static Duration Subtract(Time t1, Time t2)
{
int hr_dif, min_dif, sec_dif;

if t1.getHours() < t2.getHours)
//throw exception I'll leave this up to you.

else
{
hr_dif = t1.getHours() - t2.getHours();
min_dif = t1.getMinutes - t2.getMinutes();
sec_dif = t1.getSeconds() - t2.getSeconds();
}

//create new Duration object with the difference in time
Duration time_dif = new Duration(hr_dif, min_dif, sec_dif);

return time_dif;
}
Give that a shot, there may be some syntax errors (I did it rather quickly), let me know how it turns out for you.

EDIT: The subtract method is incorrect for a number of reasons (negative seconds) and (what if seconds/minutes > 60). I'll leave this part up to you. ;-)

2nd EDIT: I'm retarded... the Duration class already handles minutes/seconds > 60... so really you have two options. Either use the absolute value function or double negate them. Ex. (if min < 0) min = -min.

Last edited by userrc651; 03-25-2009 at 07:21 PM..
userrc651 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 07:06 PM   #8 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

Thanks a lot I'll give it a try and see what I can do with the next class
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 07:08 PM   #9 (permalink)
Programmer
 
Join Date: Apr 2008
Posts: 1,567
Reputation: 255
Bomb is a jewel in the roughBomb is a jewel in the roughBomb is a jewel in the rough

cBay Rating:

Theta The Internet 

Send a message via AIM to Bomb Send a message via MSN to Bomb Send a message via Skype™ to Bomb
Default

I'm only 15 but I can confidently say you suck at Java.
Bomb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 07:17 PM   #10 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Thumbs down

Quote:
Originally Posted by Bomb View Post
I'm only 15 but I can confidently say you suck at Java.
Cool, everyone give this kid a round of applause.


BTW: I started java about 4 weeks ago and had no prior knowledge of java programming.

Also, stay out of the thread if you don't want to help .
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 07:50 PM   #11 (permalink)
Senior Member
 
BrownPaperBag's Avatar
 
Join Date: Jun 2008
Posts: 1,595
Reputation: 86
BrownPaperBag will become famous soon enough

cBay Rating:

Scribe Superintendent 

Default

Quote:
Originally Posted by Bomb View Post
I'm only 15 but I can confidently say you suck at Java.
You're the bomb.
__________________
Quote:
Originally Posted by BeginnersLuck View Post
Meh, they seems racists, only accept ones from USA/CAnada
Quote:
Originally Posted by BeginnersLuck View Post
Classifying black people as a "race" makes you a racist
BrownPaperBag is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-25-2009, 07:52 PM   #12 (permalink)
Member
 
Join Date: Feb 2009
Posts: 65
Reputation: 0
Notikk is an unknown quantity at this point

cBay Rating:
Default

LMAO icefisherman doesn't this fall under the academic dishonesty rule? I don't blame you though I was about to do the same shit like 2 weeks ago.
__________________
Habu Gaming Mouse (Ordered 2/15/09 | Received 3/19/09)
Windows Vista Ultimate (Ordered 4/19/09 | Received 5/22/09)
Xbox 360 (Ordered 4/28/09 | Received N/A )
Notikk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-01-2009, 06:24 PM   #13 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

bump........ I really need help I will pay via paypal if you can do the GymWeeklyExerciseManager class
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-01-2009, 07:45 PM   #14 (permalink)
Senior Member
 
Join Date: Mar 2008
Posts: 143
Reputation: -12
bigfatturd can only hope to improve

cBay Rating:
Default

How much are you willing to pay?
bigfatturd is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-01-2009, 08:30 PM   #15 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

I will pay around $10 via paypal
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-01-2009, 08:54 PM   #16 (permalink)
Senior Member
 
Join Date: Dec 2008
Posts: 304
Reputation: 29
campbell292 is on a distinguished road

cBay Rating:
Default

Well just one thing I noticed.
Code:
//This method sets the hours
public void setHours(int hr){
	hr = hours;
}
should be
Code:
//This method sets the hours
public void setHours(int hr){
	hours = hr;
}
campbell292 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-01-2009, 09:29 PM   #17 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

Thanks I updated it
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-03-2009, 08:50 PM   #18 (permalink)
Go State!
 
icefisherman's Avatar
 
Join Date: Dec 2007
Posts: 950
Reputation: 52
icefisherman will become famous soon enough

cBay Rating:
Default

bump
icefisherman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-12-2009, 03:15 AM   #19 (permalink)
Hey
CN Coder
 
Hey's Avatar
 
Join Date: Dec 2008
Posts: 704
Reputation: 98
Hey will become famous soon enough

cBay Rating:
Send a message via MSN to Hey
Default

i took this class last year at ISU, cmon, dont be so lazy, its an easy class
__________________
"From now on we will play with 12 men on the field and I will be the 12th man kicking their butts from heaven."

Last edited by Hey; 04-12-2009 at 04:14 AM..
Hey is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
bored, coms, homework, java


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java question noxify General 1 11-06-2008 07:21 PM
Java or c++? zero Chit Chat 10 10-26-2008 07:02 PM
Java Programming Teacher....at 16 Ryutso Chit Chat 19 09-18-2008 04:20 PM
Java Programming Slashmolder General 15 09-04-2008 08:29 AM




Powered by vBulletin
Copyright © 2000-2008 Jelsoft Enterprises Limited.
Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.