Need help with Java Programming Homework

0 Nicholas Barding · September 21, 2015
They seem pretty basic. 

So we are using a program called NetBeans IDE.

and on Lab assignment 4, the instructions are as follows,

This lab assignment will ask you to write a program using the for, while, and do while statements.
 
Create a Java class named ForDemo that has a “main” similar to class Payroll in Lab 1.

What catches me up, is when it says "create a java class named ForDemo that has a "main" similar to class Payroll in Lab 1.

I dont understand if its supposed to look exactly like lab 1 and then you tinker with it like the instructions say or what. 

Aswell the payroll lab is as follows,


Source:
 
package payroll;
{
    public static void main (String[] args)
    { 
        int hours = 40;
        double grosspay; payRate = 25.0;
 
        grossPay = hours * payRate;
        System.out.printIn("Your gross pay is $" + grossPay);
        System.out.printIn("Lets get the party started!");
        System.out.printIn("Java is fun!");
 
    }
}  
 
Sample Output:
 
run:
BUILD SUCCESSFUL (total time: 0 seconds)

I was foolish and didnt do lab 2 and 3, so as im trying to catch back up i am stuck here. 

Thanks

Post a Reply

Replies

Oldest  Newest  Rating
0 Bruno Laurence · September 23, 2015
1) Open Netbeans
2) File / New Project / Java / Java Application
3) Project Name :  ForDemo   (press finish)

then you will have this : 

package fordemo;

public class ForDemo {

   public static void main(String[] args) {
     
   }
   
}
0 Nicholas Barding · September 24, 2015
This is what i get after i do what exactly you put. The thing that gets me is "Create a Java class named ForDemo that has a “main” similar to class Payroll in Lab 1."

*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fordemo;

/**
 *
 * @author Nicholas
 */
public class ForDemo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }
    
}
0 Bruno Laurence · September 24, 2015
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
0 Bram Dekker · September 25, 2015
Take a look at this explanation :)

Java is an object oriented language that has a concept called classes. You can see a class as a blue print. The class shows what the structure of a "thing" looks like. As an example:


public class House {


      private int amountWindows = 0;


      
      public void addWindow() {
          this.amountWindows++;
      }

public int getAmountWindows() {
return amountWindows;
}


}


The class depicts a House. It has an attribute: amountWindows (that represents the amount of windows), of the type integer (number). Next to that it has a method (action) to get the amount of windows and add a window (getAmountWindows() and addWindow()). Using this class, we can create an object. Lets say we want to create a House and use this in our program. We start our program with a class that contains a main method. The main method is the first question that is called if a Java program runs.

public class Main {

//this is the method that will be called first!
public static void main() {
//we create a new instance (object) of using the House class (blue print)
House h = new House();
//we call the addWindow method that will increment its internal variable with 1
h.addWindow();
//we print out the output of our getAmountWindows method.
System.out.println(h.getAmountWindows());
}
}

 
Like I mentioned, the main method is the first method that will be called when we run a Java program. The method definition is constructed as follows. public (the accessibility of the method, public means that every outside structure can access and call it). static (this means that the method can be called without creating an object (see new House statement) of the class that contains it) and void (the returning type of the method, void means that the method does NOT return a thing.
I know that this explanation did not answer your question, that was also not my intention. I wanted you to understand the ideas. Hopefuly now you know the answer to your question.
If you have any further questions, feel free to ask.
Kind regards,
Bram
  • 1

Java / Android Development

107,109 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator