473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Task - DVD Class

105 100+
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...
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * File: Driver2.java
  3.  * Copy: Copyright (c)  by Dalton S. Nelson, All Rights Reserved
  4.  * Vers: 1.0.0 January 23, 2008 dsn -- original coding
  5.  */
  6.  
  7. public class Driver2 {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         System.out.println( "Spring 2008 P2 by " + DVD.getClassAuthor());
  12.  
  13.         DVD dvd1 = new DVD( "Shrek II", 1, DVD.NTSC_FORMAT, 105.);
  14.         DVD dvd2 = new DVD( "Gone with the Wind", DVD.REGION_FREE, 
  15.                             DVD.NTSC_FORMAT, 222.);
  16.  
  17.         System.out.println( dvd1 );
  18.         System.out.println( dvd2 );
  19.  
  20.         System.out.println( "Last Sectors:");
  21.         System.out.println( "For \"" + dvd1.getTitle() + "\":" + 
  22.                              dvd1.getSectorNumber(dvd1.getLength()) );
  23.         System.out.println( "For \"" + dvd2.getTitle() + "\":" + 
  24.                 dvd1.getSectorNumber(dvd2.getLength()) );
  25.  
  26.     }
  27. }
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!!!!
Jan 25 '08 #1
17 2901
BigDaddyLH
1,216 Expert 1GB
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
Jan 25 '08 #2
jmarcrum
105 100+
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

Expand|Select|Wrap|Line Numbers
  1. /**
  2. * Beginning of the DVD class
  3. */
  4. public class DVD
  5. {
  6.     public static final int REGION_FREE = 0; // Final variable for the DVD region_free code
  7.     public static final int NTSC_FORMAT = 1; // Final variable for the DVD NTSC_format
  8.     public static final int PAL_FORMAT = 2; // Final variable for the DVD PAL_format
  9.     public static final int DVD_SECTOR_SIZE = 2048; // Final variable for the DVD sector size in bytes
  10.  
  11.     private String title; // String variable for the DVD title
  12.     private int region; // int variable for the DVD region
  13.     private int format; // int variable for the DVD format
  14.     private int serialNumber = 0; // int variable for the DVD format
  15.     private double length = 0.0; // double variable for the DVD length in minutes
  16.     private double minutes = 0.0; // double variable for minutes
  17.     private int sectorNumber = 0; // int variable for the DVD length in minutes
  18.  
  19.     /**
  20.     * Constructor: builds the DVD object
  21.     */
  22.     public DVD(String title, int region, int format, double length)
  23.     {
  24.         this.title = title; // initialization of title
  25.         this.sectorNumber = sectorNumber; // initialization of sector number
  26.         this.length = length; // initialization of length
  27.  
  28.         this.serialNumber = (int)((Math.random() + 1) + 1); // generates a random number for the serial number
  29.     }    
  30.  
  31.     //Queries:-----------------------------------------
  32.  
  33.     /**
  34.     * Query: getClassAuthor
  35.     */ 
  36.     public static String getClassAuthor() // returns name of class’ author (my name)
  37.     {  
  38.         return "Joseph D. Marcrum, III"; // returns my name
  39.     }
  40.  
  41.     /**
  42.     * Query: returns the DVD sector number
  43.     */
  44.     public int getSectorNumber(double length)
  45.     {
  46.       return sectorNumber; // returns the sector number
  47.     }
  48.  
  49.     /**
  50.     * Query: returns the DVD serial number
  51.     */
  52.     public int getSerialNumber()
  53.     {
  54.       return serialNumber; // returns the serial number
  55.     }
  56.  
  57.     /**
  58.     * Query: returns the DVD title
  59.     */
  60.     public String getTitle()
  61.     {
  62.       return title; // returns the title
  63.     }
  64.  
  65.     /**
  66.     * Query: returns the DVD region
  67.     */
  68.     public int getRegion()
  69.     {
  70.       return region; // returns the region
  71.     }
  72.  
  73.     /**
  74.     * Query: returns the DVD format
  75.     */
  76.     public int getFormat()
  77.     {
  78.       return format; // returns the format
  79.     }
  80.  
  81.     /**
  82.     * Query: returns the DVD length
  83.     */
  84.     public double getLength()
  85.     {
  86.       return length; // returns the length
  87.     }
  88.  
  89.     //Commands:--------------------------------------------
  90.  
  91.     /**
  92.     * Command: sets sector number for the DVD
  93.     */
  94.     public void setsectorNumber(int newsectorNumber)
  95.     {
  96.       sectorNumber = newsectorNumber; // sets new sector number
  97.     }
  98.  
  99.     /**
  100.     * Command: sets a serial number for the DVD
  101.     */
  102.     public void setserialNumber(int newserialNumber)
  103.     {
  104.       serialNumber = newserialNumber; // sets new serial number
  105.     }
  106.  
  107.     /**
  108.     * Command: sets a title for the DVD
  109.     */
  110.     public void setTitle(String newTitle)
  111.     {
  112.       title = newTitle; // sets new title
  113.     }
  114.  
  115.     /**
  116.     * Command: sets a region for the DVD
  117.     */
  118.     public void setRegion(int newRegion)
  119.     {
  120.       region = newRegion; // sets new region
  121.     }
  122.  
  123.     /**
  124.     * Command: sets a format for the DVD
  125.     */
  126.     public void setFormat(int newFormat)
  127.     {
  128.       format = newFormat; // sets new format
  129.     }
  130.  
  131.     /**
  132.     * Command: sets the length for the DVD
  133.     */
  134.     public void setlength(double numMinutes)
  135.     {
  136.       length = numMinutes; // sets the DVD length
  137.     }    
  138.  
  139.     /**
  140.     * Command: toString
  141.     */
  142.     public String toString() // returns a text representation of all the data pertaining to a given DVD: "serial number, title, region, format, length."
  143.     {                             
  144.         // return of the full DVD printable object - formatted as a form
  145.         //  (properly formatted for display, and without the quotes).
  146.         return "Serial_Number: " + getSerialNumber() + "\n" + 
  147.           "Title: " + getTitle() + "\n" + 
  148.           "Region: " + getRegion() + "\n" + 
  149.           "Format: " + getFormat() + "\n" + 
  150.           "Length: " + getLength(); 
  151.     }
  152. }
------------------------------------------------------------

Test code...

------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. public class Driver2 {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         System.out.println( "Spring 2008 P2 by " + DVD.getClassAuthor());
  6.  
  7.         DVD dvd1 = new DVD( "Shrek II", 1, DVD.NTSC_FORMAT, 105.);
  8.         DVD dvd2 = new DVD( "Gone with the Wind", DVD.REGION_FREE, 
  9.                             DVD.NTSC_FORMAT, 222.);
  10.  
  11.         System.out.println( dvd1 );
  12.         System.out.println( dvd2 );
  13.  
  14.         System.out.println( "Last Sectors:");
  15.         System.out.println( "For \"" + dvd1.getTitle() + "\":" + 
  16.                              dvd1.getSectorNumber(dvd1.getLength()) );
  17.         System.out.println( "For \"" + dvd2.getTitle() + "\":" + 
  18.                 dvd1.getSectorNumber(dvd2.getLength()) );
  19.  
  20.     }
  21. }
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!!
Jan 28 '08 #3
BigDaddyLH
1,216 Expert 1GB
DVD isn't the class with a main method, Driver2 is. You launch your program from the command line by writing:

Expand|Select|Wrap|Line Numbers
  1. java Driver2
not

Expand|Select|Wrap|Line Numbers
  1. java DVD
Or are you using an IDE?
Jan 28 '08 #4
jmarcrum
105 100+
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?
Jan 28 '08 #5
jmarcrum
105 100+
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?
Jan 28 '08 #6
BigDaddyLH
1,216 Expert 1GB
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...
Jan 28 '08 #7
BigDaddyLH
1,216 Expert 1GB
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?
Jan 28 '08 #8
jmarcrum
105 100+
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?
Jan 28 '08 #9
jmarcrum
105 100+
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
Jan 28 '08 #10
BigDaddyLH
1,216 Expert 1GB
Also, what about that sector number stuff...the long thing? What? lol
Type long is a 64-bit integer, just as type int is a 32-bit integer. There's no special magic to working with it.

http://java.sun.com/docs/books/tutor...datatypes.html
Jan 28 '08 #11
jmarcrum
105 100+
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?
Jan 29 '08 #12
BigDaddyLH
1,216 Expert 1GB
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.
Jan 29 '08 #13
jmarcrum
105 100+
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...

Expand|Select|Wrap|Line Numbers
  1. /**
  2.     * Query: returns the DVD serial number
  3.     */
  4.     public static int getSerialNumber()
  5.     {
  6.       return serialNumber; // returns the serial number
  7.     }
i get an error...because of how ive defined it above...

Error: non-static variable serialNumber cannot be referenced from a static object
Jan 29 '08 #14
r035198x
13,262 8TB
if i do this though...

Expand|Select|Wrap|Line Numbers
  1. /**
  2.     * Query: returns the DVD serial number
  3.     */
  4.     public static int getSerialNumber()
  5.     {
  6.       return serialNumber; // returns the serial number
  7.     }
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.
Jan 29 '08 #15
jmarcrum
105 100+
if i do this though...

Expand|Select|Wrap|Line Numbers
  1. /**
  2.     * Query: returns the DVD serial number
  3.     */
  4.     public static int getSerialNumber()
  5.     {
  6.       return serialNumber; // returns the serial number
  7.     }
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...

Expand|Select|Wrap|Line Numbers
  1. /**
  2.     * Query: returns the DVD serial number
  3.     */
  4.     public static int getSerialNumber()
  5.     {
  6.       serialNumber = serialNumber + 1;
  7.       return serialNumber; // returns the serial number
  8.     }
I made the serialNumber variable a public static int up top in my declarations as well.

Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1. /**
  2.     * Query: returns the DVD sector number
  3.     */
  4.     public long getSectorNumber(double length)
  5.     {
  6.       return (long)sectorNumber; // returns the sector number
  7.     }
Jan 29 '08 #16
r035198x
13,262 8TB
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.
Jan 29 '08 #17
BigDaddyLH
1,216 Expert 1GB
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.

Expand|Select|Wrap|Line Numbers
  1. /**
  2.     * Query: returns the DVD sector number
  3.     */
  4.     public long getSectorNumber(double length)
  5.     {
  6.       return (long)sectorNumber; // returns the sector number
  7.     }
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?
Jan 29 '08 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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. ...
6
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...
4
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...
0
oll3i
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
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
0
BarryA
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.