3 Replies - 234 Views - Last Post: 31 October 2012 - 02:11 AM Rate Topic: -----

#1 codking328  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-October 12

Can't Get This To Compile Right

Posted 30 October 2012 - 09:30 PM

I can't get this to compile right any help will be greatly appreciated

public class Inventory1 {

	public static void main(String args []) {

		Mobile Phone phone;


		phone = new Mobile Phone(1, "iphone5", 10, 199.99);
		System.out.println(phone);

		phone = new Mobile Phone (2, "Droid Razr", 7, 199.99);
		System.out.println(phone);

		phone = new Mobile Phone (3, "Droid Razr Maxx", 9, 299.99);
		System.out.println(phone);

		phone = new Mobile Phone (4, "Spectrum", 3, 99.99);
		System.out.println(phone);

		System.out.println("ThePhone Name is " + phone.getphoneName());
		System.out.println("Number of units in stock is" + phone.getphoneStock());
		System.out.println("The price of each Mobile Phone is" + phone.getphonePrice());
		System.out.println("The item number is " + phone.getphoneItem());
		System.out.println("The value of the inventory is" + phone.value());
	} //end main

} // end class Inventory1


class Mobile Phone {
	private String phoneName;
	private double phoneStock;
	private double phonePrice;
	private double phoneItem;

	public Mobile Phone(String title, double stock, double price, double item) {
		phoneName = name;
		phoneStock = stock;
		phonePrice = price;
		phoneItem = item;
	} //end four-argument constructor

	// set Mobile Phone name
	public void setphoneName(String title) {
		 phoneName = name;
	} //end method  setphoneName

	//return Mobile Phone name
	public String getphoneName() {
		return phoneName;
	} //end method getphoneName

	//set Mobile Phone Stock
	public void setphoneStock(double stock) {
		phoneStock = stock;
	} //end method setphoneStock

	//return phoneStock
	public double getphoneStock() {
		return phoneStock;
	} //end method get phoneStock

	public void setphonePrice(double price) {
		phonePrice = price;
	} //end method setphonePrice

	//return phonePrice
	public double getphonePrice() {
		return phonePrice;
	} //end method get phonePrice

	public void setphoneItem(double item) {
		phoneItem = item;
	} //end method setphoneItem

	//return Mobile Phone item
	public double getphoneItem() {
		return phoneItem;
	} //end  method getphoneItem

	//calculate inventory value
	public double value() {
		return phonePrice * phoneStock;
	} //end method value

} //end class Mobile Phone



I get these errors

C:\Users\Inventory1.java:5: error: ';' expected
Mobile Phone phone;
^
C:\Users\Inventory1.java:5: error: not a statement
Mobile Phone phone;
^
C:\Users\Inventory1.java:8: error: '(' or '[' expected
phone = new Mobile Phone(1, "iphone5", 10, 199.99);
^
C:\Users\Inventory1.java:8: error: ')' expected
phone = new Mobile Phone(1, "iphone5", 10, 199.99);
^
C:\Users\Inventory1.java:8: error: not a statement
phone = new Mobile Phone(1, "iphone5", 10, 199.99);
^
C:\Users\Inventory1.java:8: error: not a statement
phone = new Mobile Phone(1, "iphone5", 10, 199.99);
^
C:\Users\Inventory1.java:8: error: ';' expected
phone = new Mobile Phone(1, "iphone5", 10, 199.99);
^
C:\Users\Inventory1.java:11: error: '(' or '[' expected
phone = new Mobile Phone (2, "Droid Razr", 7, 199.99);
^
C:\Users\Inventory1.java:11: error: ')' expected
phone = new Mobile Phone (2, "Droid Razr", 7, 199.99);
^
C:\Users\Inventory1.java:11: error: not a statement
phone = new Mobile Phone (2, "Droid Razr", 7, 199.99);
^
C:\Users\Inventory1.java:11: error: not a statement
phone = new Mobile Phone (2, "Droid Razr", 7, 199.99);
^
C:\Users\Inventory1.java:11: error: ';' expected
phone = new Mobile Phone (2, "Droid Razr", 7, 199.99);
^
C:\Users\Inventory1.java:14: error: '(' or '[' expected
phone = new Mobile Phone (3, "Droid Razr Maxx", 9, 299.99);
^
C:\Users\Inventory1.java:14: error: ')' expected
phone = new Mobile Phone (3, "Droid Razr Maxx", 9, 299.99);
^
C:\Users\Inventory1.java:14: error: not a statement
phone = new Mobile Phone (3, "Droid Razr Maxx", 9, 299.99);
^
C:\Users\Inventory1.java:14: error: not a statement
phone = new Mobile Phone (3, "Droid Razr Maxx", 9, 299.99);
^
C:\Users\Inventory1.java:14: error: ';' expected
phone = new Mobile Phone (3, "Droid Razr Maxx", 9, 299.99);
^
C:\Users\Inventory1.java:17: error: '(' or '[' expected
phone = new Mobile Phone (4, "Spectrum", 3, 99.99);
^
C:\Users\Inventory1.java:17: error: ')' expected
phone = new Mobile Phone (4, "Spectrum", 3, 99.99);
^
C:\Users\Inventory1.java:17: error: not a statement
phone = new Mobile Phone (4, "Spectrum", 3, 99.99);
^
C:\Users\Inventory1.java:17: error: not a statement
phone = new Mobile Phone (4, "Spectrum", 3, 99.99);
^
C:\Users\Inventory1.java:17: error: ';' expected
phone = new Mobile Phone (4, "Spectrum", 3, 99.99);
^
C:\Users\Inventory1.java:30: error: '{' expected
class Mobile Phone {
^
23 errors

Is This A Good Question/Topic? 0
  • +

Replies To: Can't Get This To Compile Right

#2 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7653
  • View blog
  • Posts: 12,909
  • Joined: 19-March 11

Re: Can't Get This To Compile Right

Posted 30 October 2012 - 10:09 PM

A class name cannot have white space in it -
class Mobile Phone



is illegal. Try

class MobilePhone
instead, and make the appropriate change to any line with "Mobile Phone" - that should clear up all of the errors you're seeing there.
Was This Post Helpful? 1
  • +
  • -

#3 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Can't Get This To Compile Right

Posted 30 October 2012 - 10:16 PM

Probably starts at line 5. Shouldn't Mobile Phone be one word? In java, there's no such thing as variables or class names with spaces. It isn't allowed.
Was This Post Helpful? 1
  • +
  • -

#4 N1G3L2  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 28
  • Joined: 25-October 11

Re: Can't Get This To Compile Right

Posted 31 October 2012 - 02:11 AM

Theres a few problems here.

1)First change every instance of "Mobile Phone" to "MobilePhone"

2)Your MobilePhone Constructor
public MobilePhone(String title, double stock, double price, double item) {
		phoneName = name;
		phoneStock = stock;
		phonePrice = price;
		phoneItem = item;
	}


In the parameters you have String title, but in the method use use a variable called "name" which you never created.

3)Your constructor parameters go (String, double, double, double) but when you call them in main you have (double, String, double, double) These need to be in same order for them to run.

That should fix it.

=)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1