The code is missing the ending }s
Where is the Time1 class code?
Does the code you have compile and execute?
If not, copy the full text of any error messages and paste them here if you need help.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
The code is missing the ending }s
Where is the Time1 class code?
Does the code you have compile and execute?
If not, copy the full text of any error messages and paste them here if you need help.
If you don't understand my answer, don't ignore it, ask a question.
Sorry, I don't see how the posted code can work with the missing parts.it works
Please post the complete code that will compile and execute and create some output.
I'm done for tonight. Back tomorrow.
If you don't understand my answer, don't ignore it, ask a question.
this outputs the nextpackage com.company; public class Time1StudentTester { public static void main(String [] args) { System.out.println("\n********** Test Time1 - Started **********\n"); System.out.println("\n1. Testing Constructors and toString:"); Time1 t1 = new Time1(17, 45); System.out.println("\tt1=" + t1); Time1 t2 = new Time1(t1); System.out.println("\tt2=" + t2); System.out.println("\n********** Test Time1 - Finished **********\n"); } }
and i need it to be the same1. Testing Constructors and toString: t1=17:45 t2=00:00
Where is the code for the Time1 class?
If you don't understand my answer, don't ignore it, ask a question.
package com.company; public class Time1 { private int _hour; private int _minute; public Time1(int h, int m) { this._hour = (((h >= 0) && (h < 23)) ? h : 0); this._minute = (((m >= 0) && (m < 59)) ? m : 0); } public String toString() { return String.format("%02d:%02d",_hour,_minute); } }
That code does not compile without errors.
The code must compile without errors to be able to execute it for testing.
If you have code that compiles without errors, please post it.
If you don't understand my answer, don't ignore it, ask a question.
Please copy the full text of the error messages you get and paste it here if you need help fixing it.how to continue from here
If you don't understand my answer, don't ignore it, ask a question.
Ok, that error says the Time1 class needs a constructor that takes a Time1 object as an argument.
You posted some code in post#13 that declared a constructor but did not have any statements in it to get the needed data from the Time1 object that was passed to the constructor.
If you don't understand my answer, don't ignore it, ask a question.
The error message says you need a constructor that takes a Time1 object as its argument.
The code in post#13 declares that constructor.
Copy that code into the class's declaration.
Add code to that constructor that copies the values from the Time1 object into the class's variables.
If you don't understand my answer, don't ignore it, ask a question.
Replaced with what? Post the new code that gives the same results.this line can be replaced and still get same result
Why not? If you get errors, copy the full text and paste it here.i just figured it out that i cant use string.format
If you don't understand my answer, don't ignore it, ask a question.
Sorry, I have no idea where that code is located or what errors it is causing.
Please post the full code that creates the error and the full text of the error messages you get.
If you don't understand my answer, don't ignore it, ask a question.
are you sure you know java ???? cause for now your not helping at all
I am not able to look over your shoulder to see what you are doing. I need you to post the code that is giving the problem and the error messages it gives so I can help.
You have been making progress and almost have it working. Don't give up now.cause for now your not helping at all
Note: I do not write code that students can copy and paste into their programs. I try to lead a student to find the answer.
I have been posting on this forum since 2010 and have posted over 22K times.are you sure you know java
If you don't understand my answer, don't ignore it, ask a question.
i am posting over and over and over and one more time over
this is the code test for the class file Time1.javapackage com.company; import com.company.Time1; public class Time1StudentTester { public static void main(String [] args) { System.out.println("\n1. Testing Constructors and toString:"); Time1 t1 = new Time1(17, 45); System.out.println("\tt1=" + t1); Time1 t2 = new Time1(t1); System.out.println("\tt2=" + t2); System.out.println("\n2. Testing accessors and mutators:"); t1.setHour(20); t1.setMinute(10); System.out.println("\tt1=" + t1); System.out.println("\tHour of t1=" + t1.getHour()); System.out.println("\tMinute of t1=" + t1.getMinute()); System.out.println("\n4. Testing equals method:"); Time1 t3=new Time1(12, 34); Time1 t4=new Time1(23, 45); System.out.println("\tt3=" + t3); System.out.println("\tt4=" + t4); if(t3.equals(t4)) System.out.println("\tt3 is the same time as t4"); else System.out.println("\tt3 isn't the same time as t4"); System.out.println("\n5. Testing before method:"); System.out.println("\n6. Testing after method:"); System.out.println("\n7. Testing difference method:"); t1=new Time1(11, 25); t2=new Time1(10, 15); System.out.println("\tt1=" + t1); System.out.println("\tt2=" + t2); System.out.println("\n8. Testing addMinutes method:"); System.out.println("\tt1=" + t1); System.out.println("\n********** Test Time1 - Finished **********\n"); } }
now this is the final output i need to recive
and now this is my time1 class file********** Test Time1 - Started ********** 1. Testing Constructors and toString: t1=17:45 t2=17:45 t33=00:00 2. Testing accessors and mutators: t1=20:10 Hour of t1=20 Minute of t1=10 2. Testing out of range setters: t1=00:00 Hour of t33=0 Minute of t33=0 3. Testing minFromMidnight method: t1=10:15 Minutes from midnight of t1=615 3. Testing minFromMidnight method: t33=00:00 Minutes from midnight of t33=0 3. Testing minFromMidnight method: t1=23:59 Minutes from midnight of t1=1439 4. Testing equals method: t3=12:34 t4=23:45 t33=23:45 t3=12:34 = t4=23:45 ? false t33=23:45 = t4=23:45 ? true t34=23:46 = t4=23:45 ? false t35=22:45 = t4=23:45 ? false 5. Testing before method: t3=12:34 before t4=23:45 ? true t33=23:45 before t4=23:45 ? false t34=23:46 before t4=23:45 ? false t35=22:45 before t4=23:45 ? true t35=23:44 before t4=23:45 ? true 6. Testing after method: t3=12:34 after t4=23:45 ? false t33=23:45 after t4=23:45 ? false t34=23:46 after t4=23:45 ? true t35=22:45 after t4=23:45 ? false t35=23:44 after t4=23:45 ? false t4=23:45 after t3=12:34 ? true tt4=23:45 after t33=23:45 ? false tt4=23:45 after t34=23:46 ? false tt4=23:45 after t35=22:45 ? true tt4=23:45 after t36=23:44 ? true 7. Testing difference method: t1=11:25 t2=10:15 The difference between 11:25 and 10:15 is : 70 min The difference between 23:45 and 23:45 is : 0 min The difference between 23:45 and 23:46 is : -1 min The difference between 23:45 and 22:45 is : 60 min The difference between 23:45 and 23:44 is : 1 min 8. Testing addMinutes method: t1=11:25 Adding 10 minutes to t1=11:35 Adding 20 minutes to 23:45= 00:05 Adding 48 hours and -5 min to 23:45= 23:40 Adding 48 hours and +5 min to 23:45= 23:50 Adding 48 hours to 23:45= 23:45 Adding -48 hours to 23:45= 23:45 Adding -48 hours to 23:45= 23:45 Adding -10 minutes to 00:05= 23:55 Adding -48 hours and -6 min to 00:05= 23:59 Adding -48 hours and +6 min to 00:05= 00:11 ********** Test Time1 - Finished **********
from here how do i need to continue to eventually recive the final outputpackage com.company; public class Time1 { private int _hour; private int _minute; public Time1(int h, int m) { this._hour = (((h >= 0) && (h < 23)) ? h : 0); this._minute = (((m >= 0) && (m < 59)) ? m : 0); } public Time1(Time1 t2) { getHour (); getMinute (); } public int getHour() { return _hour; } public int getMinute() { return _minute; } public void setHour(int _hour) { this._hour = _hour; } public void setMinute(int _minute) { this._minute = _minute; } }
Where did all that code come from?the final output
This code does NOT get the time values from the argument that was passed to it:The calls to the methods should use the reference to the passed object : t2.get.... to get the valuespublic Time1(Time1 t2) { getHour (); getMinute (); }
and then those values need to be assigned to the local variables.
What is the "final output" that you are looking for? What problems are you having writing the code for that output?
If you don't understand my answer, don't ignore it, ask a question.
and again this is the final output i need to recive i am brand new to java so help me please reach this output********** Test Time1 - Started ********** 1. Testing Constructors and toString: t1=17:45 t2=17:45 t33=00:00 2. Testing accessors and mutators: t1=20:10 Hour of t1=20 Minute of t1=10 2. Testing out of range setters: t1=00:00 Hour of t33=0 Minute of t33=0 3. Testing minFromMidnight method: t1=10:15 Minutes from midnight of t1=615 3. Testing minFromMidnight method: t33=00:00 Minutes from midnight of t33=0 3. Testing minFromMidnight method: t1=23:59 Minutes from midnight of t1=1439 4. Testing equals method: t3=12:34 t4=23:45 t33=23:45 t3=12:34 = t4=23:45 ? false t33=23:45 = t4=23:45 ? true t34=23:46 = t4=23:45 ? false t35=22:45 = t4=23:45 ? false 5. Testing before method: t3=12:34 before t4=23:45 ? true t33=23:45 before t4=23:45 ? false t34=23:46 before t4=23:45 ? false t35=22:45 before t4=23:45 ? true t35=23:44 before t4=23:45 ? true 6. Testing after method: t3=12:34 after t4=23:45 ? false t33=23:45 after t4=23:45 ? false t34=23:46 after t4=23:45 ? true t35=22:45 after t4=23:45 ? false t35=23:44 after t4=23:45 ? false t4=23:45 after t3=12:34 ? true tt4=23:45 after t33=23:45 ? false tt4=23:45 after t34=23:46 ? false tt4=23:45 after t35=22:45 ? true tt4=23:45 after t36=23:44 ? true 7. Testing difference method: t1=11:25 t2=10:15 The difference between 11:25 and 10:15 is : 70 min The difference between 23:45 and 23:45 is : 0 min The difference between 23:45 and 23:46 is : -1 min The difference between 23:45 and 22:45 is : 60 min The difference between 23:45 and 23:44 is : 1 min 8. Testing addMinutes method: t1=11:25 Adding 10 minutes to t1=11:35 Adding 20 minutes to 23:45= 00:05 Adding 48 hours and -5 min to 23:45= 23:40 Adding 48 hours and +5 min to 23:45= 23:50 Adding 48 hours to 23:45= 23:45 Adding -48 hours to 23:45= 23:45 Adding -48 hours to 23:45= 23:45 Adding -10 minutes to 00:05= 23:55 Adding -48 hours and -6 min to 00:05= 23:59 Adding -48 hours and +6 min to 00:05= 00:11 ********** Test Time1 - Finished **********
Ok, it is better to work on one problem at a time.
What is the program's current output? Copy the program's output and paste it here.
Add some comments to the print out showing where it needs to be changed.
For example:1. Testing Constructors and toString: t1=17:45 t2=17:45 t33=00:00 <<<<<<<<< THIS should be t33=11:22
Did you see my comments about one of the Time1's constructors? It needs to be changed to get the values from the passed argument and saved in the current object.
If you don't understand my answer, don't ignore it, ask a question.
current output1. Testing Constructors and toString: t1=com.company.Time1@1b6d3586 t2=com.company.Time1@4554617c 2. Testing accessors and mutators: t1=com.company.Time1@1b6d3586 Hour of t1=20 Minute of t1=10 4. Testing equals method: t3=com.company.Time1@74a14482 t4=com.company.Time1@1540e19d t3 isn't the same time as t4 5. Testing before method: 6. Testing after method: 7. Testing difference method: t1=com.company.Time1@677327b6 t2=com.company.Time1@14ae5a5 8. Testing addMinutes method: t1=com.company.Time1@677327b6 ********** Test Time1 - Finished **********
I don't see any comments as I requested on this line. I assume that is not what is desired.t1=com.company.Time1@1b6d3586
The value after the = is the String returned by the Object class's default toString method. The Time1 method needs a toString method that returns the String you want to see.
What happened to the toString method that was in earlier versions of the Time1 class? Copy it into the new version. See post#31
If you don't understand my answer, don't ignore it, ask a question.