Welcome to Dream.In.Code
Become a Java Expert!

Join 150,106 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,913 people online right now. Registration is fast and FREE... Join Now!




source code

 
Reply to this topicStart new topic

source code

mrkel
25 Jun, 2008 - 10:38 AM
Post #1

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 7

Can someone tell me what i'm doing wrong.

1. public class DebugTwo4
java

{//Put bracket in correct spot.


public static void main(String[] args)//Put bracket in the correct spot.
{
int myCredits = 15;
double yourCredits = 16.5;
double rate = 75.84;
tuitionBill(myCredits,rate);
tuitionBill(yourCredits, rate);
Scanner keyboard = new Scanner(System.in);//Added this statement.

System.out.println("Enter
}
public static void tuitionBill(c,r)
{
System.out.println("Total due " + (r*c));
}
public static void tuitionBill(c, r)
{
System.out.println("Total due " + (r*c));
}
}


2.public class DebugTwo1
java

{
public static void main(String[] args)
{
oneInt=315;
System.out.print("The int is ");
System.out.println(oneInt);
}
}


3.public class DebugSix2
java

// Print the character values
// of 65 through 122
{
public static void main(String[] args)
{
char letter;
int a = 0;
for(a = 65; a <= 122; )
{
letter = (char)a;
System.out.print(" " + letter);
if(a=85||105)
System.out.println();
}



System.out.println("\nEnd of program");


4.public class DebugSix1
java

{//Remove the comments from this spot.
public static void main(String[] args)
{

// Start with a penny
// Double it every day
// How much do you have in a month?//Place comment here.
double money;
int day;
double penny;

Scanner keyboard = new Scanner(System.in);//Added this statement.
money = keyboard.nextDouble();//Added this statement.
day = keyboard.nextInt();//Added this statement.
System.out.println("Enter the total penny you have.");//Added this statement.
int count = 0;
while(day >= 30);
{
day = 30;
money = penny;
penny = keyboard.nextDouble();
money = 2 * money;
System.out.println("After day " + day +
" you have " + money);


5.public class DebugFour4
java

// This class discounts prices by 10%
{
public static void main(String args[])
{
int price = 100;
double price2 = 100.00;
tenPercentOff(price);
tenPercentOff(price2);
}
public static void tenPercentOff(int p)
{
double newPrice = p * .10;
System.out.println("Ten percent off");
System.out.println("New price is " + newPrice);


6.public class DebugFour1
java

{//Added this bracket.



public static void main(String args[])
{
int x = 5;
int y = 8;

//Ask user to input the letter.//Added this statement.
Scanner keyboard = new Scanner(System.in);//Added this statement
System.out.println("Have the user to input two letter");//Added this statement.
System.out.println("with a space between them.");//Added this statement.
System.out.println("adding " +(x + y));
x = keyboard.nextInt();//Added this statement.
y = keyboard.nextInt();//Added this statement.


//I indention the whole body.
//Now subtract z from y. Added this statement.
int z = 19;
z = keyboard.nextInt();//Added this statement.
System.out.println("subtracting " + (z - y));
//Now divide z from x. Added this statement.
System.out.println("dividing " + (z / x));//Correct the divide sign by putting space between the letter.
//Now multiply x from z. Added this statement.
System.out.println("multiplying " + (x * z));


** Edit ** code.gif
User is offlineProfile CardPM
+Quote Post

rgfirefly24
RE: Source Code
25 Jun, 2008 - 11:21 AM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Apr, 2008
Posts: 335



Thanked: 5 times
Dream Kudos: 150
My Contributions
First use code tags

[*code=java] YOUR CODE HERE [*/code] remove the *'s

second what errors are you getting? You need to be a little more descriptive with what your question actually is.

some real quick items that i saw:

java

Scanner keyboard = new Scanner(System.in);//Added this statement.

System.out.println("Enter // your missing the ");
}


java

public static void tuitionBill(c,r)
{
System.out.println("Total due " + (r*c));
}
public static void tuitionBill(c, r)
{
System.out.println("Total due " + (r*c));
}


why on earth are you recreating this method twice? its just redundancy you dont need.

java

char letter;
int a = 0;
for(a = 65; a <= 122; )
{
letter = (char)a;
System.out.print(" " + letter);
if(a=85||105)
System.out.println();
}



ok your for loop is totally wrong. also you initialize a to equal zero then use it in the for loop. the correct syntax of a for loop is:

java

for (int a=65;a<=122;a++)
{
//do stuff here
}


you are also missing two closing brackets on that class. Mate go back through your code. I've looked through the first 2 and found these errors. Check them all very carefully and you'll find the errors.

This post has been edited by rgfirefly24: 25 Jun, 2008 - 11:30 AM
User is offlineProfile CardPM
+Quote Post

rgfirefly24
RE: Source Code
25 Jun, 2008 - 05:38 PM
Post #3

D.I.C Regular
Group Icon

Joined: 7 Apr, 2008
Posts: 335



Thanked: 5 times
Dream Kudos: 150
My Contributions
ok, since i left off on number 3, i'll finish what i see on the others

another thing in number 3:

java

if(a=85||105)
System.out.println();


if statements cannot be done in the manner you have it. The way you are doing this is you are attempting to set a to 85

java

if (a==85 || a==105)
{
Sytem.out.println();
}


notice the double equal signs. That means that if a is equal to either 85 or 105 then do the following statement.

starting with number 4:

java

Scanner keyboard = new Scanner(System.in);//Added this statement.
money = keyboard.nextDouble();//Added this statement.
day = keyboard.nextInt();//Added this statement.
System.out.println("Enter the total penny you have.");//Added this statement.


ok, you have your statements out of order. You want to prompt the user before asking them to input. Plus you want to ask them how many days since that is the input, not the number of pennies. Your starting out with one so that is known.

here is a good way of doing this code:

java

int day;
double money = 1.0;

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter number of days to double penny for:")'
day = keyboard.nextInt();


java

int count = 0;
while(day >= 30);
{
day = 30;
money = penny;
penny = keyboard.nextDouble();
money = 2 * money;
System.out.println("After day " + day +
" you have " + money);


ok your while loop structure is good but incorrect for the instance at hand.

basically your while loop says to do the follow if day is greater than or equal to 30. your loop with always be greater than or equal to 30 since you set day to 30 in the while loop.

try it this way:
java

int currentday = 1;

do
{
money *= 2;
System.out.println("After day: " + currentday + " you have: " + money + " pennies");
currentday++
}while(currentday <= day);



ok number 5:

java

int price = 100;
double price2 = 100.00;
tenPercentOff(price);
tenPercentOff(price2);


you are declaring int price and double price. You only need one of those. I would use a system.in scanner so the user can input the price themselves.

java

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter normal purchase price: ");
double price = keyboard.NextDouble();//not sure on the method but i think its right
tenPercentOff(price);


now, lets look at your function tenPercentOff

java

public static void tenPercentOff(int p)
{
double newPrice = p * .10;
System.out.println("Ten percent off");
System.out.println("New price is " + newPrice);


alright good declaration, however your parameter is wrong. You are sending this function type double but wanting a type int. declare it like so:
java

public static void tenPercentOff(double p)


now lets look at the innards of that function. You do double newPrice = p *.10 what that does is get the sum of 10% of p. What you want is the price after that discount is removed.

java

double newPrice = p - (p*.10);
System.out.println("Ten percent off");
System.out.println("New price is: " + newPrice);


now you just need to finish the ending brackets and that one is good.

now lets look at number 6:

i'll have to get back to you on that one. The way you are doing it is asking for a string or char input and trying to place it into an int variable. That will never work.



This post has been edited by rgfirefly24: 25 Jun, 2008 - 05:51 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:02AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month