Hi!
I am trying to write a DVD class that will model a DVD in several ways. I wrote a test driver program to exercise my class. I want each DVD to have a fake serial number. The first number should start at 1 and increase.
I'm having trouble writing this code because I am SOOOOOO new at java, so i have no skill at all, haha!
My program needs to have these DVD Public "Constants" (used in method interface)
REGION_FREE (0) which won't interfere with the assigned region codes
NTSC_FORMAT (1)
PAL_FORMAT (2)
DVD_SECTOR_SIZE (2048) (in Bytes)
and these DVD Methods
1. DVD(String title, int region, int format, double length) - creates a DVD with a title, region code, format, and with a specific length in minutes)
2. static String getClassAuthor() - returns name of author
3. double getLength() - returns length of dvd in minutes
4. long getSectorNumber( double minutes ) - retrieve sector number associated with a time stamp assuming the video rate for the movie is 4.096 Mbps and the first movie sector is 1024. (Assume that Mbps is 10^6 bits per second).
5. int getRegion() - returns the region code
6. String getTitle() - returns the title of the DVD
7. int getSerialNumber() - return the serial number of the DVD
8. String toString() - returns a text representation of the DVD:
"serial_number,Title,Region,Format,numberMinut es). Such as "1,Shrek II,1,1,105". The default double to string conversion is acceptable.
This is my driver code that i will use for interface with my program... - /*
-
* File: Driver2.java
-
* Copy: Copyright (c) by Dalton S. Nelson, All Rights Reserved
-
* Vers: 1.0.0 January 23, 2008 dsn -- original coding
-
*/
-
-
public class Driver2 {
-
-
public static void main(String[] args) {
-
-
System.out.println( "Spring 2008 P2 by " + DVD.getClassAuthor());
-
-
DVD dvd1 = new DVD( "Shrek II", 1, DVD.NTSC_FORMAT, 105.);
-
DVD dvd2 = new DVD( "Gone with the Wind", DVD.REGION_FREE,
-
DVD.NTSC_FORMAT, 222.);
-
-
System.out.println( dvd1 );
-
System.out.println( dvd2 );
-
-
System.out.println( "Last Sectors:");
-
System.out.println( "For \"" + dvd1.getTitle() + "\":" +
-
dvd1.getSectorNumber(dvd1.getLength()) );
-
System.out.println( "For \"" + dvd2.getTitle() + "\":" +
-
dvd1.getSectorNumber(dvd2.getLength()) );
-
-
}
-
}
Can anyone help me write this? It looks like a lot of fun but I am so new to this I don't even know!!!
Thanks!!!!
17 2901
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.
Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.
Then when you are ready post a new question in this thread.
MODERATOR
ok, so i staretd looking harder at this and this is what i have so far...it compiles fine, but then i look in the interactions window (there is no GUI) and i get this error "No 'main' method in 'DVD' with arguments: ([Ljava.lang.String;)." Here's my code...with my test case
------------------------------------------------------------
Test code...
------------------------------------------------------------ - public class Driver2 {
-
-
public static void main(String[] args) {
-
-
System.out.println( "Spring 2008 P2 by " + DVD.getClassAuthor());
-
-
DVD dvd1 = new DVD( "Shrek II", 1, DVD.NTSC_FORMAT, 105.);
-
DVD dvd2 = new DVD( "Gone with the Wind", DVD.REGION_FREE,
-
DVD.NTSC_FORMAT, 222.);
-
-
System.out.println( dvd1 );
-
System.out.println( dvd2 );
-
-
System.out.println( "Last Sectors:");
-
System.out.println( "For \"" + dvd1.getTitle() + "\":" +
-
dvd1.getSectorNumber(dvd1.getLength()) );
-
System.out.println( "For \"" + dvd2.getTitle() + "\":" +
-
dvd1.getSectorNumber(dvd2.getLength()) );
-
-
}
-
}
Any help would be greatly appreciated!! As you can see I am really trying here...also, i need help forming the getSectorNumber(double minutes) to work. Not sure how to do that one.
Thanks!!
DVD isn't the class with a main method, Driver2 is. You launch your program from the command line by writing:
not
Or are you using an IDE?
Hey,
You were exactly right...but when I run the code, my output looks like this...
Spring 2008 P2 by Joseph D. Marcrum, III
Serial_Number: 2
Title: Shrek II
Region: 0
Format: 0
Length: 105.0
Serial_Number: 2
Title: Gone with the Wind
Region: 0
Format: 0
Length: 222.0
Last Sectors:
For "Shrek II":0
For "Gone with the Wind":0
---------------------------------------------------
So basically, it's not running correctly yet. It's not generating a random serial_number for the DVD and isn't showing the sectors correctly, nor the region or the format...what could be wrong? It seems such basic coding?
Hey,
You were exactly right...but when I run the code, my output looks like this...
Spring 2008 P2 by Joseph D. Marcrum, III
Serial_Number: 2
Title: Shrek II
Region: 0
Format: 0
Length: 105.0
Serial_Number: 2
Title: Gone with the Wind
Region: 0
Format: 0
Length: 222.0
Last Sectors:
For "Shrek II":0
For "Gone with the Wind":0
---------------------------------------------------
So basically, it's not running correctly yet. It's not generating a random serial_number for the DVD and isn't showing the sectors correctly, nor the region or the format...what could be wrong? It seems such basic coding?
I am seeing a couple of things....
1. In my constructor, four arguments assigned at the objects initialization, but i have only used two, and one cannot be used (sectorNumber), as it is not one of the arguments.
2. The getSectorNumber must be a long parameter, because the values being returned are potentially long integer items. So, i must specify the method as having a return type of long, and by definition, i must assign it to a long variable as well (so my sectorNumber must be long, too)? right? how to do that?
3. I am assigning random number to the serialNumber. According to the spec, these must in (at the Task heading), serial number “start at 1 and increase). I ACTUALLY cannot assign serialNumber through the constructor, since it is not one of the parameters. How might be done?
4. I have a series of “set” methods as well. There’s really nothing wrong with them but based on the spec, they shouldn't be necessary at this point. What do you think?
If you want to generate a random number, use java.util.Random. You may generate duplicates, however. An alternate approach would be to assign consecutive numbers: 1, 2, 3, 4...
I am seeing a couple of things...
3. I am assigning random number to the serialNumber. According to the spec, these must in (at the Task heading), serial number “start at 1 and increase). I ACTUALLY cannot assign serialNumber through the constructor, since it is not one of the parameters. How might be done?
1. Don't pass a serialNumber to the constructor.
2. Assign the next serialNumber in the constructor, however. Do you know how to remember the last serial number?
1. Don't pass a serialNumber to the constructor.
2. Assign the next serialNumber in the constructor, however. Do you know how to remember the last serial number?
No not sure of that...how would you suggest the best way to go about that?
No not sure of that...how would you suggest the best way to go about that?
Also, what about that sector number stuff...the long thing? What? lol
1. Don't pass a serialNumber to the constructor.
2. Assign the next serialNumber in the constructor, however. Do you know how to remember the last serial number?
In C++ i used scanf(), but i don't know what to use in java. Any hints?
In C++ i used scanf(), but i don't know what to use in java. Any hints?
Huh? Are we talking about the same thing? Who mentioned I/O? I was going to suggest using a class variable (static field) to remember the last id used.
Huh? Are we talking about the same thing? Who mentioned I/O? I was going to suggest using a class variable (static field) to remember the last id used.
if i do this though... - /**
-
* Query: returns the DVD serial number
-
*/
-
public static int getSerialNumber()
-
{
-
return serialNumber; // returns the serial number
-
}
i get an error...because of how ive defined it above...
Error: non-static variable serialNumber cannot be referenced from a static object
if i do this though... - /**
-
* Query: returns the DVD serial number
-
*/
-
public static int getSerialNumber()
-
{
-
return serialNumber; // returns the serial number
-
}
i get an error...because of how ive defined it above...
Error: non-static variable serialNumber cannot be referenced from a static object
I haven't read all the posts in this thread yet so I could be off topic here but your specs do not say that serialNumber should be static. Read your program specs again.
if i do this though... - /**
-
* Query: returns the DVD serial number
-
*/
-
public static int getSerialNumber()
-
{
-
return serialNumber; // returns the serial number
-
}
i get an error...because of how ive defined it above...
Error: non-static variable serialNumber cannot be referenced from a static object
Ok, i figured it out finally... - /**
-
* Query: returns the DVD serial number
-
*/
-
public static int getSerialNumber()
-
{
-
serialNumber = serialNumber + 1;
-
return serialNumber; // returns the serial number
-
}
I made the serialNumber variable a public static int up top in my declarations as well. - public static int serialNumber = 0; // int static variable for the DVD serialNumber
So my ONLY other question that exists is....i tried to convert getsectorNumber to long and pass double minutes through it....but i get nothing in my output. According to the project spec up top, i should be getting...something. - /**
-
* Query: returns the DVD sector number
-
*/
-
public long getSectorNumber(double length)
-
{
-
return (long)sectorNumber; // returns the sector number
-
}
Static variables are shared among all instances of the same class. So all your DVDs would have the same serial number. The advice given by SmallDaddy was to use a static variable to remember the last id that was generated rather than to use a static serial number.
So my ONLY other question that exists is....i tried to convert getsectorNumber to long and pass double minutes through it....but i get nothing in my output. According to the project spec up top, i should be getting...something. - /**
-
* Query: returns the DVD sector number
-
*/
-
public long getSectorNumber(double length)
-
{
-
return (long)sectorNumber; // returns the sector number
-
}
This is confusing. Is the SectorNumber a long or a double? Choose one and stick to it. Then the code will be trivial: just another field+setter+getter. Nothing to it. But the code quoted here makes no sense. You pass it parameter length, which is not used in the body of the method! Stare at this code and think about what you really want to do. Why is a simple getter passed any parameter?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shane Story |
last post by:
Have an app and would like to allow easy addition of MYAPP.EXE /F /P (for
example)
my prog with command line args, as a job to be run.
Would like to make it easier on the user to run the app. ...
|
by: Marcus |
last post by:
Hi,
I am a newbie at C#. Here is my current problem:
I want my application to iterate through the list of tasks presented in
task manager. I want it to look at the task names and if a certain...
|
by: Laserson |
last post by:
Hi all! I have a very difficult task for me and i can't so it. My task:
I have created an application. But how to determine that it is not
responding??? You can see it when windows add "Not...
|
by: oll3i |
last post by:
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.lang.reflect.*;
public class Exec1 extends JFrame...
|
by: zakaria2710 |
last post by:
Would u help me with this task, I am new in C++ programming, this codes have alot of errors, I have never work with graphs before, I am using Borlard C++ Ver 5.02. I was told u can not run a graph...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |