-
January 26th, 2005, 10:22 PM
#1
Banned
java problem
I am programming in java and i just started out in college.
For my class i have to write a program with the if/else statements
i have this so far and im getting the following errors
System.out.print("Enter the length of the desk : ");
int length=MyInput.readInt();
System.out.print("Enter the width of the desk : ");
int width=MyInput.readInt();
int area = (length * width)
System.out.println("Enter 1 for pine wood");
System.out.println("Enter 2 for oak wood");
System.out.println("Enter 3 for mahogany wood");
System.out.print("Enter the type of wood: ");
int wood = MyInput.readInt();
if (wood == 2)
(desk+100);
else
(desk+150);
if (wood == 1)
desk = 200);
System.out.print("Enter the number of drawers: ");
int wood= MyInput.readInt();
lab3_141.java:20: ';' expected
System.out.print("Enter the number of drawers: ");
^
lab3_141.java:23: not a statement
desk+75;
^
lab3_141.java:25: not a statement
desk+150; }
^
3 errors
any suggestions?
-
January 26th, 2005, 10:31 PM
#2
Redirect your java-related questions to http://forum.java.sun.org
While you're asking them here, try using this forums code-tags to format your code, it'll help others to read your code clearly.
Your first problem seems to be this: there's no ; after this line: int area = (length * width) Furthermore, you didn't declare a variable with the name 'desk'. At last, lines like these have no meaning:
Did you mean desk=150; ?
I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.
-
January 26th, 2005, 10:35 PM
#3
desk+100; isn't a proper Java statement. desk = desk + 100; will do what you want. That takes care of two errors.
lab3_141.java:20: ';' expected
System.out.print("Enter the number of drawers: ");
That's because of this statement:
desk = 200);
The ; should be after the 200.
-
January 26th, 2005, 10:37 PM
#4
Banned
even when i declare desk to be 200 up top, it still has the same errors
-
January 26th, 2005, 10:39 PM
#5
Paste your entire code here. It'll be easier to understand what to fix.
-
January 26th, 2005, 10:40 PM
#6
Banned
ytyes
AH TT your a savior, thats what it was, thank you much
^
-
January 26th, 2005, 10:40 PM
#7
/me bows.
Think I need to edit this, your code is horriblely written. Post it here and we'll show you how to keep it nice and clean.
-
January 26th, 2005, 11:06 PM
#8
Banned
int drawer= MyInput.readInt();
int drawers = drawer * 30;
if (area > 1000)
desk = desk+75;
if (area > 2000)
desk = desk+125;
else
desk=desk;
if (wood == 2)
desk=desk+100;
if (wood == 3)
desk=desk+150;
else
desk=desk;
System.out.println("The cost of your desk is: " + (desk+drawers));
Are my If/elses ok, b/c im not gettin the correct calculation
-
January 26th, 2005, 11:07 PM
#9
Banned
here this is my whole code
import java.io.* ;
public class lab3_141
{
public static void main(String[] args)
{
int desk=200;
System.out.print("Enter the length of the desk : ");
int length=MyInput.readInt();
System.out.print("Enter the width of the desk : ");
int width=MyInput.readInt();
int area = (length * width);
System.out.println("Enter 1 for pine wood");
System.out.println("Enter 2 for oak wood");
System.out.println("Enter 3 for mahogany wood");
System.out.print("Enter the type of wood: ");
int wood = MyInput.readInt();
System.out.print("Enter the number of drawers: ");
int drawer= MyInput.readInt();
int drawers = drawer * 30;
if (area > 1000)
desk = desk+75;
if (area > 2000)
desk = desk+125;
else
desk=desk;
if (wood == 2)
desk=desk+100;
if (wood == 3)
desk=desk+150;
else
desk=desk;
System.out.println("The cost of your desk is: " + (desk+drawers));
}
}
-
January 26th, 2005, 11:10 PM
#10
Banned
This is what it is supposed to do
Purpose : To write a simple program to perform input, output and use control structures in Java.
Description : Write a program to that calculates and displays prices for custom made desks.The base price for a desk is $200.00. Our desks are built using three types of wood, pine, oak, and mahogany. Add $100.00 to the cost for oak and $150.00 for mahogany. No extra charge for pine. If the surface area of the desk is over 1000 square inches, add $75.00. If the surface area of the desk is over 2000 square inches add $125.00. There is a $30 charge for each drawer in the desk. Compute the price display the values. Use a switch statement to determine cost for wood type.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|