Commit 7a258a45 authored by Reed McDonagh's avatar Reed McDonagh

inital commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>COM4001-week1-exercise</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
package exercise1;
public class javaApp {
public static void main(String[] args) {
System.out.println("I like java!");
System.out.println("Reed McDonagh");
}
}
/*
* Original Program (as written):
* public class {
* public Static void main(String[] args)
* {
* system.out.println( I want this program to compile)
* }
*
*
* How to fix?:
* Every class requires a unique name to be assigned, in my case to fix it I assign the class the name "javaApp".
* Although the formatting of the code is a mess this alone will not prevent the program from compiling.
* On line 4 the System namespace should be capitalized.
* Also on line 4 the method println accepts a string so the text must be wrapped in ".
* Once more on line 4 a semi colon is missing.
*
* Fixed version below
*/
package exercise10;
public class javaApp {
public static void main(String[] args) {
System.out.println("I want this program to compile");
}
}
package exercise11;
public class javaApp {
public static void main(String[] args) {
String myInfo = "Reed McDonagh\n" +
"Computer Science\n" +
"reed.mcdonagh@yorksj.ac.uk";
System.out.println(myInfo);
}
}
package exercise12;
public class javaApp {
public static void main(String[] args) {
String myInfo = "Reed McDonagh\n\n" +
"Computer Science\n\n" +
"reed.mcdonagh@yorksj.ac.uk";
System.out.println(myInfo);
}
}
package exercise13;
public class javaApp {
public static void main(String[] args) {
String myInitials = "***** **** ****\n" +
"* * * * *\n" +
"***** * * *\n" +
"* * * *\n" +
"* * * *\n" +
"* * * *\n";
System.out.println(myInitials);
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.five;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 8;
System.out.println("Gallon to Pint converter");
System.out.print("Input amount in gallons: ");
double input = stdin.nextDouble();
System.out.println(input + " gallons is equivalent to " + (input * conversionRate) + " pints.");
stdin.close();
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.four;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 0.454;
System.out.println("Pound to Kilograms converter");
System.out.print("Input weight in pounds: ");
double input = stdin.nextDouble();
System.out.println(input + " pound is equivalent to " + (input * conversionRate) + " kilograms.");
stdin.close();
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.one;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 1.609;
System.out.println("Miles to Kilometers converter");
System.out.print("Input distance in miles: ");
double input = stdin.nextDouble();
System.out.println(input + " miles is equivalent to " + (input * conversionRate) + " kilometers.");
stdin.close();
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.seven;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 4.546;
System.out.println("Gallon to litres converter");
System.out.print("Input amount in gallons: ");
double input = stdin.nextDouble();
System.out.println(input + " gallons is equivalent to " + (input * conversionRate) + " litres.");
stdin.close();
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.six;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 1.760;
System.out.println("Litre to pints converter");
System.out.print("Input amount in litres: ");
double input = stdin.nextDouble();
System.out.println(input + " litres is equivalent to " + (input * conversionRate) + " pints.");
stdin.close();
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.three;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 1000;
System.out.println("Tonnes to Kilograms converter");
System.out.print("Input weight in tonnes: ");
double input = stdin.nextDouble();
System.out.println(input + " tonnes is equivalent to " + (input * conversionRate) + " kilograms.");
stdin.close();
}
}
/*
* Would of personally done it all as one program but sheet
* specifies seperate applications
*/
package exercise14.two;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final double conversionRate = 39.370;
System.out.println("Miles to Inches converter");
System.out.print("Input distance in miles: ");
double input = stdin.nextDouble();
System.out.println(input + " miles is equivalent to " + (input * conversionRate) + " inches.");
stdin.close();
}
}
/*
* Original Program:
* public class MyProgram {
* Scanner input = new Scanner(System.in)
* public void main() {
* System.out.Print("Please, enter length");
* double b = input.next;
* double a = 1 * 1;
* println("a = " + a);
* }
* }
*
*
* What is the program doing?:
* In the state the program was provided in the program is doing nothing as it is uncompilable due to multiple errors with the code.
* Firstly the line where a new Scanner class is initated doesn't end in a semi-colon.
* Then the line where input is read into variable b the code tries to use the input.next() method as a variable instead of calling the method.
* Lastly the final println is not valid and would be System.out.println();
* However even with all these fixes made the program still does nothing than simply outputting the string "a = 1". With context gathered from
* looking at the code I assume that the code is supposed to be doubling the length of the input provided? My fixed code below does that.
*
*/
package exercise2;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.print("Please enter the length, as a double, that you'd like be to doubled:\t");
double inputLength = stdin.nextDouble();
System.out.println(inputLength + " doubled = " + (inputLength * 2));
// close stdin handle
stdin.close();
}
}
package exercise3;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int firstInput, secondInput, thirdInput;
System.out.print("Please enter the first number you'd like to add: ");
firstInput = stdin.nextInt();
System.out.print("Please enter the second number you'd like to add: ");
secondInput = stdin.nextInt();
System.out.print("Please enter the third number you'd like to add: ");
thirdInput = stdin.nextInt();
System.out.print(firstInput + " + " + secondInput + " + " + thirdInput + " = " + (firstInput + secondInput + thirdInput));
// close stdin handle
stdin.close();
}
}
package exercise4;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
double accountBalance, intrestRate;
System.out.print("Enter your account balance : ");
accountBalance = stdin.nextDouble();
System.out.print("Enter the annual intrest rate percent: ");
intrestRate = stdin.nextDouble() / 100; // convert percentage to a decimal
accountBalance += (accountBalance * intrestRate);
System.out.println("Balance with annual intrest after a year: " + accountBalance);
// close stdin handle
stdin.close();
}
}
package exercise5;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
double accountBalance, intrestRate;
System.out.print("Enter your account balance : ");
accountBalance = stdin.nextDouble();
System.out.print("Enter the annual intrest rate percent: ");
intrestRate = stdin.nextDouble() / 100; // convert percentage to a decimal
accountBalance += (accountBalance * intrestRate);
System.out.println("Balance with annual intrest after a year: " + accountBalance);
accountBalance += (accountBalance * intrestRate);
System.out.println("Balance with annual intrest after two years: " + accountBalance);
// close stdin handle
stdin.close();
}
}
package exercise6;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.print("Input the radius of a circle you'd like to know the area of: ");
int circleRadius = stdin.nextInt();
System.out.print("The area of a circle with a radius of " + circleRadius + " is " + (3.142 * circleRadius * circleRadius));
stdin.close();
}
}
package exercise7;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.print("Input the temperature in F you'd like to convert to C: ");
double degreesF = stdin.nextDouble();
System.out.print(degreesF + "F is " + (degreesF - 32) * 5/9 + "C");
stdin.close();
}
}
package exercise8;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.print("Input the amount of KG you'd like to convert to pounds: ");
double kgInput = stdin.nextDouble();
System.out.print(kgInput + "KGs is equivalent to " + kgInput * 2.2 + " pounds");
stdin.close();
}
}
package exercise9;
import java.util.Scanner;
public class javaApp {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
final int totalKids = 5; // changable at compile time
int kidsTotalAge = 0;
for (int i = 0; i < totalKids; i++)
{
System.out.print("Enter the age of kid number " + (i + 1) + ": ");
kidsTotalAge += stdin.nextInt();
}
System.out.print("The total age of all the kids combined is " + kidsTotalAge);
stdin.close();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment