-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion 1
More file actions
61 lines (51 loc) · 1.51 KB
/
Version 1
File metadata and controls
61 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* 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 shape;
/**
*
* @author S346680274
*///import java.lang.Math.*;
import java.util.Scanner;
import java.util.InputMismatchException;
public class Shape {
double area;
double perimeter;
double length;
double width;
public double checkValue(String statement){
System.out.print(statement);
Scanner input = new Scanner(System.in);
double num1;
while (true){
try{
num1=input.nextDouble();
if (num1>0){
break;
}
else{
System.out.print("Please enter a positive number!");
}
}
catch (InputMismatchException err){
input.next();
System.out.print("The value entered is not a number. Please try again."+statement);
}
}
return num1;
}
public void userInput(){
Scanner input = new Scanner(System.in);
System.out.println("Enter the width");
this.width=checkValue("width: ");
System.out.println("Enter the length");
this.length=checkValue("length: ");
}
public double area(){
return (this.width*this.length);
};
public double perimeter(){
return (2*(this.width+this.length));
}