SoftwareSales problem please help

error illegal start of expression line 31

Page 1 of 1

11 Replies - 1794 Views - Last Post: 25 August 2007 - 02:24 PM Rate Topic: -----

#1 allican57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-October 06

SoftwareSales problem please help

Posted 20 August 2007 - 09:45 AM

I'm getting an error message " illegal start on line 31 and cant find t.suspect code marked with :pirate: he problem


import java.util.Scanner;

public class SoftwareSales {

 	// Data Members
   private String  software, discount, or, more;
   private double sales, product, units, number;
   
   
   
		//Constructors
		public SoftwareSales() {
		
		software = software;
		discount = discount;
		or = or;
		more = more;
		
	  public SoftwareSales(String software, 
					String discount, String or, String more,
		double sales, double product, double units, double number){
			
		sales = v;
		product = x;
		units = y; 
		number = z;
	
	//Methods

	//Accessor Methods
	
	  public String getSales() {
		return sales;
	}
	  public String getProduct() {
		return product;
	}
	
	  public String getUnits() {
		return units;
	}
	
	  public String getNumber() {
		return number;
	}
	
	
	
	//Mutator Methods
	
		 public void setSales (double sales) {
		 sales = v;
	}
	
			public void setProduct(double product) {
		 product = x;
	}
	
			public void setUnits(double units) {
	  units = y;
	}
	
			public void setNumber(double number) {
	number = z;
		}
	};
	}
	}	
	


Pleas help!

This post has been edited by PennyBoki: 22 August 2007 - 08:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: SoftwareSales problem please help

#2 alpha02  Icon User is offline

  • Sexy DIC God
  • member icon

Reputation: 46
  • View blog
  • Posts: 803
  • Joined: 20-May 06

Re: SoftwareSales problem please help

Posted 20 August 2007 - 09:55 AM

You put a ; after the closing bracket of your constructor (at the end of the code, you have this):
}
};
}
}


Remove the ; and tell me the results.
Was This Post Helpful? 0
  • +
  • -

#3 allican57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-October 06

Re: SoftwareSales problem please help

Posted 20 August 2007 - 10:18 AM

View Postalpha02, on 20 Aug, 2007 - 09:55 AM, said:

You put a ; after the closing bracket of your constructor (at the end of the code, you have this):
}
};
}
}


Remove the ; and tell me the results.

I removed ";" and now get an additional compiler message"; expected" line 78
Was This Post Helpful? 0
  • +
  • -

#4 alpha02  Icon User is offline

  • Sexy DIC God
  • member icon

Reputation: 46
  • View blog
  • Posts: 803
  • Joined: 20-May 06

Re: SoftwareSales problem please help

Posted 20 August 2007 - 02:48 PM

I looked at your code more carefully, and I found many mistakes:

-You put a constructor in the other constructor!
-You used undefined variables (y,z, ...)
-You used wrong return types in the accessor methods
-You didn't use this.var = var, so the assignement you wrote had absolutely no effect.

I've included the corrected source below:

import java.util.Scanner;

public class SoftwareSales {
	// Data Members
	private String software, discount, or, more;
	private double sales, product, units, number;
	
	//Constructor
	public SoftwareSales(String software, String discount, String or, String more, double sales, double product, double units, double number){
		this.sales = sales;
		this.product = product;
		this.units = units;
		this.number = number;
		this.software = software;
		this.discount = discount;
		this.or = or;
		this.more = more;
	}
	
	//Methods
	public double getSales() {
		return this.sales;
	}
	public double getProduct() {
		return this.product;
	}
	public double getUnits() {
		return this.units;
	}
	public double getNumber() {
		return this.number;
	}
	
	
	
	//Mutator Methods
	
	public void setSales (double sales) {
		this.sales = sales;
	}
	
	public void setProduct(double product) {
		this.product = product;
	}
	
	public void setUnits(double units) {
		this.units = units;
	}
	
	public void setNumber(double number) {
		this.number = number;
	}
} 


If you need more explanations then reply.
Was This Post Helpful? 0
  • +
  • -

#5 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: SoftwareSales problem please help

Posted 22 August 2007 - 08:28 AM

Hi allican57, alpha02 corrected the code all you have to do is try to consider it, if you still have some trouble please share with us what is the issue you have trouble with.
Was This Post Helpful? 0
  • +
  • -

#6 allican57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-October 06

Re: SoftwareSales problem please help

Posted 22 August 2007 - 08:38 AM

Thanks so much. I seem to really be lost this. I have include the instructions for this problem, for you clarity only. I'm not asking you to do the work.I really want to learn java. I have read this complete chapter Three times now and seem to not be gtting through my thick skull wht I should add to this code from the second file (shown below).If you could show me the syntax for calling the setter/getters and how o implement he first if statement. I think i could finish the project.




/*A software company sells a package that retails for $99. Quantity discounts are given according to the following table:
Quantity Discount
1019 20% 2049 30% 5099 40% 100 or more 50%
Design a class that stores the number of units sold and has a method that returns the total cost of the purchase.
*/
import java.util.Scanner;

 class SoftwareSales {
	
	public static void main(String[] args) {
   
	// Data Members
   String software, discount, or, more;
   double sales, product, units, number;
	
   
	Scanner keyboard = new Scanner(System.in);{
	
	
		System.out.print("Please enter the number of units sold.");
		  keyboard.nextDouble();




View Postallican57, on 22 Aug, 2007 - 08:10 AM, said:

View Postalpha02, on 20 Aug, 2007 - 02:48 PM, said:

I looked at your code more carefully, and I found many mistakes:

-You put a constructor in the other constructor!
-You used undefined variables (y,z, ...)
-You used wrong return types in the accessor methods
-You didn't use this.var = var, so the assignement you wrote had absolutely no effect.

I've included the corrected source below:

import java.util.Scanner;

public class SoftwareSales {
	// Data Members
	private String software, discount, or, more;
	private double sales, product, units, number;
	
	//Constructor
	public SoftwareSales(String software, String discount, String or, String more, double sales, double product, double units, double number){
		this.sales = sales;
		this.product = product;
		this.units = units;
		this.number = number;
		this.software = software;
		this.discount = discount;
		this.or = or;
		this.more = more;
	}
	
	//Methods
	public double getSales() {
		return this.sales;
	}
	public double getProduct() {
		return this.product;
	}
	public double getUnits() {
		return this.units;
	}
	public double getNumber() {
		return this.number;
	}
	
	
	
	//Mutator Methods
	
	public void setSales (double sales) {
		this.sales = sales;
	}
	
	public void setProduct(double product) {
		this.product = product;
	}
	
	public void setUnits(double units) {
		this.units = units;
	}
	
	public void setNumber(double number) {
		this.number = number;
	}
} 


If you need more explanations then reply.

Was This Post Helpful? 0
  • +
  • -

#7 alpha02  Icon User is offline

  • Sexy DIC God
  • member icon

Reputation: 46
  • View blog
  • Posts: 803
  • Joined: 20-May 06

Re: SoftwareSales problem please help

Posted 22 August 2007 - 10:32 AM

Wow you quoted the whole topic but didn't say anything.. Anyway here's how the syntax works:

To make a constructor, declare it as well as its arguments like that:

public MyObject(int arg0, String arg1){ //This is a constructor
	//Do something here...
}


To make a method, use it like a constructor but declare a return type (what it will return: int, String... anything) or void if it does not return anything. Example:

public void setSales(double sales){ //This is a method and it does not return anything (void)
	//Do something here, we can use the sales variable which is a double
}

public double getSales (){ //This is another method with no arguments and it returns a double
	//Do something here
	return 0.0; //Return a double, it can be any double as long as it is a double
}


Here's an example of a class with its methods:

public class MyObject{ //We declare a class
	double sales = 0.0; //A variable

	public MyObject(double sl){ //Constructor with one argument: a double
		sales = sl; //Assign a value to the class' sales variable
	}

	public void setSales(double sl){ //Method with one argument: a double and no return type (void).
		sales = sl;
	}

	public double getSales(){ //Method with no arguments and a return type: a double
		return sales; //Return the class' sales variable
	}
}


A if block works as follow:

boolean allow = true;
if (allow == true){
	//Do something if allow is true
}


Same thing for a while loop.

Other tips you should consider:

-You can't put a method in a method or in a constructor.
-You can't put a constructor in a method or in a constructor.
-You can declare a class in a class.
-Every opening bracket must have a closing bracket. Your code needs to have as many closing brackets as opening brackets!
-You can't put any instruction outside a method or a constructor, except variable declarations. All other instructions must be in a method.

There are plenty of good Java tutorials floating around, and if you need further explanation just reply. Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#8 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: SoftwareSales problem please help

Posted 22 August 2007 - 10:33 AM

to allican57
Your last post was my point in my previous post above. People here that are helping are doing so when they can, if they can, and if they want, so you have to be patient. While you're waiting you might as well get back on the problem. And when I ask what kind of trouble do you have, you should post the actual issue and the assignment with the code, not just the assignment, I mean explain your self about the issues.

This post has been edited by PennyBoki: 22 August 2007 - 10:34 AM

Was This Post Helpful? 0
  • +
  • -

#9 allican57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-October 06

Re: SoftwareSales problem please help

Posted 25 August 2007 - 11:52 AM

I hit another snag on the if/else statement! I keep getting else without if error on lines 50,52,54.56. Please help!

/*A software company sells a package that retails for $99. Quantity discounts are given according to the following table:
Quantity Discount
1019 20% 2049 30% 5099 40% 100 or more 50%
Design a class that stores the number of units sold and has a method that returns the total cost of the purchase.
*/

import java.util.Scanner;

 
 public class SoftwareSales {
 
 
	
	public static void main(String[] args) {
   final double sales = 99; 
  SoftwareSales someSoftware = new SoftwareSales();
	  
   String software, discount, or, more, Enter, the, of, sold;
   double sales, product, units, number;
   {
 
	
	Scanner keyboard = new Scanner(System.in);
	
	 // Get the units sold
 System.out.println("Enter the number of units sold");
  units = keyboard.nextDouble(); 
	  
	  //Set the units sold
   //public void setUnits(double units)
   
  
   
  
  
  
 
  
	if (units < 10)
	product = (number * sales);
	System.out.println("The total cost of the purchase." + product);{
	
  
else if (units > 9 || units < 20)
 (99 - (99 * 0.2));
else if (units > 19 || units < 50)
  (99 - (99 * 0.3));
else if (units > 49 || units < 100)
  (99 - (99 * 0.4));
  else  (units > 99)
	  (99 -(99 * 0.5);
   //end else
  }
  System.out.println("units" * "sales" - discount);
 }
 }
 }
 

Was This Post Helpful? 0
  • +
  • -

#10 alpha02  Icon User is offline

  • Sexy DIC God
  • member icon

Reputation: 46
  • View blog
  • Posts: 803
  • Joined: 20-May 06

Re: SoftwareSales problem please help

Posted 25 August 2007 - 02:12 PM

Quote

if (units > 9 || units < 20)
(99 - (99 * 0.2));
else if (units > 19 || units < 50)
(99 - (99 * 0.3));
else if (units > 49 || units < 100)
(99 - (99 * 0.4));
else (units > 99)
(99 -(99 * 0.5);


Replace || by &&.

|| means OR
&& means AND

You need to use && in order to execute the statements if BOTH of the conditions are true. Take a look at the referrence sheets for Java, you might find these useful.

Other point, the code you just submitted in your last post still has wrong syntax. Look at what I wrote when I explained the syntax. If u still can't understand, get a basics tutorial, it's pretty easy.

This post has been edited by alpha02: 25 August 2007 - 02:14 PM

Was This Post Helpful? 0
  • +
  • -

#11 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: SoftwareSales problem please help

Posted 25 August 2007 - 02:17 PM

you should remove the bracket { in this line

Quote

System.out.println("The total cost of the purchase." + product);{


NOTE: when you use if statement, you can do it with brackets and without. If the if statement is only one then you can but you don't have to use them, in any other case, when you have two or more statements after the if you MUST put those statements inside the curly brackets{inside a block}

and for the if/else statements, please explain to me what are you trying to do in you code I mean the calculations thing.

I think you need to take a look at some examples on if/else.
You can check some snippets or some tutorials, here @ DIC.
Was This Post Helpful? 0
  • +
  • -

#12 alpha02  Icon User is offline

  • Sexy DIC God
  • member icon

Reputation: 46
  • View blog
  • Posts: 803
  • Joined: 20-May 06

Re: SoftwareSales problem please help

Posted 25 August 2007 - 02:24 PM

Syntax:

if (some condition && a second condition){
	System.out.println("The two conditions are respected.");
}
else if (a condition || another condition){
	System.out.println("At least one condition is respected.");
}
else if (a condition){
	System.out.println("The condition is respected.");
}
else{
	System.out.println("We found nothing matching any of the IF statements above.");
}


Note the syntax here, the brackets, the ;'s... This is a basic example and a good start.

This post has been edited by alpha02: 25 August 2007 - 02:26 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1