I am new to C Sharp, and have been working on this code for a few days. I keep getting a StackoverFlowException and I don't know what that means, since we haven't covered it in class. Any guidance would be greatful. Thanks! - using System;
-
public class BookDemo
-
{
-
public static void Main()
-
{
-
Book Book = new Book();
-
TextBook Text = new TextBook();
-
CoffeeTableBook Coffee = new CoffeeTableBook();
-
-
Book.Isbn = "0001112223330 ";
-
Book.Title = "The Story of Day of the Dead";
-
Book.Author = "Victor Juan";
-
Book.Price = 99.95;
-
-
Book.Isbn = "2323565678 ";
-
Book.Title = "The Adventure guide";
-
Book.Author = "Steven Chard";
-
Book.Price = 55.00;
-
-
Text.Isbn = "1113334444569 ";
-
Text.Title = "Computers, How they Work";
-
Text.Author = "John Smith";
-
Text.GradeLevel = 10;
-
Text.Price = 132.00;
-
-
Text.Isbn = "9995558475890 ";
-
Text.Title = "The Fundementals of Math";
-
Text.Author = "Marcia Brown";
-
Text.GradeLevel = 3;
-
Text.Price = 56.25;
-
-
Coffee.Isbn = "1932279288 ";
-
Coffee.Title = "Household Baggage";
-
Coffee.Author = "Marna Krajeski";
-
Coffee.Price = 46.25;
-
-
Coffee.Isbn = "0757300065 ";
-
Coffee.Title = "Chicken Soup for the Soul of America";
-
Coffee.Author = "Jack Canfield";
-
Coffee.Price = 125.75;
-
-
Console.WriteLine("ISBN: {0}", Book.Isbn);
-
Console.WriteLine(" {1} by {2} sells for {3}",
-
Book.Title, Book.Author,
-
Book.Price.ToString("C"));
-
-
Console.WriteLine("\nISBN: {0}", Text.Isbn);
-
Console.WriteLine(" {1} by {2} for grade {3} sells for {4}",
-
Text.Title, Text.Author,
-
Text.GradeLevel,
-
Text.Price.ToString("C"));
-
-
Console.WriteLine("\nISBN: {0}", Coffee.Isbn);
-
Console.WriteLine(" {1} by {2} sells for {3}",
-
Coffee.Title, Coffee.Author,
-
Coffee.Price.ToString("C"));
-
}
-
}
-
public class Book
-
{
-
public string Isbn { get; set; }
-
public string Title { get; set; }
-
public string Author { get; set; }
-
public double Price { get; set; }
-
}
-
public class TextBook : Book
-
{
-
private int gradeLevel;
-
const double LOWPRICE = 20.00;
-
const double HIGHPRICE = 80.00;
-
public int GradeLevel
-
{
-
get
-
{
-
return gradeLevel;
-
}
-
set
-
{
-
gradeLevel = value;
-
}
-
}
-
new public double Price
-
{
-
get
-
{
-
return Price;
-
}
-
set
-
{
-
if (value < LOWPRICE)
-
Price = LOWPRICE;
-
else if (value > HIGHPRICE)
-
Price = HIGHPRICE;
-
else Price = value;
-
}
-
}
-
}
-
public class CoffeeTableBook : Book
-
{
-
public const double LOWPRICE = 35.00;
-
public const double HIGHPRICE = 100.00;
-
new public double Price
-
{
-
get
-
{
-
return Price;
-
}
-
set
-
{
-
if (value < LOWPRICE)
-
Price = LOWPRICE;
-
else if (value > HIGHPRICE)
-
Price = HIGHPRICE;
-
else Price = value;
-
}
-
}
-
}
4 1553
A StackOverFlowException is thrown for execution stack overflow errors, typically in case of a very deep or unbounded recursion.
My question is does your code compile? The only obvious error that I see is the line.
Book Book = new Book();
You are using a class name as a variable name.
No my program does not compile, when I go to debug it says the error and then highlights the first curly brace in the below method. -
{
-
if (value < LOWPRICE)
-
Price = LOWPRICE;
-
else if (value > HIGHPRICE)
-
Price = HIGHPRICE;
-
else Price = value;
-
}
-
Compile your code first. Like hype is saying, Book can not be used as a var because its a class name.
And I dont know if this is OK:
"new public double Price"
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bart |
last post by:
Hi all
I don't understand globals between multiple modules in a python program. I
really don't. I've narrowed it down to the following two very simple
programs a.py and b.py. When I run a.py I...
|
by: Robert Nicholson |
last post by:
So I've got one page where I have an image inside a DIV with
text-align: center and the
image is correctly centered in that block. Making me think that
text-align will center the contents of a...
|
by: Jesee |
last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework
programming",i came across "Exception handing". Page 405 says
"If the stack overflow occurs within the CLR itself,your...
|
by: Wayne Wengert |
last post by:
I am using a datareader (dr1) to read through rows returned from a query. I
am getting the error: "No data exists for the row/column." at the "If
IsDbNull..." in the code below. The field "Photo1"...
|
by: Lee Crabtree |
last post by:
Okay, maybe I'm trying to use streams in some unacceptable way, but I'm
running into a few problems.
I need to be able to serialize a set of data and deserialize it in
another place. It seems...
|
by: Joshua Moore |
last post by:
/* Hi, I was hoping someone could help me with this problem. I did my
work and worked my way through the usual compiler messages, but I have
run against some problem I can't identify. The compiler...
|
by: Dave |
last post by:
When and what does .Net want to compile? I have a file called
upload.cs. I made changes to it. Tried to rebuild. But it won't
saying "the application is already precomiled." I would have...
|
by: Ben Thomas |
last post by:
Hello,
I have the following code which I don't understand why it works :
#include <iostream>
using namespace std;
void DontWork (unsigned int& i) {
cout << i << endl;
}
|
by: Stef Mientki |
last post by:
Terry Reedy wrote:
sorry, don't know how this happened, as I always copy/paste ?
AFAIK locals() == sys._getframe(0).f_locals
AFAIK, again one level up
weird, I use it in 2.5 and if I remember...
|
by: Thierry |
last post by:
Hello fellow pythonists,
I'm a relatively new python developer, and I try to adjust my
understanding about "how things works" to python, but I have hit a
block, that I cannot understand.
I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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: 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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |