FIX THE CODE PROVIDED BELOW
Part 2 - Syntax Errors and Troubleshooting
The code below has many syntax (and other) errors.
Tasks:
Compile the code and fix the errors one at a time.
// Lab1a.java // This short class has several bugs for practice.
// Authors: Carol Zander, Rob Nash, Clark Olson, you
public class Lab1a {
public static void main(String[] args) {
compareNumbers();
calculateDist();
}
publicstatic void compareNumbers() {
int firstNum = 5;
int secondNum;
System.out.println( "Sum is: + firstNum + secondNum );
System.out.println( "Difference is: " + (firstNum - secondNum );
System.out.println( "Product is: " + firstNun * secondNum );
}
public static void calculateDistance() {
int velocity = 10; //miles-per-hour
int time = 2, //hoursint
distance = velocity * timeSystem.out.println( "Total distance is: " distanace);
}
}
Part 3 - Print Statements and Simple Methods
Use "print" and "println" statements, but use method calls to reduce the number of repeated "print"
and "println" statements. Seed code is provided as follows:
// Lab1b.java
// This is a practice lab to output a few verses of
//"99 bottles of beer on the wall"
// Authors: Carol Zander, Clark Olson, you
public class Lab1b {
public static void main (String[] args) {
int numBottles; // number of bottles currently on the wall
// display first verse
numBottles = 5;
System.out.print(numBottles);
onWall();
System.out.print(numBottles);
botBeer();
takeOneDown();
numBottles = 4;
System.out.print(numBottles);
onWall();
System.out.println(); // display blank line between verses
// display second verse
// [this is where you take over]
}
public static void onWall() {
System.out.println(" bottles of beer on the wall");
}
public static void botBeer() {
System.out.println(" bottles of beer");
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images
- Create a word guessing game c# code using arraylist and stringbuilder.arrow_forwardTASK 5. Methods Overloading. Review Methods, Implement the following code, test it with different input, make sure it runs without errors.arrow_forwardpublic class Side Plot { * public static String PLOT_CHAR = "*"; public static void main(String[] args) { plotxSquared (-6,6); * plotNegXSquaredPlus20 (-5,5); plotAbsXplus1 (-4,4); plotSinWave (-9,9); public static void plotXSquared (int minX, int maxx) { System.out.println("Sideways Plot"); System.out.println("y = x*x where + minX + "= minX; row--) { for (int col = 0; col row * row; col++) { System.out.print (PLOT_CHAR); if (row== 0){ } System.out.print(" "); } for(int i = 0; i <= maxx* maxX; i++) { System.out.print("-"); } System.out.println(); Sideways PHOT y = x*x where -6<=x<=6 Sideways Plot y = x*x where -6<=x<=6 How do I fix my code to get a plot like 3rd picture?arrow_forward
- TASK 1. Variables. Review variables, Implement the following code, make sure it runs without errors. Change Summation Integers problem to Finding the minimum problem.arrow_forwardjava languageSchedule the People classIn main file, create an object of class PeopleMake the showPeople method callarrow_forwardDebugging is the process of discovering and correcting bugs. What relevance does this have to testing?arrow_forward
- First snippet public static void main(String[] args) { Dog aDog = new Dog("Max"); Dog oldDog = aDog; // we pass the object to foo foo(aDog); // aDog variable is still pointing to the "Max" dog when foo(...) returns aDog.getName().equals("Max"); // true aDog.getName().equals("Fifi"); // false aDog == oldDog; // true } public static void foo(Dog d) { d.getName().equals("Max"); // true // change d inside of foo() to point to a new Dog instance "Fifi" d = new Dog("Fifi"); d.getName().equals("Fifi"); // true } Second snippt public static void main(String[] args) { Dog aDog = new Dog("Max"); Dog oldDog = aDog; foo(aDog); // when foo(...) returns, the name of the dog has been changed to "Fifi" aDog.getName().equals("Fifi"); // true // but it is still the same dog: aDog == oldDog; // true } public static void foo(Dog d) { d.getName().equals("Max"); // true // this changes the name of d to be "Fifi" d.setName("Fifi"); } What is the difference between the first code snippet and the second?…arrow_forward* CENGAGE MINDTAP Programming Exercise 3-6 Instructions BookstoreCredit.java + 1 import java.util.Scanner; 2 public class BookstoreCredit { To encourage good grades, Hermosa High School has decided to public static void main (String args[]) { // Write your code here 3 award each student a bookstore credit that is 10 times the student's 4 grade point average. 5 } 6 public static void computeDiscount(String name, double gpa) { // Write your code here } In other words, a student with a 3.2 grade point average receives a 8 $32.0 credit. 10 Create an application that prompts a student for a name and grade 11 } point average, and then passes the values to a method ( 12 computeDiscount ) that displays a descriptive message. The message uses the student's name, echoes the grade point average, and computes and displays the credit. An example of the program is shown below: Enter your name >> John Enter your gpa >>3.4 John, your GPA is 3.4, so your credit is $34.0 Grading Write your Java code in…arrow_forwardJava - Smallest Numberarrow_forward
- Arrays of objects. Java programming: How to create and work with an array of objects in Java I wanted to know that supppose that I have 100 employees who are paid on an hourly basis and I need to keep track of their arrival and departure times, and I have also created the class Clock to implement the time of day in a program. I also know that I will use two arraays; one called arrivalTime and the other array called departure time. Each of these arrays will have 100 elements and each element will be a reference variable of Clock type.. For example Clock[] arrival = new Clock[100]. My qeustion is how do I create the objects arrival and departure. Then how could I use the methods f the class clokc. Thank youarrow_forward8) Now use the Rectangle class to complete the following tasks: - Create another object of the Rectangle class named box2 with a width of 100 and height of 50. Note that we are not specifying the x and y position for this Rectangle object. Hint: look at the different constructors) Display the properties of box2 (same as step 7 above). - Call the proper method to move box1 to a new location with x of 20, and y of 20. Call the proper method to change box2's dimension to have a width of 50 and a height of 30. Display the properties of box1 and box2. - Call the proper method to find the smallest intersection of box1 and box2 and store it in reference variable box3. - Calculate and display the area of box3. Hint: call proper methods to get the values of width and height of box3 before calculating the area. Display the properties of box3. 9) Sample output of the program is as follow: Output - 1213 Module2 (run) x run: box1: java.awt. Rectangle [x=10, y=10,width=40,height=30] box2: java.awt.…arrow_forwardBAGEL FILES import javax.swing.JFrame; public class Bagel{//-----------------------------------------------------------------// Creates and displays the controls for a bagel shop.//-----------------------------------------------------------------public static void main (String[] args){JFrame frame = new JFrame ("Bagel Shop");frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new BagelControls()); frame.pack();frame.setVisible(true);}} import java.awt.*;import java.awt.event.*; import javax.swing.*; public class BagelControls extends JPanel{private JComboBox bagelCombo;private JButton calcButton;private JLabel cost;private double bagelCost;public BagelControls(){String[] types = {"Make A Selection...", "Plain","Asiago Cheese", "Cranberry"};bagelCombo = new JComboBox(types);calcButton = new JButton("Calc");cost = new JLabel("Cost = " + bagelCost);setPreferredSize (new Dimension (400,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education